Merge pull request #4793 from jeromegamez/constants-vs-methods

Use constants instead of functions
This commit is contained in:
John Paul E. Balandan, CPA 2021-06-08 00:42:29 +08:00 committed by GitHub
commit 6edfdeb131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 14 additions and 13 deletions

View File

@ -389,7 +389,7 @@
<p> <p>
Displayed at <?= esc(date('H:i:sa')) ?> &mdash; Displayed at <?= esc(date('H:i:sa')) ?> &mdash;
PHP: <?= esc(phpversion()) ?> &mdash; PHP: <?= esc(PHP_VERSION) ?> &mdash;
CodeIgniter: <?= esc(\CodeIgniter\CodeIgniter::CI_VERSION) ?> CodeIgniter: <?= esc(\CodeIgniter\CodeIgniter::CI_VERSION) ?>
</p> </p>

View File

@ -1202,7 +1202,7 @@ abstract class BaseModel
if (empty($this->allowedFields)) if (empty($this->allowedFields))
{ {
throw DataException::forInvalidAllowedFields(get_class($this)); throw DataException::forInvalidAllowedFields(static::class);
} }
foreach (array_keys($data) as $key) foreach (array_keys($data) as $key)

View File

@ -448,7 +448,7 @@ class CLI
*/ */
public static function isWindows(): bool public static function isWindows(): bool
{ {
return stripos(PHP_OS, 'WIN') === 0; return PHP_OS_FAMILY === 'Windows';
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------

View File

@ -707,7 +707,7 @@ abstract class BaseConnection implements ConnectionInterface
} }
// query is not write-type, so it must be read-type query; return QueryResult // 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); 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.'); 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); return new $className($tableName, $this);
} }
@ -1009,7 +1009,7 @@ abstract class BaseConnection implements ConnectionInterface
$sql = $sql->getOriginalQuery(); $sql = $sql->getOriginalQuery();
} }
$class = str_ireplace('Connection', 'PreparedQuery', get_class($this)); $class = str_ireplace('Connection', 'PreparedQuery', static::class);
/** /**
* @var BasePreparedQuery $class * @var BasePreparedQuery $class
*/ */

View File

@ -143,7 +143,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
Events::trigger('DBQuery', $query); Events::trigger('DBQuery', $query);
// Return a result object // Return a result object
$resultClass = str_replace('PreparedQuery', 'Result', get_class($this)); $resultClass = str_replace('PreparedQuery', 'Result', static::class);
$resultID = $this->_getResult(); $resultID = $this->_getResult();

View File

@ -31,8 +31,8 @@ class Config
return [ return [
'ciVersion' => CodeIgniter::CI_VERSION, 'ciVersion' => CodeIgniter::CI_VERSION,
'phpVersion' => phpversion(), 'phpVersion' => PHP_VERSION,
'phpSAPI' => php_sapi_name(), 'phpSAPI' => PHP_SAPI,
'environment' => ENVIRONMENT, 'environment' => ENVIRONMENT,
'baseURL' => $config->baseURL, 'baseURL' => $config->baseURL,
'timezone' => app_timezone(), 'timezone' => app_timezone(),

View File

@ -410,7 +410,7 @@ class Email
$config = get_object_vars($config); $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])) if (property_exists($this, $key) && isset($config[$key]))
{ {

View File

@ -485,7 +485,7 @@ trait ResponseTrait
// Per spec, MUST be sent with each request, if possible. // Per spec, MUST be sent with each request, if possible.
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html // 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())); $this->setDate(DateTime::createFromFormat('U', (string) time()));
} }

View File

@ -73,7 +73,7 @@ class ImageMagickHandler extends BaseHandler
$destination = $this->getResourcePath(); $destination = $this->getResourcePath();
$escape = '\\'; $escape = '\\';
if (stripos(PHP_OS, 'WIN') === 0) if (PHP_OS_FAMILY === 'Windows')
{ {
$escape = ''; $escape = '';
} }

View File

@ -88,7 +88,7 @@ class MockConnection extends BaseConnection
} }
// query is not write-type, so it must be read-type query; return QueryResult // 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); return new $resultClass($this->connID, $this->resultID);
} }

View File

@ -34,6 +34,7 @@ final class CodeIgniter4 extends AbstractRuleset
], ],
'blank_line_after_namespace' => true, 'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true, 'blank_line_after_opening_tag' => true,
'function_to_constant' => true,
'indentation_type' => true, 'indentation_type' => true,
'line_ending' => true, 'line_ending' => true,
'static_lambda' => true, 'static_lambda' => true,