From 68bb8a7b2894b7bdbafb66631f3d8fba25e0523e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gamez?= Date: Mon, 7 Jun 2021 13:28:58 +0200 Subject: [PATCH] Use constants instead of functions --- app/Views/errors/html/error_exception.php | 2 +- system/BaseModel.php | 2 +- system/CLI/CLI.php | 2 +- system/Database/BaseConnection.php | 6 +++--- system/Database/BasePreparedQuery.php | 2 +- system/Debug/Toolbar/Collectors/Config.php | 4 ++-- system/Email/Email.php | 2 +- system/HTTP/ResponseTrait.php | 2 +- system/Images/Handlers/ImageMagickHandler.php | 2 +- system/Test/Mock/MockConnection.php | 2 +- utils/PhpCsFixer/CodeIgniter4.php | 1 + 11 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/Views/errors/html/error_exception.php b/app/Views/errors/html/error_exception.php index 56df526b13..14c471f356 100644 --- a/app/Views/errors/html/error_exception.php +++ b/app/Views/errors/html/error_exception.php @@ -389,7 +389,7 @@

Displayed at — - PHP: — + PHP: — CodeIgniter:

diff --git a/system/BaseModel.php b/system/BaseModel.php index faeee5a43f..337ead66ac 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -1202,7 +1202,7 @@ abstract class BaseModel if (empty($this->allowedFields)) { - throw DataException::forInvalidAllowedFields(get_class($this)); + throw DataException::forInvalidAllowedFields(static::class); } foreach (array_keys($data) as $key) diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 37dd16ee09..f7b1f2f46a 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -448,7 +448,7 @@ class CLI */ public static function isWindows(): bool { - return stripos(PHP_OS, 'WIN') === 0; + return PHP_OS_FAMILY === 'Windows'; } //-------------------------------------------------------------------- diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index f4a3a8a2d6..e4fa59d5c4 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -707,7 +707,7 @@ abstract class BaseConnection implements ConnectionInterface } // query is not write-type, so it must be read-type query; return QueryResult - $resultClass = str_replace('Connection', 'Result', get_class($this)); + $resultClass = str_replace('Connection', 'Result', static::class); return new $resultClass($this->connID, $this->resultID); } @@ -965,7 +965,7 @@ abstract class BaseConnection implements ConnectionInterface throw new DatabaseException('You must set the database table to be used with your query.'); } - $className = str_replace('Connection', 'Builder', get_class($this)); + $className = str_replace('Connection', 'Builder', static::class); return new $className($tableName, $this); } @@ -1009,7 +1009,7 @@ abstract class BaseConnection implements ConnectionInterface $sql = $sql->getOriginalQuery(); } - $class = str_ireplace('Connection', 'PreparedQuery', get_class($this)); + $class = str_ireplace('Connection', 'PreparedQuery', static::class); /** * @var BasePreparedQuery $class */ diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index a7317cb5af..655cc57336 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -143,7 +143,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface Events::trigger('DBQuery', $query); // Return a result object - $resultClass = str_replace('PreparedQuery', 'Result', get_class($this)); + $resultClass = str_replace('PreparedQuery', 'Result', static::class); $resultID = $this->_getResult(); diff --git a/system/Debug/Toolbar/Collectors/Config.php b/system/Debug/Toolbar/Collectors/Config.php index 1d02f4d09b..83d80a1200 100644 --- a/system/Debug/Toolbar/Collectors/Config.php +++ b/system/Debug/Toolbar/Collectors/Config.php @@ -31,8 +31,8 @@ class Config return [ 'ciVersion' => CodeIgniter::CI_VERSION, - 'phpVersion' => phpversion(), - 'phpSAPI' => php_sapi_name(), + 'phpVersion' => PHP_VERSION, + 'phpSAPI' => PHP_SAPI, 'environment' => ENVIRONMENT, 'baseURL' => $config->baseURL, 'timezone' => app_timezone(), diff --git a/system/Email/Email.php b/system/Email/Email.php index c02b2e9436..cf2f509409 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -410,7 +410,7 @@ class Email $config = get_object_vars($config); } - foreach (array_keys(get_class_vars(get_class($this))) as $key) + foreach (array_keys(get_class_vars(static::class)) as $key) { if (property_exists($this, $key) && isset($config[$key])) { diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php index b33d92cb82..5d814536fd 100644 --- a/system/HTTP/ResponseTrait.php +++ b/system/HTTP/ResponseTrait.php @@ -485,7 +485,7 @@ trait ResponseTrait // Per spec, MUST be sent with each request, if possible. // http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html - if (! isset($this->headers['Date']) && php_sapi_name() !== 'cli-server') + if (! isset($this->headers['Date']) && PHP_SAPI !== 'cli-server') { $this->setDate(DateTime::createFromFormat('U', (string) time())); } diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index efcc57f1a7..793db35204 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -73,7 +73,7 @@ class ImageMagickHandler extends BaseHandler $destination = $this->getResourcePath(); $escape = '\\'; - if (stripos(PHP_OS, 'WIN') === 0) + if (PHP_OS_FAMILY === 'Windows') { $escape = ''; } diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index 5a2688a442..e3f0e8a8c4 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -88,7 +88,7 @@ class MockConnection extends BaseConnection } // query is not write-type, so it must be read-type query; return QueryResult - $resultClass = str_replace('Connection', 'Result', get_class($this)); + $resultClass = str_replace('Connection', 'Result', static::class); return new $resultClass($this->connID, $this->resultID); } diff --git a/utils/PhpCsFixer/CodeIgniter4.php b/utils/PhpCsFixer/CodeIgniter4.php index e0de298a6b..dcade5b78e 100644 --- a/utils/PhpCsFixer/CodeIgniter4.php +++ b/utils/PhpCsFixer/CodeIgniter4.php @@ -34,6 +34,7 @@ final class CodeIgniter4 extends AbstractRuleset ], 'blank_line_after_namespace' => true, 'blank_line_after_opening_tag' => true, + 'function_to_constant' => true, 'indentation_type' => true, 'line_ending' => true, 'static_lambda' => true,