Skip to content

Commit

Permalink
Merge branch 'develop' into 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Dec 28, 2024
2 parents 22b8e9e + ee4ee98 commit c7548a3
Show file tree
Hide file tree
Showing 96 changed files with 314 additions and 584 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'_support/View/Cells/multiplier.php',
'_support/View/Cells/colors.php',
'_support/View/Cells/addition.php',
'system/Database/Live/PreparedQueryTest.php',
])
->notName('#Foobar.php$#');

Expand Down
2 changes: 1 addition & 1 deletion app/Views/errors/cli/error_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

$args = implode(', ', array_map(static fn ($value) => match (true) {
is_object($value) => 'Object(' . $value::class . ')',
is_array($value) => count($value) ? '[...]' : '[]',
is_array($value) => $value !== [] ? '[...]' : '[]',
$value === null => 'null', // return the lowercased version
default => var_export($value, true),
}, array_values($error['args'] ?? [])));
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"phpunit/phpcov": "^9.0.2 || ^10.0",
"phpunit/phpunit": "^10.5.16 || ^11.2",
"predis/predis": "^1.1 || ^2.3",
"rector/rector": "2.0.3",
"rector/rector": "2.0.4",
"shipmonk/phpstan-baseline-per-identifier": "^2.0"
},
"replace": {
Expand Down
8 changes: 2 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
Expand All @@ -55,11 +54,8 @@

return RectorConfig::configure()
->withPhpSets(php81: true)
->withPreparedSets(deadCode: true)
->withSets([
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_100,
])
->withPreparedSets(deadCode: true, instanceOf: true, strictBooleans: true, phpunitCodeQuality: true)
->withComposerBased(phpunit: true)
->withParallel(120, 8, 10)
->withCache(
// Github action cache or local
Expand Down
6 changes: 3 additions & 3 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public function findColumn(string $columnName)

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

return $resultSet ? array_column($resultSet, $columnName) : null;
return $resultSet !== null ? array_column($resultSet, $columnName) : null;
}

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

if ($id && (is_numeric($id) || is_string($id))) {
if (! in_array($id, [null, 0, '0'], true) && (is_numeric($id) || is_string($id))) {
$id = [$id];
}

Expand Down Expand Up @@ -1250,7 +1250,7 @@ public function errors(bool $forceDB = false)
}

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

Expand Down
22 changes: 11 additions & 11 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ public static function prompt(string $field, $options = null, $validation = null
$extraOutput = '';
$default = '';

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

if (! is_array($validation)) {
$validation = $validation ? explode('|', $validation) : [];
$validation = ($validation !== null) ? explode('|', $validation) : [];
}

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

Expand Down Expand Up @@ -441,7 +441,7 @@ protected static function validate(string $field, string $value, $rules): bool
*/
public static function print(string $text = '', ?string $foreground = null, ?string $background = null)
{
if ($foreground || $background) {
if ((string) $foreground !== '' || (string) $background !== '') {
$text = static::color($text, $foreground, $background);
}

Expand All @@ -457,7 +457,7 @@ public static function print(string $text = '', ?string $foreground = null, ?str
*/
public static function write(string $text = '', ?string $foreground = null, ?string $background = null)
{
if ($foreground || $background) {
if ((string) $foreground !== '' || (string) $background !== '') {
$text = static::color($text, $foreground, $background);
}

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

if ($foreground || $background) {
if ($foreground !== '' || (string) $background !== '') {
$text = static::color($text, $foreground, $background);
}

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

if ($background !== null && ! array_key_exists($background, static::$background_colors)) {
if ((string) $background !== '' && ! array_key_exists($background, static::$background_colors)) {
throw CLIException::forInvalidColor('background', $background);
}

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

if ($background !== null) {
if ((string) $background !== '') {
$string .= "\033[" . static::$background_colors[$background] . 'm';
}

Expand All @@ -654,7 +654,7 @@ private static function getColoredText(string $text, string $foreground, ?string
*/
public static function strlen(?string $string): int
{
if ($string === null) {
if ((string) $string === '') {
return 0;
}

Expand Down Expand Up @@ -768,7 +768,7 @@ public static function generateDimensions()

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

Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function validateKey($key, $prefix = ''): string
}

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

Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs
if ($filename !== '.' && $filename !== '..') {
if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.') {
$this->deleteFiles($path . DIRECTORY_SEPARATOR . $filename, $delDir, $htdocs, $_level + 1);
} elseif (! $htdocs || ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) {
} elseif (! $htdocs || preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename) !== 1) {
@unlink($path . DIRECTORY_SEPARATOR . $filename);
}
}
Expand Down
3 changes: 2 additions & 1 deletion system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Exception;
use Predis\Client;
use Predis\Collection\Iterator\Keyspace;
use Predis\Response\Status;

/**
* Predis cache handler
Expand Down Expand Up @@ -121,7 +122,7 @@ public function save(string $key, $value, int $ttl = 60)
return false;
}

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

Expand Down
12 changes: 9 additions & 3 deletions system/Commands/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,24 @@ class ListCommands extends BaseCommand

/**
* Displays the help for the spark cli script itself.
*
* @return int
*/
public function run(array $params)
{
$commands = $this->commands->getCommands();
ksort($commands);

// Check for 'simple' format
return array_key_exists('simple', $params) || CLI::getOption('simple')
return array_key_exists('simple', $params) || CLI::getOption('simple') === true
? $this->listSimple($commands)
: $this->listFull($commands);
}

/**
* Lists the commands with accompanying info.
*
* @return void
* @return int
*/
protected function listFull(array $commands)
{
Expand Down Expand Up @@ -124,17 +126,21 @@ protected function listFull(array $commands)
CLI::newLine();
}
}

return EXIT_SUCCESS;
}

/**
* Lists the commands only.
*
* @return void
* @return int
*/
protected function listSimple(array $commands)
{
foreach (array_keys($commands) as $title) {
CLI::write($title);
}

return EXIT_SUCCESS;
}
}
2 changes: 1 addition & 1 deletion system/Commands/Server/Serve.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function run(array $params)
// to ensure our environment is set and it simulates basic mod_rewrite.
passthru($php . ' -S ' . $host . ':' . $port . ' -t ' . $docroot . ' ' . $rewrite, $status);

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

$this->run($params);
Expand Down
10 changes: 6 additions & 4 deletions system/Commands/Utilities/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function run(array $params)
$host = $params['host'] ?? null;

// Set HTTP_HOST
if ($host) {
if ($host !== null) {
$request = service('request');
$_SERVER = $request->getServer();
$_SERVER['HTTP_HOST'] = $host;
Expand All @@ -96,7 +96,7 @@ public function run(array $params)
$collection = service('routes')->loadRoutes();

// Reset HTTP_HOST
if ($host) {
if ($host !== null) {
unset($_SERVER['HTTP_HOST']);
}

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

// Check for Module Routes.
if ($routingConfig = config(Routing::class)) {
$routingConfig = config(Routing::class);

if ($routingConfig instanceof Routing) {
foreach ($routingConfig->moduleRoutes as $uri => $namespace) {
$autoRouteCollector = new AutoRouteCollectorImproved(
$namespace,
Expand Down Expand Up @@ -188,7 +190,7 @@ public function run(array $params)
usort($tbody, static fn ($handler1, $handler2) => strcmp($handler1[3], $handler2[3]));
}

if ($host) {
if ($host !== null) {
CLI::write('Host: ' . $host);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private function getRouteForDefaultController(
if ($classShortname === $defaultController) {
$pattern = '#' . preg_quote(lcfirst($defaultController), '#') . '\z#';
$routeWithoutController = rtrim(preg_replace($pattern, '', $uriByClass), '/');
$routeWithoutController = $routeWithoutController ?: '/';
$routeWithoutController = $routeWithoutController !== '' && $routeWithoutController !== '0' ? $routeWithoutController : '/';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function getRouteWithoutController(

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

return [[
'route' => $routeWithoutController,
Expand Down
8 changes: 4 additions & 4 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ function esc($data, string $context = 'html', ?string $encoding = null)
$escaper = new Escaper($encoding);
}

if ($encoding && $escaper->getEncoding() !== $encoding) {
if ($encoding !== null && $escaper->getEncoding() !== $encoding) {
$escaper = new Escaper($encoding);
}

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

if ($locale && $locale !== $activeLocale) {
if ((string) $locale !== '' && $locale !== $activeLocale) {
$language->setLocale($locale);
}

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

if ($locale && $locale !== $activeLocale) {
if ((string) $locale !== '' && $locale !== $activeLocale) {
// Reset to active locale
$language->setLocale($activeLocale);
}
Expand Down Expand Up @@ -851,7 +851,7 @@ function redirect(?string $route = null): RedirectResponse
{
$response = service('redirectresponse');

if ($route !== null) {
if ((string) $route !== '') {
return $response->route($route);
}

Expand Down
2 changes: 1 addition & 1 deletion system/Config/DotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function parse(): ?array
*/
protected function setVariable(string $name, string $value = '')
{
if (! getenv($name, true)) {
if (getenv($name, true) === false) {
putenv("{$name}={$value}");
}

Expand Down
8 changes: 4 additions & 4 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public static function image(?string $handler = null, ?Images $config = null, bo
$config ??= config(Images::class);
assert($config instanceof Images);

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

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

// Use '?:' for empty string check
$locale = $locale ?: $requestLocale;
$locale = $locale !== null && $locale !== '' && $locale !== '0' ? $locale : $requestLocale;

return new Language($locale);
}
Expand Down Expand Up @@ -484,7 +484,7 @@ public static function parser(?string $viewPath = null, ?ViewConfig $config = nu
return static::getSharedInstance('parser', $viewPath, $config);
}

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

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

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

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

0 comments on commit c7548a3

Please sign in to comment.