Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.5
Browse files Browse the repository at this point in the history
 Conflicts:
	phpstan-baseline.php
  • Loading branch information
kenjis committed Oct 16, 2023
2 parents 5f0a8ca + 431748b commit b7cb0cc
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 145 deletions.
115 changes: 0 additions & 115 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Autoloader/FileLocator.php',
];
$ignoreErrors[] = [
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
'count' => 6,
Expand Down Expand Up @@ -136,16 +131,6 @@
'count' => 1,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, array given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, int given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in \\|\\|, string given on the left side\\.$#',
'count' => 1,
Expand All @@ -166,11 +151,6 @@
'count' => 5,
'path' => __DIR__ . '/system/CLI/CLI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, array given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/CLI/Commands.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 2,
Expand Down Expand Up @@ -206,26 +186,11 @@
'count' => 1,
'path' => __DIR__ . '/system/Cache/Handlers/PredisHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, int given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Cache/Handlers/PredisHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, int given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Cache/Handlers/RedisHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 6,
'path' => __DIR__ . '/system/CodeIgniter.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, CodeIgniter\\\\HTTP\\\\ResponseInterface\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/CodeIgniter.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\CodeIgniter\\:\\:\\$controller type has no signature specified for Closure\\.$#',
'count' => 1,
Expand Down Expand Up @@ -961,11 +926,6 @@
'count' => 2,
'path' => __DIR__ . '/system/Config/Factories.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string\\|null given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Config/Factories.php',
];
$ignoreErrors[] = [
'message' => '#^Accessing offset \'SERVER_PROTOCOL\' directly on \\$_SERVER is discouraged\\.$#',
'count' => 1,
Expand Down Expand Up @@ -1916,31 +1876,11 @@
'count' => 2,
'path' => __DIR__ . '/system/Debug/ExceptionHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Debug/ExceptionHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
'path' => __DIR__ . '/system/Debug/Exceptions.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, Throwable\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Debug/Exceptions.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, int given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Debug/Exceptions.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Debug/Exceptions.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
Expand Down Expand Up @@ -2031,11 +1971,6 @@
'count' => 2,
'path' => __DIR__ . '/system/Encryption/Encryption.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, Config\\\\Encryption\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Encryption/Encryption.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 2,
Expand Down Expand Up @@ -2156,11 +2091,6 @@
'count' => 1,
'path' => __DIR__ . '/system/HTTP/CURLRequest.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/HTTP/CURLRequest.php',
];
$ignoreErrors[] = [
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
'count' => 1,
Expand Down Expand Up @@ -2416,11 +2346,6 @@
'count' => 4,
'path' => __DIR__ . '/system/HTTP/SiteURI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/HTTP/SiteURI.php',
];
$ignoreErrors[] = [
'message' => '#^Strict comparison using \\!\\=\\= between mixed and null will always evaluate to true\\.$#',
'count' => 1,
Expand All @@ -2431,16 +2356,6 @@
'count' => 15,
'path' => __DIR__ . '/system/HTTP/URI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/HTTP/URI.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string\\|null given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/HTTP/URI.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\HTTP\\\\URI\\:\\:\\$fragment \\(string\\) on left side of \\?\\? is not nullable\\.$#',
'count' => 1,
Expand Down Expand Up @@ -2611,11 +2526,6 @@
'count' => 2,
'path' => __DIR__ . '/system/Helpers/test_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, array\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Helpers/test_helper.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
Expand Down Expand Up @@ -2776,11 +2686,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Log/Logger.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, array given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Log/Logger.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$level \\(string\\) of method CodeIgniter\\\\Log\\\\Logger\\:\\:log\\(\\) should be contravariant with parameter \\$level \\(mixed\\) of method Psr\\\\Log\\\\LoggerInterface\\:\\:log\\(\\)$#',
'count' => 1,
Expand Down Expand Up @@ -2838,11 +2743,6 @@
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, array given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Pager/Pager.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, int given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Pager/Pager.php',
];
Expand Down Expand Up @@ -3631,11 +3531,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Test/FeatureTestCase.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, array\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Test/FeatureTestCase.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\Test\\\\CIUnitTestCase\\:\\:\\$bodyFormat \\(string\\) in isset\\(\\) is not nullable\\.$#',
'count' => 1,
Expand Down Expand Up @@ -4141,11 +4036,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Validation/Validation.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, array given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Validation/Validation.php',
];
$ignoreErrors[] = [
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
'count' => 2,
Expand Down Expand Up @@ -4216,11 +4106,6 @@
'count' => 3,
'path' => __DIR__ . '/system/View/View.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in an if condition, string\\|null given\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/View/View.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$context \\(\'attr\'\\|\'css\'\\|\'html\'\\|\'js\'\\|\'raw\'\\|\'url\'\\|null\\) of method CodeIgniter\\\\View\\\\View\\:\\:setData\\(\\) should be contravariant with parameter \\$context \\(string\\|null\\) of method CodeIgniter\\\\View\\\\RendererInterface\\:\\:setData\\(\\)$#',
'count' => 1,
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
use Utils\Rector\RemoveVarTagFromClassConstantRector;
Expand Down Expand Up @@ -140,4 +141,5 @@
$rectorConfig->rule(StringClassNameToClassConstantRector::class);
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
$rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class);
};
2 changes: 1 addition & 1 deletion system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function search(string $path, string $ext = 'php', bool $prioritizeApp =
*/
protected function ensureExt(string $path, string $ext): string
{
if ($ext) {
if ($ext !== '') {
$ext = '.' . $ext;

if (substr($path, -strlen($ext)) !== $ext) {
Expand Down
4 changes: 3 additions & 1 deletion system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ public function paginate(?int $perPage = null, string $group = 'default', ?int $
// Since multiple models may use the Pager, the Pager must be shared.
$pager = Services::pager();

if ($segment) {
if ($segment !== 0) {
$pager->setSegment($segment, $group);
}

Expand Down Expand Up @@ -1640,6 +1640,8 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv
{
$properties = $this->objectToRawArray($data, $onlyChanged, $recursive);

assert(is_array($properties));

Check failure on line 1643 in system/BaseModel.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Call to function is_array() with array will always evaluate to true.

// Convert any Time instances to appropriate $dateFormat
if ($properties !== []) {
$properties = array_map(function ($value) {
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static function prompt(string $field, $options = null, $validation = null
// Read the input from keyboard.
$input = trim(static::input()) ?: $default;

if ($validation) {
if ($validation !== []) {
while (! static::validate('"' . trim($field) . '"', $input, $validation)) {
$input = static::prompt($field, $options, $validation);
}
Expand Down Expand Up @@ -1088,7 +1088,7 @@ public static function table(array $tbody, array $thead = [])
foreach ($tableRows[$row] as $col) {
$diff = $maxColsLengths[$column] - static::strlen($col);

if ($diff) {
if ($diff !== 0) {
$tableRows[$row][$column] .= str_repeat(' ', $diff);
}

Expand Down
3 changes: 2 additions & 1 deletion system/CLI/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public function verifyCommand(string $command, array $commands): bool

$message = lang('CLI.commandNotFound', [$command]);

if ($alternatives = $this->getCommandAlternatives($command, $commands)) {
$alternatives = $this->getCommandAlternatives($command, $commands);
if ($alternatives !== []) {
if (count($alternatives) === 1) {
$message .= "\n\n" . lang('CLI.altCommandSingular') . "\n ";
} else {
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function save(string $key, $value, int $ttl = 60)
return false;
}

if ($ttl) {
if ($ttl !== 0) {
$this->redis->expireat($key, Time::now()->getTimestamp() + $ttl);
}

Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function save(string $key, $value, int $ttl = 60)
return false;
}

if ($ttl) {
if ($ttl !== 0) {
$this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl);
}

Expand Down
3 changes: 2 additions & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,8 @@ protected function forceSecureAccess($duration = 31_536_000)
*/
public function displayCache(Cache $config)
{
if ($cachedResponse = $this->pageCache->get($this->request, $this->response)) {
$cachedResponse = $this->pageCache->get($this->request, $this->response);
if ($cachedResponse instanceof ResponseInterface) {
$this->response = $cachedResponse;

$this->totalTime = $this->benchmark->getElapsedTime('total_execution');
Expand Down
5 changes: 3 additions & 2 deletions system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public static function __callStatic(string $component, array $arguments)
}

// Try to locate the class
if ($class = self::locateClass($options, $alias)) {
$class = self::locateClass($options, $alias);
if ($class !== null) {
return new $class(...$arguments);
}

Expand Down Expand Up @@ -422,7 +423,7 @@ public static function setOptions(string $component, array $values): array
*/
public static function reset(?string $component = null)
{
if ($component) {
if ($component !== null) {
unset(
static::$options[$component],
static::$aliases[$component],
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function determineView(Throwable $exception, string $templatePath): st
// Production environments should have a custom exception file.
$view = 'production.php';

if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors'))) {
if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') {
$view = 'error_exception.php';
}

Expand Down
6 changes: 3 additions & 3 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function errorHandler(int $severity, string $message, ?string $file = nul
return $this->handleDeprecationError($message, $file, $line);
}

if (error_reporting() & $severity) {
if ((error_reporting() & $severity) !== 0) {
throw new ErrorException($message, 0, $severity, $file, $line);
}

Expand All @@ -227,7 +227,7 @@ public function shutdownHandler()

['type' => $type, 'message' => $message, 'file' => $file, 'line' => $line] = $error;

if ($this->exceptionCaughtByExceptionHandler) {
if ($this->exceptionCaughtByExceptionHandler instanceof Throwable) {
$message .= "\n【Previous Exception】\n"
. get_class($this->exceptionCaughtByExceptionHandler) . "\n"
. $this->exceptionCaughtByExceptionHandler->getMessage() . "\n"
Expand All @@ -253,7 +253,7 @@ protected function determineView(Throwable $exception, string $templatePath): st
$view = 'production.php';
$templatePath = rtrim($templatePath, '\\/ ') . DIRECTORY_SEPARATOR;

if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors'))) {
if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') {
$view = 'error_exception.php';
}

Expand Down
2 changes: 1 addition & 1 deletion system/Encryption/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function __construct(?EncryptionConfig $config = null)
*/
public function initialize(?EncryptionConfig $config = null)
{
if ($config) {
if ($config instanceof EncryptionConfig) {
$this->key = $config->key;
$this->driver = $config->driver;
$this->digest = $config->digest ?? 'SHA512';
Expand Down
Loading

0 comments on commit b7cb0cc

Please sign in to comment.