From 9a06db475b8c39b29e7e1a8a8d7a2c32308711cb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 28 Sep 2020 18:56:04 +0700 Subject: [PATCH] update both parameter and @param docblock --- app/Config/Mimes.php | 10 +- rector.php | 4 +- system/CLI/CLI.php | 13 +-- system/Cache/Handlers/FileHandler.php | 51 ++++----- system/Common.php | 8 +- system/Config/BaseService.php | 7 +- system/Database/BaseBuilder.php | 51 ++++----- system/Database/BaseConnection.php | 14 +-- system/Database/BaseUtils.php | 21 ++-- system/Database/Forge.php | 87 +++++++------- system/Database/MySQLi/Forge.php | 17 ++- system/Database/Postgre/Builder.php | 7 +- system/Database/Postgre/Forge.php | 22 ++-- system/Database/SQLite3/Forge.php | 13 +-- system/Debug/Exceptions.php | 11 +- system/Events/Events.php | 52 ++++----- system/HTTP/CURLRequest.php | 107 +++++++++--------- system/Helpers/filesystem_helper.php | 94 +++++++-------- system/Helpers/form_helper.php | 26 ++--- system/Helpers/text_helper.php | 44 +++---- system/Helpers/xml_helper.php | 8 +- system/Security/Security.php | 9 +- system/Session/Handlers/FileHandler.php | 13 +-- system/Session/Handlers/MemcachedHandler.php | 14 +-- system/Session/Handlers/RedisHandler.php | 7 +- system/Test/Mock/MockCURLRequest.php | 4 +- system/Test/Mock/MockCommon.php | 8 +- system/Typography/Typography.php | 8 +- system/Validation/Validation.php | 11 +- ...derscoreToCamelCaseVariableNameRector.php} | 96 ++++++++-------- 30 files changed, 397 insertions(+), 440 deletions(-) rename utils/Rector/{UnderscoreToCamelCaseLocalVariableNameRector.php => UnderscoreToCamelCaseVariableNameRector.php} (56%) diff --git a/app/Config/Mimes.php b/app/Config/Mimes.php index cfeea777c7f2..ce014db338ac 100644 --- a/app/Config/Mimes.php +++ b/app/Config/Mimes.php @@ -497,19 +497,19 @@ public static function guessTypeFromExtension(string $extension) * Attempts to determine the best file extension for a given mime type. * * @param string $type - * @param string|null $proposed_extension - default extension (in case there is more than one with the same mime type) + * @param string|null $proposedExtension - default extension (in case there is more than one with the same mime type) * * @return string|null The extension determined, or null if unable to match. */ - public static function guessExtensionFromType(string $type, string $proposed_extension = null) + public static function guessExtensionFromType(string $type, string $proposedExtension = null) { $type = trim(strtolower($type), '. '); - $proposed_extension = trim(strtolower($proposed_extension)); + $proposedExtension = trim(strtolower($proposedExtension)); - if ($proposed_extension !== '' && array_key_exists($proposed_extension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposed_extension]) ? [static::$mimes[$proposed_extension]] : static::$mimes[$proposed_extension])) + if ($proposedExtension !== '' && array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension])) { - return $proposed_extension; + return $proposedExtension; } foreach (static::$mimes as $ext => $types) diff --git a/rector.php b/rector.php index a0531b4d70cc..3ddb5c5c473f 100644 --- a/rector.php +++ b/rector.php @@ -2,7 +2,7 @@ use Rector\Core\Configuration\Option; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Utils\Rector\UnderscoreToCamelCaseLocalVariableNameRector; +use Utils\Rector\UnderscoreToCamelCaseVariableNameRector; return static function (ContainerConfigurator $containerConfigurator): void { $parameters = $containerConfigurator->parameters(); @@ -25,5 +25,5 @@ ]); $services = $containerConfigurator->services(); - $services->set(UnderscoreToCamelCaseLocalVariableNameRector::class); + $services->set(UnderscoreToCamelCaseVariableNameRector::class); }; diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index c4343dfcbf41..84bde5ac0016 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -813,7 +813,6 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10) } //-------------------------------------------------------------------- - /** * Takes a string and writes it to the command line, wrapping to a maximum * width. If no maximum width is specified, will wrap to the window's max @@ -825,11 +824,11 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10) * * @param string $string * @param integer $max - * @param integer $pad_left + * @param integer $padLeft * * @return string */ - public static function wrap(string $string = null, int $max = 0, int $pad_left = 0): string + public static function wrap(string $string = null, int $max = 0, int $padLeft = 0): string { if (empty($string)) { @@ -846,20 +845,20 @@ public static function wrap(string $string = null, int $max = 0, int $pad_left = $max = CLI::getWidth(); } - $max = $max - $pad_left; + $max = $max - $padLeft; $lines = wordwrap($string, $max, PHP_EOL); - if ($pad_left > 0) + if ($padLeft > 0) { $lines = explode(PHP_EOL, $lines); $first = true; - array_walk($lines, function (&$line, $index) use ($pad_left, &$first) { + array_walk($lines, function (&$line, $index) use ($padLeft, &$first) { if (! $first) { - $line = str_repeat(' ', $pad_left) . $line; + $line = str_repeat(' ', $padLeft) . $line; } else { diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index c4e7c4055f4e..651f3c3968ea 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -373,7 +373,6 @@ protected function writeFile($path, $data, $mode = 'wb') } //-------------------------------------------------------------------- - /** * Delete Files * @@ -382,14 +381,14 @@ protected function writeFile($path, $data, $mode = 'wb') * If the second parameter is set to TRUE, any directories contained * within the supplied base directory will be nuked as well. * - * @param string $path File path - * @param boolean $del_dir Whether to delete any directories found in the path - * @param boolean $htdocs Whether to skip deleting .htaccess and index page files - * @param integer $_level Current directory depth level (default: 0; internal use only) + * @param string $path File path + * @param boolean $delDir Whether to delete any directories found in the path + * @param boolean $htdocs Whether to skip deleting .htaccess and index page files + * @param integer $_level Current directory depth level (default: 0; internal use only) * * @return boolean */ - protected function deleteFiles(string $path, bool $del_dir = false, bool $htdocs = false, int $_level = 0): bool + protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs = false, int $_level = 0): bool { // Trim the trailing slash $path = rtrim($path, '/\\'); @@ -405,7 +404,7 @@ protected function deleteFiles(string $path, bool $del_dir = false, bool $htdocs { if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.') { - $this->deleteFiles($path . DIRECTORY_SEPARATOR . $filename, $del_dir, $htdocs, $_level + 1); + $this->deleteFiles($path . DIRECTORY_SEPARATOR . $filename, $delDir, $htdocs, $_level + 1); } elseif ($htdocs !== true || ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) { @@ -416,11 +415,10 @@ protected function deleteFiles(string $path, bool $del_dir = false, bool $htdocs closedir($currentDir); - return ($del_dir === true && $_level > 0) ? @rmdir($path) : true; + return ($delDir === true && $_level > 0) ? @rmdir($path) : true; } //-------------------------------------------------------------------- - /** * Get Directory File Information * @@ -429,36 +427,36 @@ protected function deleteFiles(string $path, bool $del_dir = false, bool $htdocs * * Any sub-folders contained within the specified path are read as well. * - * @param string $source_dir Path to source - * @param boolean $top_level_only Look only at the top level directory specified? - * @param boolean $_recursion Internal variable to determine recursion status - do not use in calls + * @param string $sourceDir Path to source + * @param boolean $topLevelOnly Look only at the top level directory specified? + * @param boolean $_recursion Internal variable to determine recursion status - do not use in calls * * @return array|false */ - protected function getDirFileInfo(string $source_dir, bool $top_level_only = true, bool $_recursion = false) + protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true, bool $_recursion = false) { static $_filedata = []; - $relativePath = $source_dir; + $relativePath = $sourceDir; - if ($fp = @opendir($source_dir)) + if ($fp = @opendir($sourceDir)) { // reset the array and make sure $source_dir has a trailing slash on the initial call if ($_recursion === false) { - $_filedata = []; - $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + $_filedata = []; + $sourceDir = rtrim(realpath($sourceDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } // Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast while (false !== ($file = readdir($fp))) { - if (is_dir($source_dir . $file) && $file[0] !== '.' && $top_level_only === false) + if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) { - $this->getDirFileInfo($source_dir . $file . DIRECTORY_SEPARATOR, $top_level_only, true); + $this->getDirFileInfo($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true); } elseif ($file[0] !== '.') { - $_filedata[$file] = $this->getFileInfo($source_dir . $file); + $_filedata[$file] = $this->getFileInfo($sourceDir . $file); $_filedata[$file]['relative_path'] = $relativePath; } } @@ -472,7 +470,6 @@ protected function getDirFileInfo(string $source_dir, bool $top_level_only = tru } //-------------------------------------------------------------------- - /** * Get File Info * @@ -481,24 +478,24 @@ protected function getDirFileInfo(string $source_dir, bool $top_level_only = tru * Options are: name, server_path, size, date, readable, writable, executable, fileperms * Returns FALSE if the file cannot be found. * - * @param string $file Path to file - * @param mixed $returned_values Array or comma separated string of information returned + * @param string $file Path to file + * @param mixed $returnedValues Array or comma separated string of information returned * * @return array|false */ - protected function getFileInfo(string $file, $returned_values = ['name', 'server_path', 'size', 'date']) + protected function getFileInfo(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']) { if (! is_file($file)) { return false; } - if (is_string($returned_values)) + if (is_string($returnedValues)) { - $returned_values = explode(',', $returned_values); + $returnedValues = explode(',', $returnedValues); } - foreach ($returned_values as $key) + foreach ($returnedValues as $key) { switch ($key) { diff --git a/system/Common.php b/system/Common.php index 538e351d2a18..206ea2bc95a7 100644 --- a/system/Common.php +++ b/system/Common.php @@ -594,24 +594,24 @@ function force_https(int $duration = 31536000, RequestInterface $request = null, * be just temporary, but would probably be kept for a few years. * * @link http://www.hardened-php.net/suhosin/ - * @param string $function_name Function to check for + * @param string $functionName Function to check for * @return boolean TRUE if the function exists and is safe to call, * FALSE otherwise. * * @codeCoverageIgnore This is too exotic */ - function function_usable(string $function_name): bool + function function_usable(string $functionName): bool { static $_suhosin_func_blacklist; - if (function_exists($function_name)) + if (function_exists($functionName)) { if (! isset($_suhosin_func_blacklist)) { $_suhosin_func_blacklist = extension_loaded('suhosin') ? explode(',', trim(ini_get('suhosin.executor.func.blacklist'))) : []; } - return ! in_array($function_name, $_suhosin_func_blacklist, true); + return ! in_array($functionName, $_suhosin_func_blacklist, true); } return false; diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index 34c9a3bb35d0..c7ce12e997c9 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -201,19 +201,18 @@ public static function __callStatic(string $name, array $arguments) } //-------------------------------------------------------------------- - /** * Reset shared instances and mocks for testing. * - * @param boolean $init_autoloader Initializes autoloader instance + * @param boolean $initAutoloader Initializes autoloader instance */ - public static function reset(bool $init_autoloader = false) + public static function reset(bool $initAutoloader = false) { static::$mocks = []; static::$instances = []; - if ($init_autoloader) + if ($initAutoloader) { static::autoloader()->initialize(new Autoload(), new Modules()); } diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index e5bd9802ec73..43b40461e020 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -745,7 +745,6 @@ public function orWhere($key, $value = null, bool $escape = null) } //-------------------------------------------------------------------- - /** * WHERE, HAVING * @@ -754,7 +753,7 @@ public function orWhere($key, $value = null, bool $escape = null) * @used-by having() * @used-by orHaving() * - * @param string $qb_key 'QBWhere' or 'QBHaving' + * @param string $qbKey 'QBWhere' or 'QBHaving' * @param mixed $key * @param mixed $value * @param string $type @@ -762,7 +761,7 @@ public function orWhere($key, $value = null, bool $escape = null) * * @return BaseBuilder */ - protected function whereHaving(string $qb_key, $key, $value = null, string $type = 'AND ', bool $escape = null) + protected function whereHaving(string $qbKey, $key, $value = null, string $type = 'AND ', bool $escape = null) { if (! is_array($key)) { @@ -774,7 +773,7 @@ protected function whereHaving(string $qb_key, $key, $value = null, string $type foreach ($key as $k => $v) { - $prefix = empty($this->$qb_key) ? $this->groupGetType('') : $this->groupGetType($type); + $prefix = empty($this->$qbKey) ? $this->groupGetType('') : $this->groupGetType($type); if ($v !== null) { @@ -815,7 +814,7 @@ protected function whereHaving(string $qb_key, $key, $value = null, string $type $v = " :$bind:"; } } - elseif (! $this->hasOperator($k) && $qb_key !== 'QBHaving') + elseif (! $this->hasOperator($k) && $qbKey !== 'QBHaving') { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; @@ -825,7 +824,7 @@ protected function whereHaving(string $qb_key, $key, $value = null, string $type $k = substr($k, 0, $match[0][1]) . ($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL'); } - $this->{$qb_key}[] = [ + $this->{$qbKey}[] = [ 'condition' => $prefix . $k . $v, 'escape' => $escape, ]; @@ -2803,20 +2802,19 @@ public function getCompiledDelete(bool $reset = true): string } //-------------------------------------------------------------------- - /** * Delete * * Compiles a delete string and runs the query * - * @param mixed $where The where clause - * @param integer $limit The limit clause - * @param boolean $reset_data + * @param mixed $where The where clause + * @param integer $limit The limit clause + * @param boolean $resetData * * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function delete($where = '', int $limit = null, bool $reset_data = true) + public function delete($where = '', int $limit = null, bool $resetData = true) { $table = $this->db->protectIdentifiers($this->QBFrom[0], true, null, false); @@ -2853,7 +2851,7 @@ public function delete($where = '', int $limit = null, bool $reset_data = true) $sql = $this->_limit($sql, true); } - if ($reset_data) + if ($resetData) { $this->resetWrite(); } @@ -2959,23 +2957,22 @@ protected function trackAliases($table) } //-------------------------------------------------------------------- - /** * Compile the SELECT statement * * Generates a query string based on which functions were used. * Should not be called directly. * - * @param mixed $select_override + * @param mixed $selectOverride * * @return string */ - protected function compileSelect($select_override = false): string + protected function compileSelect($selectOverride = false): string { // Write the "select" portion of the query - if ($select_override !== false) + if ($selectOverride !== false) { - $sql = $select_override; + $sql = $selectOverride; } else { @@ -3052,7 +3049,6 @@ protected function compileIgnore(string $statement) } //-------------------------------------------------------------------- - /** * Compile WHERE, HAVING statements * @@ -3062,15 +3058,15 @@ protected function compileIgnore(string $statement) * where(), orWhere(), having(), orHaving are called prior to from(), * join() and prefixTable is added only if needed. * - * @param string $qb_key 'QBWhere' or 'QBHaving' + * @param string $qbKey 'QBWhere' or 'QBHaving' * * @return string SQL statement */ - protected function compileWhereHaving(string $qb_key): string + protected function compileWhereHaving(string $qbKey): string { - if (! empty($this->$qb_key)) + if (! empty($this->$qbKey)) { - foreach ($this->$qb_key as &$qbkey) + foreach ($this->$qbKey as &$qbkey) { // Is this condition already compiled? if (is_string($qbkey)) @@ -3129,8 +3125,8 @@ protected function compileWhereHaving(string $qb_key): string $qbkey = implode('', $conditions); } - return ($qb_key === 'QBHaving' ? "\nHAVING " : "\nWHERE ") - . implode("\n", $this->$qb_key); + return ($qbKey === 'QBHaving' ? "\nHAVING " : "\nWHERE ") + . implode("\n", $this->$qbKey); } return ''; @@ -3328,17 +3324,16 @@ public function resetQuery() } //-------------------------------------------------------------------- - /** * Resets the query builder values. Called by the get() function * - * @param array $qb_reset_items An array of fields to reset + * @param array $qbResetItems An array of fields to reset * * @return void */ - protected function resetRun(array $qb_reset_items) + protected function resetRun(array $qbResetItems) { - foreach ($qb_reset_items as $item => $defaultValue) + foreach ($qbResetItems as $item => $defaultValue) { $this->$item = $defaultValue; } diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 693ae210857e..b8e2e5ee3615 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -762,21 +762,20 @@ public function transStrict(bool $mode = true) } //-------------------------------------------------------------------- - /** * Start Transaction * - * @param boolean $test_mode = FALSE + * @param boolean $testMode = FALSE * @return boolean */ - public function transStart(bool $test_mode = false): bool + public function transStart(bool $testMode = false): bool { if (! $this->transEnabled) { return false; } - return $this->transBegin($test_mode); + return $this->transBegin($testMode); } //-------------------------------------------------------------------- @@ -826,14 +825,13 @@ public function transStatus(): bool } //-------------------------------------------------------------------- - /** * Begin Transaction * - * @param boolean $test_mode + * @param boolean $testMode * @return boolean */ - public function transBegin(bool $test_mode = false): bool + public function transBegin(bool $testMode = false): bool { if (! $this->transEnabled) { @@ -855,7 +853,7 @@ public function transBegin(bool $test_mode = false): bool // Reset the transaction failure flag. // If the $test_mode flag is set to TRUE transactions will be rolled back // even if the queries produce a successful result. - $this->transFailure = ($test_mode === true); + $this->transFailure = ($testMode === true); if ($this->_transBegin()) { diff --git a/system/Database/BaseUtils.php b/system/Database/BaseUtils.php index 567403d78168..ed5778f4cfd1 100644 --- a/system/Database/BaseUtils.php +++ b/system/Database/BaseUtils.php @@ -131,28 +131,26 @@ public function listDatabases() } //-------------------------------------------------------------------- - /** * Determine if a particular database exists * - * @param string $database_name + * @param string $databaseName * @return boolean */ - public function databaseExists(string $database_name): bool + public function databaseExists(string $databaseName): bool { - return in_array($database_name, $this->listDatabases(), true); + return in_array($databaseName, $this->listDatabases(), true); } //-------------------------------------------------------------------- - /** * Optimize Table * - * @param string $table_name + * @param string $tableName * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function optimizeTable(string $table_name) + public function optimizeTable(string $tableName) { if ($this->optimizeTable === false) { @@ -163,7 +161,7 @@ public function optimizeTable(string $table_name) return false; } - $query = $this->db->query(sprintf($this->optimizeTable, $this->db->escapeIdentifiers($table_name))); + $query = $this->db->query(sprintf($this->optimizeTable, $this->db->escapeIdentifiers($tableName))); if ($query !== false) { $query = $query->getResultArray(); @@ -225,15 +223,14 @@ public function optimizeDatabase() } //-------------------------------------------------------------------- - /** * Repair Table * - * @param string $table_name + * @param string $tableName * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function repairTable(string $table_name) + public function repairTable(string $tableName) { if ($this->repairTable === false) { @@ -244,7 +241,7 @@ public function repairTable(string $table_name) return false; } - $query = $this->db->query(sprintf($this->repairTable, $this->db->escapeIdentifiers($table_name))); + $query = $this->db->query(sprintf($this->repairTable, $this->db->escapeIdentifiers($tableName))); if (is_bool($query)) { return $query; diff --git a/system/Database/Forge.php b/system/Database/Forge.php index c3fb1b6f2b34..05be7e7ee3df 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -492,18 +492,17 @@ public function dropForeignKey(string $table, string $foreignName) } //-------------------------------------------------------------------- - /** * Create Table * - * @param string $table Table name - * @param boolean $if_not_exists Whether to add IF NOT EXISTS condition - * @param array $attributes Associative array of table attributes + * @param string $table Table name + * @param boolean $ifNotExists Whether to add IF NOT EXISTS condition + * @param array $attributes Associative array of table attributes * * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function createTable(string $table, bool $if_not_exists = false, array $attributes = []) + public function createTable(string $table, bool $ifNotExists = false, array $attributes = []) { if ($table === '') { @@ -517,7 +516,7 @@ public function createTable(string $table, bool $if_not_exists = false, array $a throw new \RuntimeException('Field information is required.'); } - $sql = $this->_createTable($table, $if_not_exists, $attributes); + $sql = $this->_createTable($table, $ifNotExists, $attributes); if (is_bool($sql)) { @@ -556,30 +555,29 @@ public function createTable(string $table, bool $if_not_exists = false, array $a } //-------------------------------------------------------------------- - /** * Create Table * - * @param string $table Table name - * @param boolean $if_not_exists Whether to add 'IF NOT EXISTS' condition - * @param array $attributes Associative array of table attributes + * @param string $table Table name + * @param boolean $ifNotExists Whether to add 'IF NOT EXISTS' condition + * @param array $attributes Associative array of table attributes * * @return mixed */ - protected function _createTable(string $table, bool $if_not_exists, array $attributes) + protected function _createTable(string $table, bool $ifNotExists, array $attributes) { // For any platforms that don't support Create If Not Exists... - if ($if_not_exists === true && $this->createTableIfStr === false) + if ($ifNotExists === true && $this->createTableIfStr === false) { if ($this->db->tableExists($table)) { return true; } - $if_not_exists = false; + $ifNotExists = false; } - $sql = ($if_not_exists) ? sprintf($this->createTableIfStr, $this->db->escapeIdentifiers($table)) + $sql = ($ifNotExists) ? sprintf($this->createTableIfStr, $this->db->escapeIdentifiers($table)) : 'CREATE TABLE'; $columns = $this->_processFields(true); @@ -691,23 +689,22 @@ public function dropTable(string $tableName, bool $ifExists = false, bool $casca } //-------------------------------------------------------------------- - /** * Drop Table * * Generates a platform-specific DROP TABLE string * - * @param string $table Table name - * @param boolean $if_exists Whether to add an IF EXISTS condition - * @param boolean $cascade Whether to add an CASCADE condition + * @param string $table Table name + * @param boolean $ifExists Whether to add an IF EXISTS condition + * @param boolean $cascade Whether to add an CASCADE condition * * @return string|boolean */ - protected function _dropTable(string $table, bool $if_exists, bool $cascade) + protected function _dropTable(string $table, bool $ifExists, bool $cascade) { $sql = 'DROP TABLE'; - if ($if_exists) + if ($ifExists) { if ($this->dropTableIfStr === false) { @@ -726,19 +723,18 @@ protected function _dropTable(string $table, bool $if_exists, bool $cascade) } //-------------------------------------------------------------------- - /** * Rename Table * - * @param string $table_name Old table name - * @param string $new_table_name New table name + * @param string $tableName Old table name + * @param string $newTableName New table name * * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function renameTable(string $table_name, string $new_table_name) + public function renameTable(string $tableName, string $newTableName) { - if ($table_name === '' || $new_table_name === '') + if ($tableName === '' || $newTableName === '') { throw new \InvalidArgumentException('A table name is required for that operation.'); } @@ -754,17 +750,17 @@ public function renameTable(string $table_name, string $new_table_name) } $result = $this->db->query(sprintf($this->renameTableStr, - $this->db->escapeIdentifiers($this->db->DBPrefix . $table_name), - $this->db->escapeIdentifiers($this->db->DBPrefix . $new_table_name)) + $this->db->escapeIdentifiers($this->db->DBPrefix . $tableName), + $this->db->escapeIdentifiers($this->db->DBPrefix . $newTableName)) ); if ($result && ! empty($this->db->dataCache['table_names'])) { - $key = array_search(strtolower($this->db->DBPrefix . $table_name), + $key = array_search(strtolower($this->db->DBPrefix . $tableName), array_map('strtolower', $this->db->dataCache['table_names']), true); if ($key !== false) { - $this->db->dataCache['table_names'][$key] = $this->db->DBPrefix . $new_table_name; + $this->db->dataCache['table_names'][$key] = $this->db->DBPrefix . $newTableName; } } @@ -816,19 +812,18 @@ public function addColumn(string $table, $field): bool } //-------------------------------------------------------------------- - /** * Column Drop * - * @param string $table Table name - * @param string|array $column_name Column name Array or comma separated + * @param string $table Table name + * @param string|array $columnName Column name Array or comma separated * * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function dropColumn(string $table, $column_name) + public function dropColumn(string $table, $columnName) { - $sql = $this->_alterTable('DROP', $this->db->DBPrefix . $table, $column_name); + $sql = $this->_alterTable('DROP', $this->db->DBPrefix . $table, $columnName); if ($sql === false) { if ($this->db->DBDebug) @@ -895,22 +890,21 @@ public function modifyColumn(string $table, $field): bool } //-------------------------------------------------------------------- - /** * ALTER TABLE * - * @param string $alter_type ALTER type - * @param string $table Table name - * @param mixed $fields Column definition + * @param string $alterType ALTER type + * @param string $table Table name + * @param mixed $fields Column definition * * @return string|string[]|false */ - protected function _alterTable(string $alter_type, string $table, $fields) + protected function _alterTable(string $alterType, string $table, $fields) { $sql = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table) . ' '; // DROP has everything it needs now. - if ($alter_type === 'DROP') + if ($alterType === 'DROP') { if (is_string($fields)) { @@ -924,7 +918,7 @@ protected function _alterTable(string $alter_type, string $table, $fields) return $sql . implode(', ', $fields); } - $sql .= ($alter_type === 'ADD') ? 'ADD ' : $alter_type . ' COLUMN '; + $sql .= ($alterType === 'ADD') ? 'ADD ' : $alterType . ' COLUMN '; $sqls = []; foreach ($fields as $data) @@ -937,15 +931,14 @@ protected function _alterTable(string $alter_type, string $table, $fields) } //-------------------------------------------------------------------- - /** * Process fields * - * @param boolean $create_table + * @param boolean $createTable * * @return array */ - protected function _processFields(bool $create_table = false): array + protected function _processFields(bool $createTable = false): array { $fields = []; @@ -959,7 +952,7 @@ protected function _processFields(bool $create_table = false): array $attributes = array_change_key_case($attributes, CASE_UPPER); - if ($create_table === true && empty($attributes['TYPE'])) + if ($createTable === true && empty($attributes['TYPE'])) { continue; } @@ -983,7 +976,7 @@ protected function _processFields(bool $create_table = false): array // @phpstan-ignore-next-line isset($attributes['TYPE']) && $this->_attributeUnsigned($attributes, $field); - if ($create_table === false) + if ($createTable === false) { if (isset($attributes['AFTER'])) { @@ -1008,7 +1001,7 @@ protected function _processFields(bool $create_table = false): array $field['null'] = ' NOT NULL'; } } - elseif ($create_table === true) + elseif ($createTable === true) { $field['null'] = ' NOT NULL'; } diff --git a/system/Database/MySQLi/Forge.php b/system/Database/MySQLi/Forge.php index 6dd7c40c4b08..9cbba78e51f5 100644 --- a/system/Database/MySQLi/Forge.php +++ b/system/Database/MySQLi/Forge.php @@ -161,20 +161,19 @@ protected function _createTableAttributes(array $attributes): string } //-------------------------------------------------------------------- - /** * ALTER TABLE * - * @param string $alter_type ALTER type - * @param string $table Table name - * @param mixed $field Column definition + * @param string $alterType ALTER type + * @param string $table Table name + * @param mixed $field Column definition * @return string|string[] */ - protected function _alterTable(string $alter_type, string $table, $field) + protected function _alterTable(string $alterType, string $table, $field) { - if ($alter_type === 'DROP') + if ($alterType === 'DROP') { - return parent::_alterTable($alter_type, $table, $field); + return parent::_alterTable($alterType, $table, $field); } $sql = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table); @@ -182,11 +181,11 @@ protected function _alterTable(string $alter_type, string $table, $field) { if ($data['_literal'] !== false) { - $field[$i] = ($alter_type === 'ADD') ? "\n\tADD " . $data['_literal'] : "\n\tMODIFY " . $data['_literal']; + $field[$i] = ($alterType === 'ADD') ? "\n\tADD " . $data['_literal'] : "\n\tMODIFY " . $data['_literal']; } else { - if ($alter_type === 'ADD') + if ($alterType === 'ADD') { $field[$i]['_literal'] = "\n\tADD "; } diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index b8b38a07dc31..25027d49d6ab 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -233,7 +233,6 @@ public function replace(array $set = null) } //-------------------------------------------------------------------- - /** * Delete * @@ -241,7 +240,7 @@ public function replace(array $set = null) * * @param mixed $where * @param integer $limit - * @param boolean $reset_data + * @param boolean $resetData * * @return mixed * @throws DatabaseException @@ -249,14 +248,14 @@ public function replace(array $set = null) * @internal param the $mixed limit clause * @internal param $bool */ - public function delete($where = '', int $limit = null, bool $reset_data = true) + public function delete($where = '', int $limit = null, bool $resetData = true) { if (! empty($limit) || ! empty($this->QBLimit)) { throw new DatabaseException('PostgreSQL does not allow LIMITs on DELETE queries.'); } - return parent::delete($where, $limit, $reset_data); + return parent::delete($where, $limit, $resetData); } //-------------------------------------------------------------------- diff --git a/system/Database/Postgre/Forge.php b/system/Database/Postgre/Forge.php index c4c45e3a42da..65395ce3a37a 100644 --- a/system/Database/Postgre/Forge.php +++ b/system/Database/Postgre/Forge.php @@ -97,21 +97,20 @@ protected function _createTableAttributes(array $attributes): string } //-------------------------------------------------------------------- - /** * ALTER TABLE * - * @param string $alter_type ALTER type - * @param string $table Table name - * @param mixed $field Column definition + * @param string $alterType ALTER type + * @param string $table Table name + * @param mixed $field Column definition * * @return string|array|boolean */ - protected function _alterTable(string $alter_type, string $table, $field) + protected function _alterTable(string $alterType, string $table, $field) { - if (in_array($alter_type, ['DROP', 'ADD'], true)) + if (in_array($alterType, ['DROP', 'ADD'], true)) { - return parent::_alterTable($alter_type, $table, $field); + return parent::_alterTable($alterType, $table, $field); } $sql = 'ALTER TABLE ' . $this->db->escapeIdentifiers($table); @@ -232,21 +231,20 @@ protected function _attributeAutoIncrement(array &$attributes, array &$field) } //-------------------------------------------------------------------- - /** * Drop Table * * Generates a platform-specific DROP TABLE string * - * @param string $table Table name - * @param boolean $if_exists Whether to add an IF EXISTS condition + * @param string $table Table name + * @param boolean $ifExists Whether to add an IF EXISTS condition * @param boolean $cascade * * @return string */ - protected function _dropTable(string $table, bool $if_exists, bool $cascade): string + protected function _dropTable(string $table, bool $ifExists, bool $cascade): string { - $sql = parent::_dropTable($table, $if_exists, $cascade); + $sql = parent::_dropTable($table, $ifExists, $cascade); if ($cascade === true) { diff --git a/system/Database/SQLite3/Forge.php b/system/Database/SQLite3/Forge.php index 3591b05595e6..bd4a34273045 100644 --- a/system/Database/SQLite3/Forge.php +++ b/system/Database/SQLite3/Forge.php @@ -145,19 +145,18 @@ public function dropDatabase(string $dbName): bool } //-------------------------------------------------------------------- - /** * ALTER TABLE * - * @param string $alter_type ALTER type - * @param string $table Table name - * @param mixed $field Column definition + * @param string $alterType ALTER type + * @param string $table Table name + * @param mixed $field Column definition * * @return string|array|null */ - protected function _alterTable(string $alter_type, string $table, $field) + protected function _alterTable(string $alterType, string $table, $field) { - switch ($alter_type) + switch ($alterType) { case 'DROP': $sqlTable = new Table($this->db, $this); @@ -176,7 +175,7 @@ protected function _alterTable(string $alter_type, string $table, $field) return null; default: - return parent::_alterTable($alter_type, $table, $field); + return parent::_alterTable($alterType, $table, $field); } } diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 3476da6b28d9..46b83690cb41 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -227,21 +227,20 @@ public function shutdownHandler() } //-------------------------------------------------------------------- - /** * Determines the view to display based on the exception thrown, * whether an HTTP or CLI request, etc. * * @param \Throwable $exception - * @param string $template_path + * @param string $templatePath * * @return string The path and filename of the view file to use */ - protected function determineView(Throwable $exception, string $template_path): string + protected function determineView(Throwable $exception, string $templatePath): string { // Production environments should have a custom exception file. - $view = 'production.php'; - $template_path = rtrim($template_path, '\\/ ') . DIRECTORY_SEPARATOR; + $view = 'production.php'; + $templatePath = rtrim($templatePath, '\\/ ') . DIRECTORY_SEPARATOR; if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors'))) { @@ -255,7 +254,7 @@ protected function determineView(Throwable $exception, string $template_path): s } // Allow for custom views based upon the status code - if (is_file($template_path . 'error_' . $exception->getCode() . '.php')) + if (is_file($templatePath . 'error_' . $exception->getCode() . '.php')) { return 'error_' . $exception->getCode() . '.php'; } diff --git a/system/Events/Events.php b/system/Events/Events.php index 1c236ee5906b..8f690274ac38 100644 --- a/system/Events/Events.php +++ b/system/Events/Events.php @@ -126,7 +126,6 @@ public static function initialize() } //-------------------------------------------------------------------- - /** * Registers an action to happen on an event. The action can be any sort * of callable: @@ -136,15 +135,15 @@ public static function initialize() * Events::on('create', [$myInstance, 'myMethod']); // Method on an existing instance * Events::on('create', function() {}); // Closure * - * @param string $event_name + * @param string $eventName * @param callable $callback * @param integer $priority */ - public static function on($event_name, $callback, $priority = EVENT_PRIORITY_NORMAL) + public static function on($eventName, $callback, $priority = EVENT_PRIORITY_NORMAL) { - if (! isset(static::$listeners[$event_name])) + if (! isset(static::$listeners[$eventName])) { - static::$listeners[$event_name] = [ + static::$listeners[$eventName] = [ true, // If there's only 1 item, it's sorted. [$priority], [$callback], @@ -152,9 +151,9 @@ public static function on($event_name, $callback, $priority = EVENT_PRIORITY_NOR } else { - static::$listeners[$event_name][0] = false; // Not sorted - static::$listeners[$event_name][1][] = $priority; - static::$listeners[$event_name][2][] = $callback; + static::$listeners[$eventName][0] = false; // Not sorted + static::$listeners[$eventName][1][] = $priority; + static::$listeners[$eventName][2][] = $callback; } } @@ -206,7 +205,6 @@ public static function trigger($eventName, ...$arguments): bool } //-------------------------------------------------------------------- - /** * Returns an array of listeners for a single event. They are * sorted by priority. @@ -214,56 +212,55 @@ public static function trigger($eventName, ...$arguments): bool * If the listener could not be found, returns FALSE, or TRUE if * it was removed. * - * @param string $event_name + * @param string $eventName * * @return array */ - public static function listeners($event_name): array + public static function listeners($eventName): array { - if (! isset(static::$listeners[$event_name])) + if (! isset(static::$listeners[$eventName])) { return []; } // The list is not sorted - if (! static::$listeners[$event_name][0]) + if (! static::$listeners[$eventName][0]) { // Sort it! - array_multisort(static::$listeners[$event_name][1], SORT_NUMERIC, static::$listeners[$event_name][2]); + array_multisort(static::$listeners[$eventName][1], SORT_NUMERIC, static::$listeners[$eventName][2]); // Mark it as sorted already! - static::$listeners[$event_name][0] = true; + static::$listeners[$eventName][0] = true; } - return static::$listeners[$event_name][2]; + return static::$listeners[$eventName][2]; } //-------------------------------------------------------------------- - /** * Removes a single listener from an event. * * If the listener couldn't be found, returns FALSE, else TRUE if * it was removed. * - * @param string $event_name + * @param string $eventName * @param callable $listener * * @return boolean */ - public static function removeListener($event_name, callable $listener): bool + public static function removeListener($eventName, callable $listener): bool { - if (! isset(static::$listeners[$event_name])) + if (! isset(static::$listeners[$eventName])) { return false; } - foreach (static::$listeners[$event_name][2] as $index => $check) + foreach (static::$listeners[$eventName][2] as $index => $check) { if ($check === $listener) { - unset(static::$listeners[$event_name][1][$index]); - unset(static::$listeners[$event_name][2][$index]); + unset(static::$listeners[$eventName][1][$index]); + unset(static::$listeners[$eventName][2][$index]); return true; } @@ -273,20 +270,19 @@ public static function removeListener($event_name, callable $listener): bool } //-------------------------------------------------------------------- - /** * Removes all listeners. * * If the event_name is specified, only listeners for that event will be * removed, otherwise all listeners for all events are removed. * - * @param string|null $event_name + * @param string|null $eventName */ - public static function removeAllListeners($event_name = null) + public static function removeAllListeners($eventName = null) { - if (! is_null($event_name)) + if (! is_null($eventName)) { - unset(static::$listeners[$event_name]); + unset(static::$listeners[$eventName]); } else { diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 33547796da34..d01c7e213ab9 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -485,16 +485,15 @@ public function send(string $method, string $url) } //-------------------------------------------------------------------- - /** * Takes all headers current part of this request and adds them * to the cURL request. * - * @param array $curl_options + * @param array $curlOptions * * @return array */ - protected function applyRequestHeaders(array $curl_options = []): array + protected function applyRequestHeaders(array $curlOptions = []): array { if (empty($this->headers)) { @@ -508,7 +507,7 @@ protected function applyRequestHeaders(array $curl_options = []): array if (empty($headers)) { - return $curl_options; + return $curlOptions; } $set = []; @@ -518,34 +517,33 @@ protected function applyRequestHeaders(array $curl_options = []): array $set[] = $name . ': ' . $this->getHeaderLine($name); } - $curl_options[CURLOPT_HTTPHEADER] = $set; + $curlOptions[CURLOPT_HTTPHEADER] = $set; - return $curl_options; + return $curlOptions; } //-------------------------------------------------------------------- - /** * Apply method * * @param string $method - * @param array $curl_options + * @param array $curlOptions * * @return array */ - protected function applyMethod(string $method, array $curl_options): array + protected function applyMethod(string $method, array $curlOptions): array { $method = strtoupper($method); - $this->method = $method; - $curl_options[CURLOPT_CUSTOMREQUEST] = $method; + $this->method = $method; + $curlOptions[CURLOPT_CUSTOMREQUEST] = $method; $size = strlen($this->body); // Have content? if ($size > 0) { - return $this->applyBody($curl_options); + return $this->applyBody($curlOptions); } if ($method === 'PUT' || $method === 'POST') @@ -558,29 +556,28 @@ protected function applyMethod(string $method, array $curl_options): array } else if ($method === 'HEAD') { - $curl_options[CURLOPT_NOBODY] = 1; + $curlOptions[CURLOPT_NOBODY] = 1; } - return $curl_options; + return $curlOptions; } //-------------------------------------------------------------------- - /** * Apply body * - * @param array $curl_options + * @param array $curlOptions * * @return array */ - protected function applyBody(array $curl_options = []): array + protected function applyBody(array $curlOptions = []): array { if (! empty($this->body)) { - $curl_options[CURLOPT_POSTFIELDS] = (string) $this->getBody(); + $curlOptions[CURLOPT_POSTFIELDS] = (string) $this->getBody(); } - return $curl_options; + return $curlOptions; } //-------------------------------------------------------------------- @@ -620,29 +617,28 @@ protected function setResponseHeaders(array $headers = []) } //-------------------------------------------------------------------- - /** * Set CURL options * - * @param array $curl_options + * @param array $curlOptions * @param array $config * @return array * @throws \InvalidArgumentException */ - protected function setCURLOptions(array $curl_options = [], array $config = []) + protected function setCURLOptions(array $curlOptions = [], array $config = []) { // Auth Headers if (! empty($config['auth'])) { - $curl_options[CURLOPT_USERPWD] = $config['auth'][0] . ':' . $config['auth'][1]; + $curlOptions[CURLOPT_USERPWD] = $config['auth'][0] . ':' . $config['auth'][1]; if (! empty($config['auth'][2]) && strtolower($config['auth'][2]) === 'digest') { - $curl_options[CURLOPT_HTTPAUTH] = CURLAUTH_DIGEST; + $curlOptions[CURLOPT_HTTPAUTH] = CURLAUTH_DIGEST; } else { - $curl_options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC; + $curlOptions[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC; } } @@ -653,8 +649,8 @@ protected function setCURLOptions(array $curl_options = [], array $config = []) if (is_array($cert)) { - $curl_options[CURLOPT_SSLCERTPASSWD] = $cert[1]; - $cert = $cert[0]; + $curlOptions[CURLOPT_SSLCERTPASSWD] = $cert[1]; + $cert = $cert[0]; } if (! is_file($cert)) @@ -662,7 +658,7 @@ protected function setCURLOptions(array $curl_options = [], array $config = []) throw HTTPException::forSSLCertNotFound($cert); } - $curl_options[CURLOPT_SSLCERT] = $cert; + $curlOptions[CURLOPT_SSLCERT] = $cert; } // SSL Verification @@ -677,20 +673,20 @@ protected function setCURLOptions(array $curl_options = [], array $config = []) throw HTTPException::forInvalidSSLKey($config['ssl_key']); } - $curl_options[CURLOPT_CAINFO] = $file; - $curl_options[CURLOPT_SSL_VERIFYPEER] = 1; + $curlOptions[CURLOPT_CAINFO] = $file; + $curlOptions[CURLOPT_SSL_VERIFYPEER] = 1; } else if (is_bool($config['verify'])) { - $curl_options[CURLOPT_SSL_VERIFYPEER] = $config['verify']; + $curlOptions[CURLOPT_SSL_VERIFYPEER] = $config['verify']; } } // Debug if ($config['debug']) { - $curl_options[CURLOPT_VERBOSE] = 1; - $curl_options[CURLOPT_STDERR] = is_string($config['debug']) ? fopen($config['debug'], 'a+') : fopen('php://stderr', 'w'); + $curlOptions[CURLOPT_VERBOSE] = 1; + $curlOptions[CURLOPT_STDERR] = is_string($config['debug']) ? fopen($config['debug'], 'a+') : fopen('php://stderr', 'w'); } // Decode Content @@ -700,12 +696,12 @@ protected function setCURLOptions(array $curl_options = [], array $config = []) if ($accept) { - $curl_options[CURLOPT_ENCODING] = $accept; + $curlOptions[CURLOPT_ENCODING] = $accept; } else { - $curl_options[CURLOPT_ENCODING] = ''; - $curl_options[CURLOPT_HTTPHEADER] = 'Accept-Encoding'; + $curlOptions[CURLOPT_ENCODING] = ''; + $curlOptions[CURLOPT_HTTPHEADER] = 'Accept-Encoding'; } } @@ -721,16 +717,16 @@ protected function setCURLOptions(array $curl_options = [], array $config = []) if ($config['allow_redirects'] === false) { - $curl_options[CURLOPT_FOLLOWLOCATION] = 0; + $curlOptions[CURLOPT_FOLLOWLOCATION] = 0; } else { - $curl_options[CURLOPT_FOLLOWLOCATION] = 1; - $curl_options[CURLOPT_MAXREDIRS] = $settings['max']; + $curlOptions[CURLOPT_FOLLOWLOCATION] = 1; + $curlOptions[CURLOPT_MAXREDIRS] = $settings['max']; if ($settings['strict'] === true) { - $curl_options[CURLOPT_POSTREDIR] = 1 | 2 | 4; + $curlOptions[CURLOPT_POSTREDIR] = 1 | 2 | 4; } $protocols = 0; @@ -739,21 +735,21 @@ protected function setCURLOptions(array $curl_options = [], array $config = []) $protocols += constant('CURLPROTO_' . strtoupper($proto)); } - $curl_options[CURLOPT_REDIR_PROTOCOLS] = $protocols; + $curlOptions[CURLOPT_REDIR_PROTOCOLS] = $protocols; } } // Timeout - $curl_options[CURLOPT_TIMEOUT_MS] = (float) $config['timeout'] * 1000; + $curlOptions[CURLOPT_TIMEOUT_MS] = (float) $config['timeout'] * 1000; // Connection Timeout - $curl_options[CURLOPT_CONNECTTIMEOUT_MS] = (float) $config['connect_timeout'] * 1000; + $curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = (float) $config['connect_timeout'] * 1000; // Post Data - application/x-www-form-urlencoded if (! empty($config['form_params']) && is_array($config['form_params'])) { - $postFields = http_build_query($config['form_params']); - $curl_options[CURLOPT_POSTFIELDS] = $postFields; + $postFields = http_build_query($config['form_params']); + $curlOptions[CURLOPT_POSTFIELDS] = $postFields; // Ensure content-length is set, since CURL doesn't seem to // calculate it when HTTPHEADER is set. @@ -765,11 +761,11 @@ protected function setCURLOptions(array $curl_options = [], array $config = []) if (! empty($config['multipart']) && is_array($config['multipart'])) { // setting the POSTFIELDS option automatically sets multipart - $curl_options[CURLOPT_POSTFIELDS] = $config['multipart']; + $curlOptions[CURLOPT_POSTFIELDS] = $config['multipart']; } // HTTP Errors - $curl_options[CURLOPT_FAILONERROR] = array_key_exists('http_errors', $config) ? (bool) $config['http_errors'] : true; + $curlOptions[CURLOPT_FAILONERROR] = array_key_exists('http_errors', $config) ? (bool) $config['http_errors'] : true; // JSON if (isset($config['json'])) @@ -786,41 +782,40 @@ protected function setCURLOptions(array $curl_options = [], array $config = []) { if ($config['version'] === 1.0) { - $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; + $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; } else if ($config['version'] === 1.1) { - $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; + $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; } } // Cookie if (isset($config['cookie'])) { - $curl_options[CURLOPT_COOKIEJAR] = $config['cookie']; - $curl_options[CURLOPT_COOKIEFILE] = $config['cookie']; + $curlOptions[CURLOPT_COOKIEJAR] = $config['cookie']; + $curlOptions[CURLOPT_COOKIEFILE] = $config['cookie']; } - return $curl_options; + return $curlOptions; } //-------------------------------------------------------------------- - /** * Does the actual work of initializing cURL, setting the options, * and grabbing the output. * * @codeCoverageIgnore * - * @param array $curl_options + * @param array $curlOptions * * @return string */ - protected function sendRequest(array $curl_options = []): string + protected function sendRequest(array $curlOptions = []): string { $ch = curl_init(); - curl_setopt_array($ch, $curl_options); + curl_setopt_array($ch, $curlOptions); // Send the request and wait for a response. $output = curl_exec($ch); diff --git a/system/Helpers/filesystem_helper.php b/system/Helpers/filesystem_helper.php index 368803548792..3e23914bcf17 100644 --- a/system/Helpers/filesystem_helper.php +++ b/system/Helpers/filesystem_helper.php @@ -54,22 +54,22 @@ * representation of it. Sub-folders contained with the * directory will be mapped as well. * - * @param string $source_dir Path to source - * @param integer $directory_depth Depth of directories to traverse + * @param string $sourceDir Path to source + * @param integer $directoryDepth Depth of directories to traverse * (0 = fully recursive, 1 = current dir, etc) - * @param boolean $hidden Whether to show hidden files + * @param boolean $hidden Whether to show hidden files * * @return array */ - function directory_map(string $source_dir, int $directory_depth = 0, bool $hidden = false): array + function directory_map(string $sourceDir, int $directoryDepth = 0, bool $hidden = false): array { try { - $fp = opendir($source_dir); + $fp = opendir($sourceDir); - $fileData = []; - $newDepth = $directory_depth - 1; - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + $fileData = []; + $newDepth = $directoryDepth - 1; + $sourceDir = rtrim($sourceDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; while (false !== ($file = readdir($fp))) { @@ -79,11 +79,11 @@ function directory_map(string $source_dir, int $directory_depth = 0, bool $hidde continue; } - is_dir($source_dir . $file) && $file .= DIRECTORY_SEPARATOR; + is_dir($sourceDir . $file) && $file .= DIRECTORY_SEPARATOR; - if (($directory_depth < 1 || $newDepth > 0) && is_dir($source_dir . $file)) + if (($directoryDepth < 1 || $newDepth > 0) && is_dir($sourceDir . $file)) { - $fileData[$file] = directory_map($source_dir . $file, $newDepth, $hidden); + $fileData[$file] = directory_map($sourceDir . $file, $newDepth, $hidden); } else { @@ -157,14 +157,14 @@ function write_file(string $path, string $data, string $mode = 'wb'): bool * If the second parameter is set to true, any directories contained * within the supplied base directory will be nuked as well. * - * @param string $path File path - * @param boolean $del_dir Whether to delete any directories found in the path - * @param boolean $htdocs Whether to skip deleting .htaccess and index page files - * @param boolean $hidden Whether to include hidden files (files beginning with a period) + * @param string $path File path + * @param boolean $delDir Whether to delete any directories found in the path + * @param boolean $htdocs Whether to skip deleting .htaccess and index page files + * @param boolean $hidden Whether to include hidden files (files beginning with a period) * * @return boolean */ - function delete_files(string $path, bool $del_dir = false, bool $htdocs = false, bool $hidden = false): bool + function delete_files(string $path, bool $delDir = false, bool $htdocs = false, bool $hidden = false): bool { $path = realpath($path) ?: $path; $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; @@ -186,7 +186,7 @@ function delete_files(string $path, bool $del_dir = false, bool $htdocs = false, { $isDir = $object->isDir(); - if ($isDir && $del_dir) + if ($isDir && $delDir) { @rmdir($object->getPathname()); continue; @@ -218,23 +218,23 @@ function delete_files(string $path, bool $del_dir = false, bool $htdocs = false, * Reads the specified directory and builds an array containing the filenames. * Any sub-folders contained within the specified path are read as well. * - * @param string $source_dir Path to source - * @param boolean|null $include_path Whether to include the path as part of the filename; false for no path, null for a relative path, true for full path - * @param boolean $hidden Whether to include hidden files (files beginning with a period) + * @param string $sourceDir Path to source + * @param boolean|null $includePath Whether to include the path as part of the filename; false for no path, null for a relative path, true for full path + * @param boolean $hidden Whether to include hidden files (files beginning with a period) * * @return array */ - function get_filenames(string $source_dir, ?bool $include_path = false, bool $hidden = false): array + function get_filenames(string $sourceDir, ?bool $includePath = false, bool $hidden = false): array { $files = []; - $source_dir = realpath($source_dir) ?: $source_dir; - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + $sourceDir = realpath($sourceDir) ?: $sourceDir; + $sourceDir = rtrim($sourceDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; try { foreach (new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($source_dir, RecursiveDirectoryIterator::SKIP_DOTS), + new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST ) as $name => $object) { @@ -244,13 +244,13 @@ function get_filenames(string $source_dir, ?bool $include_path = false, bool $hi { continue; } - elseif ($include_path === false) + elseif ($includePath === false) { $files[] = $basename; } - elseif (is_null($include_path)) + elseif (is_null($includePath)) { - $files[] = str_replace($source_dir, '', $name); + $files[] = str_replace($sourceDir, '', $name); } else { @@ -281,37 +281,37 @@ function get_filenames(string $source_dir, ?bool $include_path = false, bool $hi * * Any sub-folders contained within the specified path are read as well. * - * @param string $source_dir Path to source - * @param boolean $top_level_only Look only at the top level directory specified? - * @param boolean $recursion Internal variable to determine recursion status - do not use in calls + * @param string $sourceDir Path to source + * @param boolean $topLevelOnly Look only at the top level directory specified? + * @param boolean $recursion Internal variable to determine recursion status - do not use in calls * * @return array */ - function get_dir_file_info(string $source_dir, bool $top_level_only = true, bool $recursion = false): array + function get_dir_file_info(string $sourceDir, bool $topLevelOnly = true, bool $recursion = false): array { static $fileData = []; - $relativePath = $source_dir; + $relativePath = $sourceDir; try { - $fp = @opendir($source_dir); { + $fp = @opendir($sourceDir); { // reset the array and make sure $source_dir has a trailing slash on the initial call if ($recursion === false) { - $fileData = []; - $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; + $fileData = []; + $sourceDir = rtrim(realpath($sourceDir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } // Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast while (false !== ($file = readdir($fp))) { - if (is_dir($source_dir . $file) && $file[0] !== '.' && $top_level_only === false) + if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) { - get_dir_file_info($source_dir . $file . DIRECTORY_SEPARATOR, $top_level_only, true); + get_dir_file_info($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true); } elseif ($file[0] !== '.') { - $fileData[$file] = get_file_info($source_dir . $file); + $fileData[$file] = get_file_info($sourceDir . $file); $fileData[$file]['relative_path'] = $relativePath; } } @@ -339,24 +339,24 @@ function get_dir_file_info(string $source_dir, bool $top_level_only = true, bool * Options are: name, server_path, size, date, readable, writable, executable, fileperms * Returns false if the file cannot be found. * - * @param string $file Path to file - * @param mixed $returned_values Array or comma separated string of information returned + * @param string $file Path to file + * @param mixed $returnedValues Array or comma separated string of information returned * * @return array|null */ - function get_file_info(string $file, $returned_values = ['name', 'server_path', 'size', 'date']) + function get_file_info(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']) { if (! is_file($file)) { return null; } - if (is_string($returned_values)) + if (is_string($returnedValues)) { - $returned_values = explode(',', $returned_values); + $returnedValues = explode(',', $returnedValues); } - foreach ($returned_values as $key) + foreach ($returnedValues as $key) { switch ($key) { case 'name': @@ -484,11 +484,11 @@ function octal_permissions(int $perms): string * Set Realpath * * @param string $path - * @param boolean $check_existence Checks to see if the path exists + * @param boolean $checkExistence Checks to see if the path exists * * @return string */ - function set_realpath(string $path, bool $check_existence = false): string + function set_realpath(string $path, bool $checkExistence = false): string { // Security check to make sure the path is NOT a URL. No remote file inclusion! if (preg_match('#^(http:\/\/|https:\/\/|www\.|ftp)#i', $path) || filter_var($path, FILTER_VALIDATE_IP) === $path) @@ -501,7 +501,7 @@ function set_realpath(string $path, bool $check_existence = false): string { $path = realpath($path); } - elseif ($check_existence && ! is_dir($path) && ! is_file($path)) + elseif ($checkExistence && ! is_dir($path) && ! is_file($path)) { throw new InvalidArgumentException('Not a valid path: ' . $path); } diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index e6aefb76f47c..8e834f40fa74 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -604,13 +604,13 @@ function form_button($data = '', string $content = '', $extra = ''): string /** * Form Label Tag * - * @param string $label_text The text to appear onscreen + * @param string $labelText The text to appear onscreen * @param string $id The id the label applies to * @param array $attributes Additional attributes * * @return string */ - function form_label(string $label_text = '', string $id = '', array $attributes = []): string + function form_label(string $labelText = '', string $id = '', array $attributes = []): string { $label = '' . $label_text . ''; + return $label . '>' . $labelText . ''; } } @@ -679,18 +679,18 @@ function form_datalist(string $name, string $value, array $options): string * Used to produce
text. To close fieldset * use form_fieldset_close() * - * @param string $legend_text The legend text - * @param array $attributes Additional attributes + * @param string $legendText The legend text + * @param array $attributes Additional attributes * * @return string */ - function form_fieldset(string $legend_text = '', array $attributes = []): string + function form_fieldset(string $legendText = '', array $attributes = []): string { $fieldset = '\n"; - if ($legend_text !== '') + if ($legendText !== '') { - return $fieldset . '' . $legend_text . "\n"; + return $fieldset . '' . $legendText . "\n"; } return $fieldset; @@ -741,13 +741,13 @@ function form_close(string $extra = ''): string * Grabs a value from the POST array for the specified field so you can * re-populate an input field or textarea * - * @param string $field Field name - * @param string $default Default value - * @param boolean $html_escape Whether to escape HTML special characters or not + * @param string $field Field name + * @param string $default Default value + * @param boolean $htmlEscape Whether to escape HTML special characters or not * * @return string */ - function set_value(string $field, string $default = '', bool $html_escape = true): string + function set_value(string $field, string $default = '', bool $htmlEscape = true): string { $request = Services::request(); @@ -759,7 +759,7 @@ function set_value(string $field, string $default = '', bool $html_escape = true $value = $request->getPost($field) ?? $default; } - return ($html_escape) ? esc($value) : $value; + return ($htmlEscape) ? esc($value) : $value; } } diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index 0dfababbdc47..abbcef3939df 100755 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -54,11 +54,11 @@ * * @param string $str * @param integer $limit - * @param string $end_char the end character. Usually an ellipsis + * @param string $endChar the end character. Usually an ellipsis * * @return string */ - function word_limiter(string $str, int $limit = 100, string $end_char = '…'): string + function word_limiter(string $str, int $limit = 100, string $endChar = '…'): string { if (trim($str) === '') { @@ -69,10 +69,10 @@ function word_limiter(string $str, int $limit = 100, string $end_char = '… if (strlen($str) === strlen($matches[0])) { - $end_char = ''; + $endChar = ''; } - return rtrim($matches[0]) . $end_char; + return rtrim($matches[0]) . $endChar; } } @@ -88,11 +88,11 @@ function word_limiter(string $str, int $limit = 100, string $end_char = '… * * @param string $str * @param integer $n - * @param string $end_char the end character. Usually an ellipsis + * @param string $endChar the end character. Usually an ellipsis * * @return string */ - function character_limiter(string $str, int $n = 500, string $end_char = '…'): string + function character_limiter(string $str, int $n = 500, string $endChar = '…'): string { if (mb_strlen($str) < $n) { @@ -118,7 +118,7 @@ function character_limiter(string $str, int $n = 500, string $end_char = '… break; } } - return (mb_strlen($out) === mb_strlen($str)) ? $out : $out . $end_char; + return (mb_strlen($out) === mb_strlen($str)) ? $out : $out . $endChar; } } @@ -397,16 +397,16 @@ function highlight_code(string $str): string * * Highlights a phrase within a text string * - * @param string $str the text string - * @param string $phrase the phrase you'd like to highlight - * @param string $tag_open the opening tag to precede the phrase with - * @param string $tag_close the closing tag to end the phrase with + * @param string $str the text string + * @param string $phrase the phrase you'd like to highlight + * @param string $tagOpen the opening tag to precede the phrase with + * @param string $tagClose the closing tag to end the phrase with * * @return string */ - function highlight_phrase(string $str, string $phrase, string $tag_open = '', string $tag_close = ''): string + function highlight_phrase(string $str, string $phrase, string $tagOpen = '', string $tagClose = ''): string { - return ($str !== '' && $phrase !== '') ? preg_replace('/(' . preg_quote($phrase, '/') . ')/i', $tag_open . '\\1' . $tag_close, $str) : $str; + return ($str !== '' && $phrase !== '') ? preg_replace('/(' . preg_quote($phrase, '/') . ')/i', $tagOpen . '\\1' . $tagClose, $str) : $str; } } @@ -555,34 +555,34 @@ function word_wrap(string $str, int $charlim = 76): string * * This function will strip tags from a string, split it at its max_length and ellipsize * - * @param string $str String to ellipsize - * @param integer $max_length Max length of string - * @param mixed $position int (1|0) or float, .5, .2, etc for position to split - * @param string $ellipsis ellipsis ; Default '...' + * @param string $str String to ellipsize + * @param integer $maxLength Max length of string + * @param mixed $position int (1|0) or float, .5, .2, etc for position to split + * @param string $ellipsis ellipsis ; Default '...' * * @return string Ellipsized string */ - function ellipsize(string $str, int $max_length, $position = 1, string $ellipsis = '…'): string + function ellipsize(string $str, int $maxLength, $position = 1, string $ellipsis = '…'): string { // Strip tags $str = trim(strip_tags($str)); // Is the string long enough to ellipsize? - if (mb_strlen($str) <= $max_length) + if (mb_strlen($str) <= $maxLength) { return $str; } - $beg = mb_substr($str, 0, (int) floor($max_length * $position)); + $beg = mb_substr($str, 0, (int) floor($maxLength * $position)); $position = ($position > 1) ? 1 : $position; if ($position === 1) { - $end = mb_substr($str, 0, -($max_length - mb_strlen($beg))); + $end = mb_substr($str, 0, -($maxLength - mb_strlen($beg))); } else { - $end = mb_substr($str, -($max_length - mb_strlen($beg))); + $end = mb_substr($str, -($maxLength - mb_strlen($beg))); } return $beg . $ellipsis . $end; diff --git a/system/Helpers/xml_helper.php b/system/Helpers/xml_helper.php index 05eb76c63b94..553679d3d233 100644 --- a/system/Helpers/xml_helper.php +++ b/system/Helpers/xml_helper.php @@ -49,10 +49,10 @@ * Convert Reserved XML characters to Entities * * @param string $str - * @param boolean $protect_all + * @param boolean $protectAll * @return string */ - function xml_convert(string $str, bool $protect_all = false): string + function xml_convert(string $str, bool $protectAll = false): string { $temp = '__TEMP_AMPERSANDS__'; @@ -60,7 +60,7 @@ function xml_convert(string $str, bool $protect_all = false): string // ampersands won't get messed up $str = preg_replace('/&#(\d+);/', $temp . '\\1;', $str); - if ($protect_all === true) + if ($protectAll === true) { $str = preg_replace('/&(\w+);/', $temp . '\\1;', $str); } @@ -88,7 +88,7 @@ function xml_convert(string $str, bool $protect_all = false): string // Decode the temp markers back to entities $str = preg_replace('/' . $temp . '(\d+);/', '&#\\1;', $str); - if ($protect_all === true) + if ($protectAll === true) { return preg_replace('/' . $temp . '(\w+);/', '&\\1;', $str); } diff --git a/system/Security/Security.php b/system/Security/Security.php index 906e81da9a1f..c39fc972d079 100644 --- a/system/Security/Security.php +++ b/system/Security/Security.php @@ -397,7 +397,6 @@ protected function CSRFSetHash(): string } //-------------------------------------------------------------------- - /** * Sanitize Filename * @@ -409,16 +408,16 @@ protected function CSRFSetHash(): string * e.g. file/in/some/approved/folder.txt, you can set the second optional * parameter, $relative_path to TRUE. * - * @param string $str Input file name - * @param boolean $relative_path Whether to preserve paths + * @param string $str Input file name + * @param boolean $relativePath Whether to preserve paths * * @return string */ - public function sanitizeFilename(string $str, bool $relative_path = false): string + public function sanitizeFilename(string $str, bool $relativePath = false): string { $bad = $this->filenameBadChars; - if (! $relative_path) + if (! $relativePath) { $bad[] = './'; $bad[] = '/'; diff --git a/system/Session/Handlers/FileHandler.php b/system/Session/Handlers/FileHandler.php index ec38183896fd..97dcd485c166 100644 --- a/system/Session/Handlers/FileHandler.php +++ b/system/Session/Handlers/FileHandler.php @@ -316,30 +316,29 @@ public function close(): bool } //-------------------------------------------------------------------- - /** * Destroy * * Destroys the current session. * - * @param string $session_id Session ID + * @param string $sessionId Session ID * * @return boolean */ - public function destroy($session_id): bool + public function destroy($sessionId): bool { if ($this->close()) { - return is_file($this->filePath . $session_id) - ? (unlink($this->filePath . $session_id) && $this->destroyCookie()) : true; + return is_file($this->filePath . $sessionId) + ? (unlink($this->filePath . $sessionId) && $this->destroyCookie()) : true; } if ($this->filePath !== null) { clearstatcache(); - return is_file($this->filePath . $session_id) - ? (unlink($this->filePath . $session_id) && $this->destroyCookie()) : true; + return is_file($this->filePath . $sessionId) + ? (unlink($this->filePath . $sessionId) && $this->destroyCookie()) : true; } return false; diff --git a/system/Session/Handlers/MemcachedHandler.php b/system/Session/Handlers/MemcachedHandler.php index 95a786901bb2..dcd71632941f 100644 --- a/system/Session/Handlers/MemcachedHandler.php +++ b/system/Session/Handlers/MemcachedHandler.php @@ -107,18 +107,17 @@ public function __construct(AppConfig $config, string $ipAddress) } //-------------------------------------------------------------------- - /** * Open * * Sanitizes save_path and initializes connections. * - * @param string $save_path Server path(s) - * @param string $name Session cookie name, unused + * @param string $savePath Server path(s) + * @param string $name Session cookie name, unused * * @return boolean */ - public function open($save_path, $name): bool + public function open($savePath, $name): bool { $this->memcached = new \Memcached(); $this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); // required for touch() usage @@ -280,21 +279,20 @@ public function close(): bool } //-------------------------------------------------------------------- - /** * Destroy * * Destroys the current session. * - * @param string $session_id Session ID + * @param string $sessionId Session ID * * @return boolean */ - public function destroy($session_id): bool + public function destroy($sessionId): bool { if (isset($this->memcached, $this->lockKey)) { - $this->memcached->delete($this->keyPrefix . $session_id); + $this->memcached->delete($this->keyPrefix . $sessionId); return $this->destroyCookie(); } diff --git a/system/Session/Handlers/RedisHandler.php b/system/Session/Handlers/RedisHandler.php index 82224e49d8b7..ca3fd4372326 100644 --- a/system/Session/Handlers/RedisHandler.php +++ b/system/Session/Handlers/RedisHandler.php @@ -133,17 +133,16 @@ public function __construct(AppConfig $config, string $ipAddress) } //-------------------------------------------------------------------- - /** * Open * * Sanitizes save_path and initializes connection. * - * @param string $save_path Server path - * @param string $name Session cookie name, unused + * @param string $savePath Server path + * @param string $name Session cookie name, unused * @return boolean */ - public function open($save_path, $name): bool + public function open($savePath, $name): bool { if (empty($this->savePath)) { diff --git a/system/Test/Mock/MockCURLRequest.php b/system/Test/Mock/MockCURLRequest.php index eea2fd120d59..88b44fcd241a 100644 --- a/system/Test/Mock/MockCURLRequest.php +++ b/system/Test/Mock/MockCURLRequest.php @@ -26,10 +26,10 @@ public function setOutput($output) //-------------------------------------------------------------------- - protected function sendRequest(array $curl_options = []): string + protected function sendRequest(array $curlOptions = []): string { // Save so we can access later. - $this->curl_options = $curl_options; + $this->curl_options = $curlOptions; return $this->output; } diff --git a/system/Test/Mock/MockCommon.php b/system/Test/Mock/MockCommon.php index 3778ad1bf9ae..b56d3a28ed7c 100644 --- a/system/Test/Mock/MockCommon.php +++ b/system/Test/Mock/MockCommon.php @@ -17,17 +17,17 @@ * Test to see if a request was made from the command line. * You can set the return value for testing. * - * @param boolean $new_return return value to set + * @param boolean $newReturn return value to set * @return boolean */ - function is_cli(bool $new_return = null): bool + function is_cli(bool $newReturn = null): bool { // PHPUnit always runs via CLI. static $returnValue = true; - if ($new_return !== null) + if ($newReturn !== null) { - $returnValue = $new_return; + $returnValue = $newReturn; } return $returnValue; diff --git a/system/Typography/Typography.php b/system/Typography/Typography.php index 5643d7cf4b06..99d1ee529a97 100644 --- a/system/Typography/Typography.php +++ b/system/Typography/Typography.php @@ -99,11 +99,11 @@ class Typography * - Converts two spaces into entities * * @param string $str - * @param boolean $reduce_linebreaks whether to reduce more then two consecutive newlines to two + * @param boolean $reduceLinebreaks whether to reduce more then two consecutive newlines to two * * @return string */ - public function autoTypography(string $str, bool $reduce_linebreaks = false): string + public function autoTypography(string $str, bool $reduceLinebreaks = false): string { if ($str === '') { @@ -118,7 +118,7 @@ public function autoTypography(string $str, bool $reduce_linebreaks = false): st // Reduce line breaks. If there are more than two consecutive linebreaks // we'll compress them down to a maximum of two since there's no benefit to more. - if ($reduce_linebreaks === false) + if ($reduceLinebreaks === false) { $str = preg_replace("/\n\n+/", "\n\n", $str); } @@ -254,7 +254,7 @@ public function autoTypography(string $str, bool $reduce_linebreaks = false): st ]; // Do we need to reduce empty lines? - if ($reduce_linebreaks === true) + if ($reduceLinebreaks === true) { $table['#

\n*

#'] = ''; } diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 1f6ffdd87f0d..82ba638c9713 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -126,23 +126,22 @@ public function __construct($config, RendererInterface $view) } //-------------------------------------------------------------------- - /** * Runs the validation process, returning true/false determining whether * validation was successful or not. * - * @param array $data The array of data to validate. - * @param string $group The pre-defined group of rules to apply. - * @param string $db_group The database group to use. + * @param array $data The array of data to validate. + * @param string $group The pre-defined group of rules to apply. + * @param string $dbGroup The database group to use. * * @return boolean */ - public function run(array $data = null, string $group = null, string $db_group = null): bool + public function run(array $data = null, string $group = null, string $dbGroup = null): bool { $data = $data ?? $this->data; // i.e. is_unique - $data['DBGroup'] = $db_group; + $data['DBGroup'] = $dbGroup; $this->loadRuleSets(); diff --git a/utils/Rector/UnderscoreToCamelCaseLocalVariableNameRector.php b/utils/Rector/UnderscoreToCamelCaseVariableNameRector.php similarity index 56% rename from utils/Rector/UnderscoreToCamelCaseLocalVariableNameRector.php rename to utils/Rector/UnderscoreToCamelCaseVariableNameRector.php index 70c58387701e..4c62555f80b0 100644 --- a/utils/Rector/UnderscoreToCamelCaseLocalVariableNameRector.php +++ b/utils/Rector/UnderscoreToCamelCaseVariableNameRector.php @@ -6,13 +6,10 @@ use Nette\Utils\Strings; use PhpParser\Node; -use PhpParser\Node\Arg; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Param; -use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; +use Rector\BetterPhpDocParser\PhpDocManipulator\PropertyDocBlockManipulator; use Rector\Core\Php\ReservedKeywordAnalyzer; use Rector\Core\Rector\AbstractRector; use Rector\Core\RectorDefinition\CodeSample; @@ -21,26 +18,40 @@ use Rector\NodeTypeResolver\Node\AttributeKey; /** - * Adapted from https://github.com/rectorphp/rector/blob/master/rules/coding-style/src/Rector/Variable/UnderscoreToCamelCaseLocalVariableNameRector.php - * with skip _ in first character + * Adapted from https://github.com/rectorphp/rector/blob/master/rules/coding-style/src/Rector/Variable/UnderscoreToCamelCaseVariableNameRector.php + * with skip _ in first character\ */ -final class UnderscoreToCamelCaseLocalVariableNameRector extends AbstractRector +final class UnderscoreToCamelCaseVariableNameRector extends AbstractRector { + /** + * @var string + * @see https://regex101.com/r/OtFn8I/1 + */ + private const PARAM_NAME_REGEX = '#(?@param\s.*\s+\$)(?%s)#ms'; + + /** + * @var PropertyDocBlockManipulator + */ + private $propertyDocBlockManipulator; + /** * @var ReservedKeywordAnalyzer */ private $reservedKeywordAnalyzer; - public function __construct(ReservedKeywordAnalyzer $reservedKeywordAnalyzer) + public function __construct( + PropertyDocBlockManipulator $propertyDocBlockManipulator, + ReservedKeywordAnalyzer $reservedKeywordAnalyzer + ) { - $this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer; + $this->propertyDocBlockManipulator = $propertyDocBlockManipulator; + $this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer; } public function getDefinition(): RectorDefinition { - return new RectorDefinition( - 'Change under_score local variable names to camelCase', [ - new CodeSample( + return new RectorDefinition('Change under_score names to camelCase', [ + new CodeSample( <<<'CODE_SAMPLE' final class SomeClass { @@ -50,18 +61,18 @@ public function run($a_b) } } CODE_SAMPLE - , +, <<<'CODE_SAMPLE' final class SomeClass { - public function run($a_b) + public function run($aB) { - $someValue = $a_b; + $someValue = $aB; } } CODE_SAMPLE ), - ]); + ]); } /** @@ -104,30 +115,13 @@ public function refactor(Node $node): ?Node return null; } - $parentNode = $node->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode instanceof Expr && $this->isFoundInParentNode($node)) - { - return null; - } - - if (($parentNode instanceof Arg || $parentNode instanceof Param || $parentNode instanceof Stmt) - && $this->isFoundInParentNode($node) - ) - { - return null; - } - - if ($this->isFoundInPreviousNode($node)) - { - return null; - } - $node->name = $camelCaseName; + $this->updateDocblock($node, $nodeName, $camelCaseName); return $node; } - private function isFoundInParentNode(Variable $variable): bool + private function updateDocblock(Variable $variable, string $variableName, string $camelCaseName): void { $parentNode = $variable->getAttribute(AttributeKey::PARENT_NODE); while ($parentNode) @@ -144,24 +138,30 @@ private function isFoundInParentNode(Variable $variable): bool if ($parentNode === null) { - return false; + return; } - $params = $parentNode->getParams(); - foreach ($params as $param) + $docComment = $parentNode->getDocComment(); + if ($docComment === null) { - if ($param->var->name === $variable->name) - { - return true; - } + return; } - return false; - } + $docCommentText = $docComment->getText(); + if ($docCommentText === null) + { + return; + } - private function isFoundInPreviousNode(Variable $variable): bool - { - $previousNode = $variable->getAttribute(AttributeKey::PREVIOUS_NODE); - return $previousNode instanceof Expr && $this->isFoundInParentNode($variable); + if (! $match = Strings::match($docCommentText, sprintf(self::PARAM_NAME_REGEX, $variableName))) + { + return; + } + + $this->propertyDocBlockManipulator->renameParameterNameInDocBlock( + $parentNode, + $match['paramName'], + $camelCaseName + ); } }