From 84ff35989270d17bcdb463626eec50b4c25b3766 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 7 Apr 2024 02:46:05 +0000 Subject: [PATCH] Release v4.4.8 --- app/.htaccess | 4 +-- public/.htaccess | 2 +- system/BaseModel.php | 33 +++++++++-------- system/CLI/CLI.php | 4 +-- system/CodeIgniter.php | 2 +- system/Commands/Database/MigrateStatus.php | 2 +- system/Config/DotEnv.php | 2 +- system/Controller.php | 2 +- system/Database/BaseBuilder.php | 2 +- system/Database/BaseConnection.php | 10 ++++-- system/Database/BaseResult.php | 4 +-- system/Database/MySQLi/Connection.php | 4 +-- system/Database/OCI8/Builder.php | 2 +- system/Database/OCI8/Connection.php | 4 +-- system/Database/Postgre/Connection.php | 4 +-- system/Database/ResultInterface.php | 4 +-- system/Database/SQLSRV/Connection.php | 4 +-- system/Database/SQLite3/Connection.php | 4 +-- system/Database/SQLite3/Table.php | 10 ++---- system/Debug/ExceptionHandler.php | 19 +++++----- system/HTTP/DownloadResponse.php | 2 +- system/HTTP/Files/UploadedFile.php | 30 +++++++--------- system/HTTP/Files/UploadedFileInterface.php | 17 +++++---- system/Helpers/filesystem_helper.php | 18 +++++----- system/Helpers/form_helper.php | 2 +- system/Helpers/html_helper.php | 2 +- system/Helpers/url_helper.php | 2 +- system/Images/Handlers/ImageMagickHandler.php | 35 ++++++++++--------- system/Pager/Pager.php | 6 ++-- system/Router/RouteCollection.php | 2 +- system/Session/Handlers/FileHandler.php | 2 +- system/View/Table.php | 2 +- writable/.htaccess | 4 +-- 33 files changed, 125 insertions(+), 121 deletions(-) diff --git a/app/.htaccess b/app/.htaccess index f24db0ac..3462048a 100644 --- a/app/.htaccess +++ b/app/.htaccess @@ -1,6 +1,6 @@ - Require all denied + Require all denied - Deny from all + Deny from all diff --git a/public/.htaccess b/public/.htaccess index dbed322f..abac3cb6 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -45,5 +45,5 @@ Options -Indexes # Disable server signature start - ServerSignature Off +ServerSignature Off # Disable server signature end diff --git a/system/BaseModel.php b/system/BaseModel.php index 24479ec6..cd2bdd6b 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -173,11 +173,14 @@ abstract class BaseModel protected $db; /** - * Rules used to validate data in insert, update, and save methods. + * Rules used to validate data in insert(), update(), and save() methods. + * * The array must match the format of data passed to the Validation * library. * - * @var list|string + * @see https://codeigniter4.github.io/userguide/models/model.html#setting-validation-rules + * + * @var array|string>|string>|string */ protected $validationRules = []; @@ -243,84 +246,84 @@ abstract class BaseModel /** * Callbacks for beforeInsert * - * @var array + * @var list */ protected $beforeInsert = []; /** * Callbacks for afterInsert * - * @var array + * @var list */ protected $afterInsert = []; /** * Callbacks for beforeUpdate * - * @var array + * @var list */ protected $beforeUpdate = []; /** * Callbacks for afterUpdate * - * @var array + * @var list */ protected $afterUpdate = []; /** * Callbacks for beforeInsertBatch * - * @var array + * @var list */ protected $beforeInsertBatch = []; /** * Callbacks for afterInsertBatch * - * @var array + * @var list */ protected $afterInsertBatch = []; /** * Callbacks for beforeUpdateBatch * - * @var array + * @var list */ protected $beforeUpdateBatch = []; /** * Callbacks for afterUpdateBatch * - * @var array + * @var list */ protected $afterUpdateBatch = []; /** * Callbacks for beforeFind * - * @var array + * @var list */ protected $beforeFind = []; /** * Callbacks for afterFind * - * @var array + * @var list */ protected $afterFind = []; /** * Callbacks for beforeDelete * - * @var array + * @var list */ protected $beforeDelete = []; /** * Callbacks for afterDelete * - * @var array + * @var list */ protected $afterDelete = []; @@ -1448,7 +1451,7 @@ public function setValidationMessage(string $field, array $fieldMessages) * Allows to set (and reset) validation rules. * It could be used when you have to change default or override current validate rules. * - * @param array $validationRules Value + * @param array|string>|string> $validationRules Value * * @return $this */ diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 9a50e403..5bd85438 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -262,7 +262,7 @@ public static function prompt(string $field, $options = null, $validation = null $default = $options[0]; } - static::fwrite(STDOUT, $field . (trim($field) ? ' ' : '') . $extraOutput . ': '); + static::fwrite(STDOUT, $field . (trim($field) !== '' ? ' ' : '') . $extraOutput . ': '); // Read the input from keyboard. $input = trim(static::input()) ?: $default; @@ -386,7 +386,7 @@ public static function promptByMultipleKeys(string $text, array $options): array */ private static function isZeroOptions(array $options): void { - if (! $options) { + if ($options === []) { throw new InvalidArgumentException('No options to select from were provided'); } } diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 760a71f2..6a2dca68 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -54,7 +54,7 @@ class CodeIgniter /** * The current version of CodeIgniter Framework */ - public const CI_VERSION = '4.4.7'; + public const CI_VERSION = '4.4.8'; /** * App startup time. diff --git a/system/Commands/Database/MigrateStatus.php b/system/Commands/Database/MigrateStatus.php index cbbe2f70..ecd07427 100644 --- a/system/Commands/Database/MigrateStatus.php +++ b/system/Commands/Database/MigrateStatus.php @@ -144,7 +144,7 @@ public function run(array $params) } } - if (! $status) { + if ($status === []) { // @codeCoverageIgnoreStart CLI::error(lang('Migrations.noneFound'), 'light_gray', 'red'); CLI::newLine(); diff --git a/system/Config/DotEnv.php b/system/Config/DotEnv.php index 05ecab90..f8e757e9 100644 --- a/system/Config/DotEnv.php +++ b/system/Config/DotEnv.php @@ -140,7 +140,7 @@ public function normaliseVariable(string $name, string $value = ''): array */ protected function sanitizeValue(string $value): string { - if (! $value) { + if ($value === '') { return $value; } diff --git a/system/Controller.php b/system/Controller.php index 0cc14c56..83bc4f4b 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -187,7 +187,7 @@ private function setValidator($rules, array $messages): void } // If no error message is defined, use the error message in the Config\Validation file - if (! $messages) { + if ($messages === []) { $errorName = $rules . '_errors'; $messages = $validation->{$errorName} ?? []; } diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 8a33e220..65dea86d 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -333,7 +333,7 @@ public function __construct($tableName, ConnectionInterface $db, ?array $options /** * Returns the current database connection * - * @return BaseConnection|ConnectionInterface + * @return BaseConnection */ public function db(): ConnectionInterface { diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index ae5c4b38..93bde5dd 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1527,7 +1527,7 @@ public function getFieldData(string $table) /** * Returns an object with key data * - * @return array + * @return array */ public function getIndexData(string $table) { @@ -1547,7 +1547,9 @@ public function getForeignKeyData(string $table) /** * Converts array of arrays generated by _foreignKeyData() to array of objects * - * @return array[ + * @return array + * + * array[ * {constraint_name} => * stdClass[ * 'constraint_name' => string, @@ -1704,6 +1706,8 @@ abstract protected function _fieldData(string $table): array; * Platform-specific index data. * * @see getIndexData() + * + * @return array */ abstract protected function _indexData(string $table): array; @@ -1711,6 +1715,8 @@ abstract protected function _indexData(string $table): array; * Platform-specific foreign keys data. * * @see getForeignKeyData() + * + * @return array */ abstract protected function _foreignKeyData(string $table): array; diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index 8a624029..8720b5fe 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -260,8 +260,8 @@ public function getResultObject(): array * @param string $type The type of result object. 'array', 'object' or class name. * @phpstan-param class-string|'array'|'object' $type * - * @return array|object|stdClass|null - * @phpstan-return ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null)) + * @return array|float|int|object|stdClass|string|null + * @phpstan-return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))) */ public function getRow($n = 0, string $type = 'object') { diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 03aab408..b499e2ca 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -443,7 +443,7 @@ protected function _fieldData(string $table): array /** * Returns an array of objects with index data * - * @return list + * @return array * * @throws DatabaseException * @throws LogicException @@ -489,7 +489,7 @@ protected function _indexData(string $table): array /** * Returns an array of objects with Foreign key data * - * @return list + * @return array * * @throws DatabaseException */ diff --git a/system/Database/OCI8/Builder.php b/system/Database/OCI8/Builder.php index f5527ce7..37ba54a2 100644 --- a/system/Database/OCI8/Builder.php +++ b/system/Database/OCI8/Builder.php @@ -222,7 +222,7 @@ protected function _limit(string $sql, bool $offsetIgnore = false): string } $this->limitUsed = true; - $limitTemplateQuery = 'SELECT * FROM (SELECT INNER_QUERY.*, ROWNUM RNUM FROM (%s) INNER_QUERY WHERE ROWNUM < %d)' . ($offset ? ' WHERE RNUM >= %d' : ''); + $limitTemplateQuery = 'SELECT * FROM (SELECT INNER_QUERY.*, ROWNUM RNUM FROM (%s) INNER_QUERY WHERE ROWNUM < %d)' . ($offset !== 0 ? ' WHERE RNUM >= %d' : ''); return sprintf($limitTemplateQuery, $sql, $offset + $this->QBLimit + 1, $offset); } diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index fc7920e2..2feb2d36 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -325,7 +325,7 @@ protected function _fieldData(string $table): array /** * Returns an array of objects with index data * - * @return list + * @return array * * @throws DatabaseException */ @@ -374,7 +374,7 @@ protected function _indexData(string $table): array /** * Returns an array of objects with Foreign key data * - * @return list + * @return array * * @throws DatabaseException */ diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index baef703b..7da3d26c 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -332,7 +332,7 @@ protected function _fieldData(string $table): array /** * Returns an array of objects with index data * - * @return list + * @return array * * @throws DatabaseException */ @@ -371,7 +371,7 @@ protected function _indexData(string $table): array /** * Returns an array of objects with Foreign key data * - * @return list + * @return array * * @throws DatabaseException */ diff --git a/system/Database/ResultInterface.php b/system/Database/ResultInterface.php index ea5f0de2..2b1deb98 100644 --- a/system/Database/ResultInterface.php +++ b/system/Database/ResultInterface.php @@ -63,8 +63,8 @@ public function getResultObject(): array; * @param string $type The type of result object. 'array', 'object' or class name. * @phpstan-param class-string|'array'|'object' $type * - * @return array|object|stdClass|null - * @phpstan-return ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null)) + * @return array|float|int|object|stdClass|string|null + * @phpstan-return ($n is string ? float|int|string|null : ($type is 'object' ? stdClass|null : ($type is 'array' ? array|null : T|null))) */ public function getRow($n = 0, string $type = 'object'); diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index bc3e0360..77a1ab34 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -231,7 +231,7 @@ protected function _listColumns(string $table = ''): string /** * Returns an array of objects with index data * - * @return list + * @return array * * @throws DatabaseException */ @@ -269,7 +269,7 @@ protected function _indexData(string $table): array * Returns an array of objects with Foreign key data * referenced_object_id parent_object_id * - * @return list + * @return array * * @throws DatabaseException */ diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index be4ebc25..a7ac179d 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -286,7 +286,7 @@ protected function _fieldData(string $table): array /** * Returns an array of objects with index data * - * @return list + * @return array * * @throws DatabaseException */ @@ -343,7 +343,7 @@ protected function _indexData(string $table): array /** * Returns an array of objects with Foreign key data * - * @return list + * @return array */ protected function _foreignKeyData(string $table): array { diff --git a/system/Database/SQLite3/Table.php b/system/Database/SQLite3/Table.php index 47e6d1a7..bd2056d5 100644 --- a/system/Database/SQLite3/Table.php +++ b/system/Database/SQLite3/Table.php @@ -280,7 +280,7 @@ public function addForeignKey(array $foreignKeys) /** * Creates the new table based on our current fields. * - * @return mixed + * @return bool */ protected function createTable() { @@ -449,16 +449,12 @@ private function isNumericType(string $type): bool * Converts keys retrieved from the database to * the format needed to create later. * - * @param mixed $keys + * @param array $keys * - * @return mixed + * @return array */ protected function formatKeys($keys) { - if (! is_array($keys)) { - return $keys; - } - $return = []; foreach ($keys as $name => $key) { diff --git a/system/Debug/ExceptionHandler.php b/system/Debug/ExceptionHandler.php index 63449888..09c6de0d 100644 --- a/system/Debug/ExceptionHandler.php +++ b/system/Debug/ExceptionHandler.php @@ -97,8 +97,8 @@ public function handle( . DIRECTORY_SEPARATOR . 'errors' . DIRECTORY_SEPARATOR . $addPath; // Determine the views - $view = $this->determineView($exception, $path); - $altView = $this->determineView($exception, $altPath); + $view = $this->determineView($exception, $path, $statusCode); + $altView = $this->determineView($exception, $altPath, $statusCode); // Check if the view exists $viewFile = null; @@ -119,13 +119,16 @@ public function handle( } /** - * Determines the view to display based on the exception thrown, - * whether an HTTP or CLI request, etc. + * Determines the view to display based on the exception thrown, HTTP status + * code, whether an HTTP or CLI request, etc. * * @return string The filename of the view file to use */ - protected function determineView(Throwable $exception, string $templatePath): string - { + protected function determineView( + Throwable $exception, + string $templatePath, + int $statusCode = 500 + ): string { // Production environments should have a custom exception file. $view = 'production.php'; @@ -147,8 +150,8 @@ protected function determineView(Throwable $exception, string $templatePath): st $templatePath = rtrim($templatePath, '\\/ ') . DIRECTORY_SEPARATOR; // Allow for custom views based upon the status code - if (is_file($templatePath . 'error_' . $exception->getCode() . '.php')) { - return 'error_' . $exception->getCode() . '.php'; + if (is_file($templatePath . 'error_' . $statusCode . '.php')) { + return 'error_' . $statusCode . '.php'; } return $view; diff --git a/system/HTTP/DownloadResponse.php b/system/HTTP/DownloadResponse.php index 14dc3fec..d815a9af 100644 --- a/system/HTTP/DownloadResponse.php +++ b/system/HTTP/DownloadResponse.php @@ -194,7 +194,7 @@ private function getContentDisposition(): string $result = sprintf('attachment; filename="%s"', $downloadFilename); - if ($utf8Filename) { + if ($utf8Filename !== '') { $result .= '; filename*=UTF-8\'\'' . rawurlencode($utf8Filename); } diff --git a/system/HTTP/Files/UploadedFile.php b/system/HTTP/Files/UploadedFile.php index 70ece748..e0725e7c 100644 --- a/system/HTTP/Files/UploadedFile.php +++ b/system/HTTP/Files/UploadedFile.php @@ -15,8 +15,6 @@ use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\Mimes; use Exception; -use InvalidArgumentException; -use RuntimeException; /** * Value object representing a single file uploaded through an @@ -80,12 +78,12 @@ class UploadedFile extends File implements UploadedFileInterface /** * Accepts the file information as would be filled in from the $_FILES array. * - * @param string $path The temporary location of the uploaded file. - * @param string $originalName The client-provided filename. - * @param string $mimeType The type of file as provided by PHP - * @param int $size The size of the file, in bytes - * @param int $error The error constant of the upload (one of PHP's UPLOADERRXXX constants) - * @param string $clientPath The webkit relative path of the uploaded file. + * @param string $path The temporary location of the uploaded file. + * @param string $originalName The client-provided filename. + * @param string|null $mimeType The type of file as provided by PHP + * @param int|null $size The size of the file, in bytes + * @param int|null $error The error constant of the upload (one of PHP's UPLOADERRXXX constants) + * @param string|null $clientPath The webkit relative path of the uploaded file. */ public function __construct(string $path, string $originalName, ?string $mimeType = null, ?int $size = null, ?int $error = null, ?string $clientPath = null) { @@ -122,16 +120,12 @@ public function __construct(string $path, string $originalName, ?string $mimeTyp * @see http://php.net/is_uploaded_file * @see http://php.net/move_uploaded_file * - * @param string $targetPath Path to which to move the uploaded file. - * @param string $name the name to rename the file to. - * @param bool $overwrite State for indicating whether to overwrite the previously generated file with the same - * name or not. + * @param string $targetPath Path to which to move the uploaded file. + * @param string|null $name the name to rename the file to. + * @param bool $overwrite State for indicating whether to overwrite the previously generated file with the same + * name or not. * * @return bool - * - * @throws InvalidArgumentException if the $path specified is invalid. - * @throws RuntimeException on any error during the move operation. - * @throws RuntimeException on the second or subsequent call to the method. */ public function move(string $targetPath, ?string $name = null, bool $overwrite = false) { @@ -345,8 +339,8 @@ public function isValid(): bool * By default, upload files are saved in writable/uploads directory. The YYYYMMDD folder * and random file name will be created. * - * @param string $folderName the folder name to writable/uploads directory. - * @param string $fileName the name to rename the file to. + * @param string|null $folderName the folder name to writable/uploads directory. + * @param string|null $fileName the name to rename the file to. * * @return string file full path */ diff --git a/system/HTTP/Files/UploadedFileInterface.php b/system/HTTP/Files/UploadedFileInterface.php index 170f81c2..ef2073f2 100644 --- a/system/HTTP/Files/UploadedFileInterface.php +++ b/system/HTTP/Files/UploadedFileInterface.php @@ -26,12 +26,12 @@ interface UploadedFileInterface /** * Accepts the file information as would be filled in from the $_FILES array. * - * @param string $path The temporary location of the uploaded file. - * @param string $originalName The client-provided filename. - * @param string $mimeType The type of file as provided by PHP - * @param int $size The size of the file, in bytes - * @param int $error The error constant of the upload (one of PHP's UPLOADERRXXX constants) - * @param string $clientPath The webkit relative path of the uploaded file. + * @param string $path The temporary location of the uploaded file. + * @param string $originalName The client-provided filename. + * @param string|null $mimeType The type of file as provided by PHP + * @param int|null $size The size of the file, in bytes + * @param int|null $error The error constant of the upload (one of PHP's UPLOADERRXXX constants) + * @param string|null $clientPath The webkit relative path of the uploaded file. */ public function __construct(string $path, string $originalName, ?string $mimeType = null, ?int $size = null, ?int $error = null, ?string $clientPath = null); @@ -57,13 +57,12 @@ public function __construct(string $path, string $originalName, ?string $mimeTyp * @see http://php.net/is_uploaded_file * @see http://php.net/move_uploaded_file * - * @param string $targetPath Path to which to move the uploaded file. - * @param string $name the name to rename the file to. + * @param string $targetPath Path to which to move the uploaded file. + * @param string|null $name the name to rename the file to. * * @return bool * * @throws InvalidArgumentException if the $path specified is invalid. - * @throws RuntimeException on any error during the move operation. * @throws RuntimeException on the second or subsequent call to the method. */ public function move(string $targetPath, ?string $name = null); diff --git a/system/Helpers/filesystem_helper.php b/system/Helpers/filesystem_helper.php index 4e0e8b15..46700ffc 100644 --- a/system/Helpers/filesystem_helper.php +++ b/system/Helpers/filesystem_helper.php @@ -379,19 +379,19 @@ function symbolic_permissions(int $perms): string } // Owner - $symbolic .= (($perms & 0x0100) ? 'r' : '-') - . (($perms & 0x0080) ? 'w' : '-') - . (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x') : (($perms & 0x0800) ? 'S' : '-')); + $symbolic .= ((($perms & 0x0100) !== 0) ? 'r' : '-') + . ((($perms & 0x0080) !== 0) ? 'w' : '-') + . ((($perms & 0x0040) !== 0) ? ((($perms & 0x0800) !== 0) ? 's' : 'x') : ((($perms & 0x0800) !== 0) ? 'S' : '-')); // Group - $symbolic .= (($perms & 0x0020) ? 'r' : '-') - . (($perms & 0x0010) ? 'w' : '-') - . (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x') : (($perms & 0x0400) ? 'S' : '-')); + $symbolic .= ((($perms & 0x0020) !== 0) ? 'r' : '-') + . ((($perms & 0x0010) !== 0) ? 'w' : '-') + . ((($perms & 0x0008) !== 0) ? ((($perms & 0x0400) !== 0) ? 's' : 'x') : ((($perms & 0x0400) !== 0) ? 'S' : '-')); // World - $symbolic .= (($perms & 0x0004) ? 'r' : '-') - . (($perms & 0x0002) ? 'w' : '-') - . (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x') : (($perms & 0x0200) ? 'T' : '-')); + $symbolic .= ((($perms & 0x0004) !== 0) ? 'r' : '-') + . ((($perms & 0x0002) !== 0) ? 'w' : '-') + . ((($perms & 0x0001) !== 0) ? ((($perms & 0x0200) !== 0) ? 't' : 'x') : ((($perms & 0x0200) !== 0) ? 'T' : '-')); return $symbolic; } diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 098222e9..5f62cca8 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -29,7 +29,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): string { // If no action is provided then set to the current url - if (! $action) { + if ($action === '') { $action = current_url(true); } // If an action is not a full URL then turn it into one elseif (strpos($action, '://') === false) { diff --git a/system/Helpers/html_helper.php b/system/Helpers/html_helper.php index 0f7e154a..6d9a5135 100755 --- a/system/Helpers/html_helper.php +++ b/system/Helpers/html_helper.php @@ -195,7 +195,7 @@ function doctype(string $type = 'html5'): string function script_tag($src = '', bool $indexPage = false): string { $cspNonce = csp_script_nonce(); - $cspNonce = $cspNonce ? ' ' . $cspNonce : $cspNonce; + $cspNonce = $cspNonce !== '' ? ' ' . $cspNonce : $cspNonce; $script = ' $src]; diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index f992eac3..988d7de8 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -318,7 +318,7 @@ function safe_mailto(string $email, string $title = '', $attributes = ''): strin // improve obfuscation by eliminating newlines & whitespace $cspNonce = csp_script_nonce(); - $cspNonce = $cspNonce ? ' ' . $cspNonce : $cspNonce; + $cspNonce = $cspNonce !== '' ? ' ' . $cspNonce : $cspNonce; $output = '' . 'var l=new Array();'; diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index cb8ce9ba..d5396958 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -32,8 +32,6 @@ class ImageMagickHandler extends BaseHandler protected $resource; /** - * Constructor. - * * @param Images $config * * @throws ImageException @@ -45,6 +43,22 @@ public function __construct($config = null) if (! (extension_loaded('imagick') || class_exists(Imagick::class))) { throw ImageException::forMissingExtension('IMAGICK'); // @codeCoverageIgnore } + + $cmd = $this->config->libraryPath; + + if ($cmd === '') { + throw ImageException::forInvalidImageLibraryPath($cmd); + } + + if (preg_match('/convert$/i', $cmd) !== 1) { + $cmd = rtrim($cmd, '\/') . '/convert'; + + $this->config->libraryPath = $cmd; + } + + if (! is_file($cmd)) { + throw ImageException::forInvalidImageLibraryPath($cmd); + } } /** @@ -167,12 +181,10 @@ protected function _flip(string $direction) */ public function getVersion(): string { - $result = $this->process('-version'); + $versionString = $this->process('-version')[0]; + preg_match('/ImageMagick\s(?P[\S]+)/', $versionString, $matches); - // The first line has the version in it... - preg_match('/(ImageMagick\s[\S]+)/', $result[0], $matches); - - return str_replace('ImageMagick ', '', $matches[0]); + return $matches['version']; } /** @@ -184,19 +196,10 @@ public function getVersion(): string */ protected function process(string $action, int $quality = 100): array { - // Do we have a vaild library path? - if (empty($this->config->libraryPath)) { - throw ImageException::forInvalidImageLibraryPath($this->config->libraryPath); - } - if ($action !== '-version') { $this->supportedFormatCheck(); } - if (! preg_match('/convert$/i', $this->config->libraryPath)) { - $this->config->libraryPath = rtrim($this->config->libraryPath, '/') . '/convert'; - } - $cmd = $this->config->libraryPath; $cmd .= $action === '-version' ? ' ' . $action : ' -quality ' . $quality . ' ' . $action; diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index d9de5faa..0834fe09 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -60,9 +60,9 @@ class Pager implements PagerInterface /** * List of only permitted queries * - * @var array + * @var list|null */ - protected $only = []; + protected $only; /** * Constructor. @@ -276,7 +276,7 @@ public function getPageURI(?int $page = null, string $group = 'default', bool $r $uri->addQuery($this->groups[$group]['pageSelector'], $page); } - if ($this->only) { + if ($this->only !== null) { $query = array_intersect_key($_GET, array_flip($this->only)); if (! $segment) { diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 2adb0ed9..117f3a21 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -767,7 +767,7 @@ public function group(string $name, ...$params) // To register a route, we'll set a flag so that our router // will see the group name. // If the group name is empty, we go on using the previously built group name. - $this->group = $name ? trim($oldGroup . '/' . $name, '/') : $oldGroup; + $this->group = $name !== '' ? trim($oldGroup . '/' . $name, '/') : $oldGroup; $callback = array_pop($params); diff --git a/system/Session/Handlers/FileHandler.php b/system/Session/Handlers/FileHandler.php index 9eb64240..62513d39 100644 --- a/system/Session/Handlers/FileHandler.php +++ b/system/Session/Handlers/FileHandler.php @@ -73,7 +73,7 @@ public function __construct(SessionConfig $config, string $ipAddress) } else { $sessionPath = rtrim(ini_get('session.save_path'), '/\\'); - if (! $sessionPath) { + if ($sessionPath === '') { $sessionPath = WRITEPATH . 'session'; } diff --git a/system/View/Table.php b/system/View/Table.php index c9cd33d3..65b43195 100644 --- a/system/View/Table.php +++ b/system/View/Table.php @@ -365,7 +365,7 @@ public function generate($tableData = null) foreach ($this->rows as $row) { // We use modulus to alternate the row colors - $name = fmod($i++, 2) ? '' : 'alt_'; + $name = fmod($i++, 2) !== 0.0 ? '' : 'alt_'; $out .= $this->template['row_' . $name . 'start'] . $this->newline; diff --git a/writable/.htaccess b/writable/.htaccess index f24db0ac..3462048a 100755 --- a/writable/.htaccess +++ b/writable/.htaccess @@ -1,6 +1,6 @@ - Require all denied + Require all denied - Deny from all + Deny from all