Skip to content

Commit c7548a3

Browse files
committed
Merge branch 'develop' into 4.6
2 parents 22b8e9e + ee4ee98 commit c7548a3

File tree

96 files changed

+314
-584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+314
-584
lines changed

.php-cs-fixer.tests.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'_support/View/Cells/multiplier.php',
2727
'_support/View/Cells/colors.php',
2828
'_support/View/Cells/addition.php',
29+
'system/Database/Live/PreparedQueryTest.php',
2930
])
3031
->notName('#Foobar.php$#');
3132

app/Views/errors/cli/error_exception.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
$args = implode(', ', array_map(static fn ($value) => match (true) {
5454
is_object($value) => 'Object(' . $value::class . ')',
55-
is_array($value) => count($value) ? '[...]' : '[]',
55+
is_array($value) => $value !== [] ? '[...]' : '[]',
5656
$value === null => 'null', // return the lowercased version
5757
default => var_export($value, true),
5858
}, array_values($error['args'] ?? [])));

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"phpunit/phpcov": "^9.0.2 || ^10.0",
2929
"phpunit/phpunit": "^10.5.16 || ^11.2",
3030
"predis/predis": "^1.1 || ^2.3",
31-
"rector/rector": "2.0.3",
31+
"rector/rector": "2.0.4",
3232
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
3333
},
3434
"replace": {

rector.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
3838
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
3939
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
40-
use Rector\PHPUnit\Set\PHPUnitSetList;
4140
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
4241
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
4342
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
@@ -55,11 +54,8 @@
5554

5655
return RectorConfig::configure()
5756
->withPhpSets(php81: true)
58-
->withPreparedSets(deadCode: true)
59-
->withSets([
60-
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
61-
PHPUnitSetList::PHPUNIT_100,
62-
])
57+
->withPreparedSets(deadCode: true, instanceOf: true, strictBooleans: true, phpunitCodeQuality: true)
58+
->withComposerBased(phpunit: true)
6359
->withParallel(120, 8, 10)
6460
->withCache(
6561
// Github action cache or local

system/BaseModel.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public function findColumn(string $columnName)
639639

640640
$resultSet = $this->doFindColumn($columnName);
641641

642-
return $resultSet ? array_column($resultSet, $columnName) : null;
642+
return $resultSet !== null ? array_column($resultSet, $columnName) : null;
643643
}
644644

645645
/**
@@ -1137,7 +1137,7 @@ public function delete($id = null, bool $purge = false)
11371137
throw new InvalidArgumentException('delete(): argument #1 ($id) should not be boolean.');
11381138
}
11391139

1140-
if ($id && (is_numeric($id) || is_string($id))) {
1140+
if (! in_array($id, [null, 0, '0'], true) && (is_numeric($id) || is_string($id))) {
11411141
$id = [$id];
11421142
}
11431143

@@ -1250,7 +1250,7 @@ public function errors(bool $forceDB = false)
12501250
}
12511251

12521252
// Do we have validation errors?
1253-
if (! $forceDB && ! $this->skipValidation && ($errors = $this->validation->getErrors())) {
1253+
if (! $forceDB && ! $this->skipValidation && ($errors = $this->validation->getErrors()) !== []) {
12541254
return $errors;
12551255
}
12561256

system/CLI/CLI.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ public static function prompt(string $field, $options = null, $validation = null
225225
$extraOutput = '';
226226
$default = '';
227227

228-
if ($validation && ! is_array($validation) && ! is_string($validation)) {
228+
if (isset($validation) && ! is_array($validation) && ! is_string($validation)) {
229229
throw new InvalidArgumentException('$rules can only be of type string|array');
230230
}
231231

232232
if (! is_array($validation)) {
233-
$validation = $validation ? explode('|', $validation) : [];
233+
$validation = ($validation !== null) ? explode('|', $validation) : [];
234234
}
235235

236236
if (is_string($options)) {
@@ -348,7 +348,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
348348
// return the prompt again if $input contain(s) non-numeric character, except a comma.
349349
// And if max from $options less than max from input,
350350
// it means user tried to access null value in $options
351-
if (! $pattern || $maxOptions < $maxInput) {
351+
if ($pattern === 0 || $maxOptions < $maxInput) {
352352
static::error('Please select correctly.');
353353
CLI::newLine();
354354

@@ -441,7 +441,7 @@ protected static function validate(string $field, string $value, $rules): bool
441441
*/
442442
public static function print(string $text = '', ?string $foreground = null, ?string $background = null)
443443
{
444-
if ($foreground || $background) {
444+
if ((string) $foreground !== '' || (string) $background !== '') {
445445
$text = static::color($text, $foreground, $background);
446446
}
447447

@@ -457,7 +457,7 @@ public static function print(string $text = '', ?string $foreground = null, ?str
457457
*/
458458
public static function write(string $text = '', ?string $foreground = null, ?string $background = null)
459459
{
460-
if ($foreground || $background) {
460+
if ((string) $foreground !== '' || (string) $background !== '') {
461461
$text = static::color($text, $foreground, $background);
462462
}
463463

@@ -480,7 +480,7 @@ public static function error(string $text, string $foreground = 'light_red', ?st
480480
$stdout = static::$isColored;
481481
static::$isColored = static::hasColorSupport(STDERR);
482482

483-
if ($foreground || $background) {
483+
if ($foreground !== '' || (string) $background !== '') {
484484
$text = static::color($text, $foreground, $background);
485485
}
486486

@@ -589,7 +589,7 @@ public static function color(string $text, string $foreground, ?string $backgrou
589589
throw CLIException::forInvalidColor('foreground', $foreground);
590590
}
591591

592-
if ($background !== null && ! array_key_exists($background, static::$background_colors)) {
592+
if ((string) $background !== '' && ! array_key_exists($background, static::$background_colors)) {
593593
throw CLIException::forInvalidColor('background', $background);
594594
}
595595

@@ -637,7 +637,7 @@ private static function getColoredText(string $text, string $foreground, ?string
637637
{
638638
$string = "\033[" . static::$foreground_colors[$foreground] . 'm';
639639

640-
if ($background !== null) {
640+
if ((string) $background !== '') {
641641
$string .= "\033[" . static::$background_colors[$background] . 'm';
642642
}
643643

@@ -654,7 +654,7 @@ private static function getColoredText(string $text, string $foreground, ?string
654654
*/
655655
public static function strlen(?string $string): int
656656
{
657-
if ($string === null) {
657+
if ((string) $string === '') {
658658
return 0;
659659
}
660660

@@ -768,7 +768,7 @@ public static function generateDimensions()
768768

769769
// Look for the next lines ending in ": <number>"
770770
// Searching for "Columns:" or "Lines:" will fail on non-English locales
771-
if ($return === 0 && $output && preg_match('/:\s*(\d+)\n[^:]+:\s*(\d+)\n/', implode("\n", $output), $matches)) {
771+
if ($return === 0 && $output !== [] && preg_match('/:\s*(\d+)\n[^:]+:\s*(\d+)\n/', implode("\n", $output), $matches)) {
772772
static::$height = (int) $matches[1];
773773
static::$width = (int) $matches[2];
774774
}
@@ -835,7 +835,7 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10)
835835
*/
836836
public static function wrap(?string $string = null, int $max = 0, int $padLeft = 0): string
837837
{
838-
if ($string === null || $string === '') {
838+
if ((string) $string === '') {
839839
return '';
840840
}
841841

system/Cache/Handlers/BaseHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function validateKey($key, $prefix = ''): string
6868
}
6969

7070
$reserved = config(Cache::class)->reservedCharacters ?? self::RESERVED_CHARACTERS;
71-
if ($reserved && strpbrk($key, $reserved) !== false) {
71+
if ($reserved !== '' && strpbrk($key, $reserved) !== false) {
7272
throw new InvalidArgumentException('Cache key contains reserved characters ' . $reserved);
7373
}
7474

system/Cache/Handlers/FileHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs
308308
if ($filename !== '.' && $filename !== '..') {
309309
if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.') {
310310
$this->deleteFiles($path . DIRECTORY_SEPARATOR . $filename, $delDir, $htdocs, $_level + 1);
311-
} elseif (! $htdocs || ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) {
311+
} elseif (! $htdocs || preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename) !== 1) {
312312
@unlink($path . DIRECTORY_SEPARATOR . $filename);
313313
}
314314
}

system/Cache/Handlers/PredisHandler.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Exception;
2020
use Predis\Client;
2121
use Predis\Collection\Iterator\Keyspace;
22+
use Predis\Response\Status;
2223

2324
/**
2425
* Predis cache handler
@@ -121,7 +122,7 @@ public function save(string $key, $value, int $ttl = 60)
121122
return false;
122123
}
123124

124-
if (! $this->redis->hmset($key, ['__ci_type' => $dataType, '__ci_value' => $value])) {
125+
if (! $this->redis->hmset($key, ['__ci_type' => $dataType, '__ci_value' => $value]) instanceof Status) {
125126
return false;
126127
}
127128

system/Commands/ListCommands.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,24 @@ class ListCommands extends BaseCommand
7171

7272
/**
7373
* Displays the help for the spark cli script itself.
74+
*
75+
* @return int
7476
*/
7577
public function run(array $params)
7678
{
7779
$commands = $this->commands->getCommands();
7880
ksort($commands);
7981

8082
// Check for 'simple' format
81-
return array_key_exists('simple', $params) || CLI::getOption('simple')
83+
return array_key_exists('simple', $params) || CLI::getOption('simple') === true
8284
? $this->listSimple($commands)
8385
: $this->listFull($commands);
8486
}
8587

8688
/**
8789
* Lists the commands with accompanying info.
8890
*
89-
* @return void
91+
* @return int
9092
*/
9193
protected function listFull(array $commands)
9294
{
@@ -124,17 +126,21 @@ protected function listFull(array $commands)
124126
CLI::newLine();
125127
}
126128
}
129+
130+
return EXIT_SUCCESS;
127131
}
128132

129133
/**
130134
* Lists the commands only.
131135
*
132-
* @return void
136+
* @return int
133137
*/
134138
protected function listSimple(array $commands)
135139
{
136140
foreach (array_keys($commands) as $title) {
137141
CLI::write($title);
138142
}
143+
144+
return EXIT_SUCCESS;
139145
}
140146
}

system/Commands/Server/Serve.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function run(array $params)
110110
// to ensure our environment is set and it simulates basic mod_rewrite.
111111
passthru($php . ' -S ' . $host . ':' . $port . ' -t ' . $docroot . ' ' . $rewrite, $status);
112112

113-
if ($status && $this->portOffset < $this->tries) {
113+
if ($status !== EXIT_SUCCESS && $this->portOffset < $this->tries) {
114114
$this->portOffset++;
115115

116116
$this->run($params);

system/Commands/Utilities/Routes.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function run(array $params)
8686
$host = $params['host'] ?? null;
8787

8888
// Set HTTP_HOST
89-
if ($host) {
89+
if ($host !== null) {
9090
$request = service('request');
9191
$_SERVER = $request->getServer();
9292
$_SERVER['HTTP_HOST'] = $host;
@@ -96,7 +96,7 @@ public function run(array $params)
9696
$collection = service('routes')->loadRoutes();
9797

9898
// Reset HTTP_HOST
99-
if ($host) {
99+
if ($host !== null) {
100100
unset($_SERVER['HTTP_HOST']);
101101
}
102102

@@ -139,7 +139,9 @@ public function run(array $params)
139139
$autoRoutes = $autoRouteCollector->get();
140140

141141
// Check for Module Routes.
142-
if ($routingConfig = config(Routing::class)) {
142+
$routingConfig = config(Routing::class);
143+
144+
if ($routingConfig instanceof Routing) {
143145
foreach ($routingConfig->moduleRoutes as $uri => $namespace) {
144146
$autoRouteCollector = new AutoRouteCollectorImproved(
145147
$namespace,
@@ -188,7 +190,7 @@ public function run(array $params)
188190
usort($tbody, static fn ($handler1, $handler2) => strcmp($handler1[3], $handler2[3]));
189191
}
190192

191-
if ($host) {
193+
if ($host !== null) {
192194
CLI::write('Host: ' . $host);
193195
}
194196

system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function getRouteForDefaultController(
221221
if ($classShortname === $defaultController) {
222222
$pattern = '#' . preg_quote(lcfirst($defaultController), '#') . '\z#';
223223
$routeWithoutController = rtrim(preg_replace($pattern, '', $uriByClass), '/');
224-
$routeWithoutController = $routeWithoutController ?: '/';
224+
$routeWithoutController = $routeWithoutController !== '' && $routeWithoutController !== '0' ? $routeWithoutController : '/';
225225

226226
[$params, $routeParams] = $this->getParameters($method);
227227

system/Commands/Utilities/Routes/ControllerMethodReader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private function getRouteWithoutController(
161161

162162
$pattern = '#' . preg_quote(lcfirst($defaultController), '#') . '\z#';
163163
$routeWithoutController = rtrim(preg_replace($pattern, '', $uriByClass), '/');
164-
$routeWithoutController = $routeWithoutController ?: '/';
164+
$routeWithoutController = $routeWithoutController !== '' && $routeWithoutController !== '0' ? $routeWithoutController : '/';
165165

166166
return [[
167167
'route' => $routeWithoutController,

system/Common.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ function esc($data, string $context = 'html', ?string $encoding = null)
443443
$escaper = new Escaper($encoding);
444444
}
445445

446-
if ($encoding && $escaper->getEncoding() !== $encoding) {
446+
if ($encoding !== null && $escaper->getEncoding() !== $encoding) {
447447
$escaper = new Escaper($encoding);
448448
}
449449

@@ -741,13 +741,13 @@ function lang(string $line, array $args = [], ?string $locale = null)
741741
// Get active locale
742742
$activeLocale = $language->getLocale();
743743

744-
if ($locale && $locale !== $activeLocale) {
744+
if ((string) $locale !== '' && $locale !== $activeLocale) {
745745
$language->setLocale($locale);
746746
}
747747

748748
$lines = $language->getLine($line, $args);
749749

750-
if ($locale && $locale !== $activeLocale) {
750+
if ((string) $locale !== '' && $locale !== $activeLocale) {
751751
// Reset to active locale
752752
$language->setLocale($activeLocale);
753753
}
@@ -851,7 +851,7 @@ function redirect(?string $route = null): RedirectResponse
851851
{
852852
$response = service('redirectresponse');
853853

854-
if ($route !== null) {
854+
if ((string) $route !== '') {
855855
return $response->route($route);
856856
}
857857

system/Config/DotEnv.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function parse(): ?array
9494
*/
9595
protected function setVariable(string $name, string $value = '')
9696
{
97-
if (! getenv($name, true)) {
97+
if (getenv($name, true) === false) {
9898
putenv("{$name}={$value}");
9999
}
100100

system/Config/Services.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public static function image(?string $handler = null, ?Images $config = null, bo
345345
$config ??= config(Images::class);
346346
assert($config instanceof Images);
347347

348-
$handler = $handler ?: $config->defaultHandler;
348+
$handler = $handler !== null && $handler !== '' && $handler !== '0' ? $handler : $config->defaultHandler;
349349
$class = $config->handlers[$handler];
350350

351351
return new $class($config);
@@ -385,7 +385,7 @@ public static function language(?string $locale = null, bool $getShared = true)
385385
}
386386

387387
// Use '?:' for empty string check
388-
$locale = $locale ?: $requestLocale;
388+
$locale = $locale !== null && $locale !== '' && $locale !== '0' ? $locale : $requestLocale;
389389

390390
return new Language($locale);
391391
}
@@ -484,7 +484,7 @@ public static function parser(?string $viewPath = null, ?ViewConfig $config = nu
484484
return static::getSharedInstance('parser', $viewPath, $config);
485485
}
486486

487-
$viewPath = $viewPath ?: (new Paths())->viewDirectory;
487+
$viewPath = $viewPath !== null && $viewPath !== '' && $viewPath !== '0' ? $viewPath : (new Paths())->viewDirectory;
488488
$config ??= config(ViewConfig::class);
489489

490490
return new Parser($config, $viewPath, AppServices::get('locator'), CI_DEBUG, AppServices::get('logger'));
@@ -503,7 +503,7 @@ public static function renderer(?string $viewPath = null, ?ViewConfig $config =
503503
return static::getSharedInstance('renderer', $viewPath, $config);
504504
}
505505

506-
$viewPath = $viewPath ?: (new Paths())->viewDirectory;
506+
$viewPath = $viewPath !== null && $viewPath !== '' && $viewPath !== '0' ? $viewPath : (new Paths())->viewDirectory;
507507
$config ??= config(ViewConfig::class);
508508

509509
return new View($config, $viewPath, AppServices::get('locator'), CI_DEBUG, AppServices::get('logger'));

0 commit comments

Comments
 (0)