Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.6
Browse files Browse the repository at this point in the history
 Conflicts:
	system/Filters/Filters.php
  • Loading branch information
kenjis committed Jun 30, 2024
2 parents 3dffbc9 + 1638990 commit dc9adb1
Show file tree
Hide file tree
Showing 30 changed files with 192 additions and 112 deletions.
4 changes: 2 additions & 2 deletions app/Config/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Events::on('create', [$myInstance, 'myMethod']);
*/

Events::on('pre_system', static function () {
Events::on('pre_system', static function (): void {
if (ENVIRONMENT !== 'testing') {
if (ini_get('zlib.output_compression')) {
throw FrameworkException::forEnabledZlibOutputCompression();
Expand All @@ -47,7 +47,7 @@
Services::toolbar()->respond();
// Hot Reload route - for framework use on the hot reloader.
if (ENVIRONMENT === 'development') {
Services::routes()->get('__hot-reload', static function () {
Services::routes()->get('__hot-reload', static function (): void {
(new HotReloader())->run();
});
}
Expand Down
130 changes: 61 additions & 69 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,44 @@
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
SetList::DEAD_CODE,
LevelSetList::UP_TO_PHP_81,
return RectorConfig::configure()
->withPhpSets(php81: true)
->withPreparedSets(deadCode: true)
->withSets([
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_100,
]);

$rectorConfig->parallel(120, 8, 10);

// Github action cache
$rectorConfig->cacheClass(FileCacheStorage::class);
if (is_dir('/tmp')) {
$rectorConfig->cacheDirectory('/tmp/rector');
}

])
->withParallel(120, 8, 10)
->withCache(
// Github action cache or local
is_dir('/tmp') ? '/tmp/rector' : null,
FileCacheStorage::class
)
// paths to refactor; solid alternative to CLI arguments
$rectorConfig->paths([__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils']);

->withPaths(
[__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils']
)
// do you need to include constants, class aliases or custom autoloader? files listed will be executed
$rectorConfig->bootstrapFiles([
->withBootstrapFiles([
__DIR__ . '/system/Test/bootstrap.php',
]);

$rectorConfig->phpstanConfigs([
])
->withPHPStanConfigs([
__DIR__ . '/phpstan.neon.dist',
__DIR__ . '/vendor/codeigniter/phpstan-codeigniter/extension.neon',
__DIR__ . '/vendor/phpstan/phpstan-strict-rules/rules.neon',
]);

])
// is there a file you need to skip?
$rectorConfig->skip([
->withSkip([
__DIR__ . '/system/Debug/Toolbar/Views/toolbar.tpl.php',
__DIR__ . '/system/ThirdParty',
__DIR__ . '/tests/system/Config/fixtures',
Expand Down Expand Up @@ -187,48 +182,45 @@
AnnotationWithValueToAttributeRector::class,
AnnotationToAttributeRector::class,
CoversAnnotationWithValueToAttributeRector::class,
]);

])
// auto import fully qualified class names
$rectorConfig->importNames();
$rectorConfig->removeUnusedImports();

$rectorConfig->rule(DeclareStrictTypesRector::class);
$rectorConfig->rule(UnderscoreToCamelCaseVariableNameRector::class);
$rectorConfig->rule(SimplifyUselessVariableRector::class);
$rectorConfig->rule(RemoveAlwaysElseRector::class);
$rectorConfig->rule(PassStrictParameterToFunctionParameterRector::class);
$rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);
$rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class);
$rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class);
$rectorConfig->rule(SimplifyStrposLowerRector::class);
$rectorConfig->rule(CombineIfRector::class);
$rectorConfig->rule(SimplifyIfReturnBoolRector::class);
$rectorConfig->rule(InlineIfToExplicitIfRector::class);
$rectorConfig->rule(PreparedValueToEarlyReturnRector::class);
$rectorConfig->rule(ShortenElseIfRector::class);
$rectorConfig->rule(SimplifyIfElseToTernaryRector::class);
$rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class);
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
$rectorConfig->rule(RemoveErrorSuppressInTryCatchStmtsRector::class);
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
$rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class);
$rectorConfig->rule(TernaryEmptyArrayArrayDimFetchToCoalesceRector::class);
$rectorConfig->rule(EmptyOnNullableObjectToInstanceOfRector::class);
$rectorConfig->rule(DisallowedEmptyRuleFixerRector::class);
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
$rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class);
$rectorConfig->rule(SingleInArrayToCompareRector::class);
$rectorConfig->rule(VersionCompareFuncCallToConstantRector::class);
$rectorConfig->rule(ExplicitBoolCompareRector::class);

$rectorConfig
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
// keep '\\' prefix string on string '\Foo\Bar'
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
]);
};
->withImportNames(removeUnusedImports: true)
->withRules([
DeclareStrictTypesRector::class,
UnderscoreToCamelCaseVariableNameRector::class,
SimplifyUselessVariableRector::class,
RemoveAlwaysElseRector::class,
PassStrictParameterToFunctionParameterRector::class,
CountArrayToEmptyArrayComparisonRector::class,
ChangeNestedForeachIfsToEarlyContinueRector::class,
ChangeIfElseValueAssignToEarlyReturnRector::class,
SimplifyStrposLowerRector::class,
CombineIfRector::class,
SimplifyIfReturnBoolRector::class,
InlineIfToExplicitIfRector::class,
PreparedValueToEarlyReturnRector::class,
ShortenElseIfRector::class,
SimplifyIfElseToTernaryRector::class,
UnusedForeachValueToArrayKeysRector::class,
ChangeArrayPushToArrayAssignRector::class,
UnnecessaryTernaryExpressionRector::class,
RemoveErrorSuppressInTryCatchStmtsRector::class,
FuncGetArgsToVariadicParamRector::class,
MakeInheritedMethodVisibilitySameAsParentRector::class,
SimplifyEmptyArrayCheckRector::class,
SimplifyEmptyCheckOnEmptyArrayRector::class,
TernaryEmptyArrayArrayDimFetchToCoalesceRector::class,
EmptyOnNullableObjectToInstanceOfRector::class,
DisallowedEmptyRuleFixerRector::class,
PrivatizeFinalClassPropertyRector::class,
CompleteDynamicPropertiesRector::class,
BooleanInIfConditionRuleFixerRector::class,
SingleInArrayToCompareRector::class,
VersionCompareFuncCallToConstantRector::class,
ExplicitBoolCompareRector::class,
AddClosureVoidReturnTypeWhereNoReturnRector::class,
])
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
// keep '\\' prefix string on string '\Foo\Bar'
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
]);
2 changes: 1 addition & 1 deletion system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ private function autoloadKint(): void
{
// If we have KINT_DIR it means it's already loaded via composer
if (! defined('KINT_DIR')) {
spl_autoload_register(function ($class) {
spl_autoload_register(function ($class): void {
$class = explode('\\', $class);

if (array_shift($class) !== 'Kint') {
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function showHelp()
if ($this->arguments !== []) {
CLI::newLine();
CLI::write(lang('CLI.helpArguments'), 'yellow');
$length = max(array_map('strlen', array_keys($this->arguments)));
$length = max(array_map(strlen(...), array_keys($this->arguments)));

foreach ($this->arguments as $argument => $description) {
CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description);
Expand All @@ -173,7 +173,7 @@ public function showHelp()
if ($this->options !== []) {
CLI::newLine();
CLI::write(lang('CLI.helpOptions'), 'yellow');
$length = max(array_map('strlen', array_keys($this->options)));
$length = max(array_map(strlen(...), array_keys($this->options)));

foreach ($this->options as $option => $description) {
CLI::write(CLI::color($this->setPad($option, $length, 2, 2), 'green') . $description);
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private static function isZeroOptions(array $options): void
private static function printKeysAndValues(array $options): void
{
// +2 for the square brackets around the key
$keyMaxLength = max(array_map('mb_strwidth', array_keys($options))) + 2;
$keyMaxLength = max(array_map(mb_strwidth(...), array_keys($options))) + 2;

foreach ($options as $key => $description) {
$name = str_pad(' [' . $key . '] ', $keyMaxLength + 4, ' ');
Expand Down Expand Up @@ -857,7 +857,7 @@ public static function wrap(?string $string = null, int $max = 0, int $padLeft =

$first = true;

array_walk($lines, static function (&$line) use ($padLeft, &$first) {
array_walk($lines, static function (&$line) use ($padLeft, &$first): void {
if (! $first) {
$line = str_repeat(' ', $padLeft) . $line;
} else {
Expand Down
2 changes: 1 addition & 1 deletion system/CLI/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private function normalizeInputClassName(): string
implode(
'\\',
array_map(
'pascalize',
pascalize(...),
explode('\\', str_replace('/', '\\', trim($class)))
)
),
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private function autoloadKint(): void
{
// If we have KINT_DIR it means it's already loaded via composer
if (! defined('KINT_DIR')) {
spl_autoload_register(function ($class) {
spl_autoload_register(function ($class): void {
$class = explode('\\', $class);

if (array_shift($class) !== 'Kint') {
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function listFull(array $commands)
$groups[$command['group']][$title] = $command;
}

$length = max(array_map('strlen', array_keys($commands)));
$length = max(array_map(strlen(...), array_keys($commands)));

ksort($groups);

Expand Down
8 changes: 4 additions & 4 deletions system/Commands/Utilities/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public function run(array $params)
$route['route'],
$routeName,
$route['handler'],
implode(' ', array_map('class_basename', $filters['before'])),
implode(' ', array_map('class_basename', $filters['after'])),
implode(' ', array_map(class_basename(...), $filters['before'])),
implode(' ', array_map(class_basename(...), $filters['after'])),
];
}

Expand Down Expand Up @@ -166,8 +166,8 @@ public function run(array $params)
// There is no `AUTO` method, but it is intentional not to get route filters.
$filters = $filterCollector->get('AUTO', $uriGenerator->get($routes[1]));

$routes[] = implode(' ', array_map('class_basename', $filters['before']));
$routes[] = implode(' ', array_map('class_basename', $filters['after']));
$routes[] = implode(' ', array_map(class_basename(...), $filters['before']));
$routes[] = implode(' ', array_map(class_basename(...), $filters['after']));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ private function addFilters($routes)
$filters['before'] = array_intersect($filtersLongest['before'], $filtersShortest['before']);
$filters['after'] = array_intersect($filtersLongest['after'], $filtersShortest['after']);

$route['before'] = implode(' ', array_map('class_basename', $filters['before']));
$route['after'] = implode(' ', array_map('class_basename', $filters['after']));
$route['before'] = implode(' ', array_map(class_basename(...), $filters['before']));
$route['after'] = implode(' ', array_map(class_basename(...), $filters['after']));
}

return $routes;
Expand Down
2 changes: 1 addition & 1 deletion system/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function getPrefixedName(): string
$name .= $this->getName();
} else {
$search = str_split(self::$reservedCharsList);
$replace = array_map('rawurlencode', $search);
$replace = array_map(rawurlencode(...), $search);

$name .= str_replace($search, $replace, $this->getName());
}
Expand Down
2 changes: 1 addition & 1 deletion system/DataCaster/DataCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function castAs(mixed $value, string $field, string $method = 'get'): mix
// type[param, param2,param3]
if (preg_match('/\A(.+)\[(.+)\]\z/', $type, $matches)) {
$type = $matches[1];
$params = array_map('trim', explode(',', $matches[2]));
$params = array_map(trim(...), explode(',', $matches[2]));
}

if ($isNullable && ! $this->strict) {
Expand Down
2 changes: 1 addition & 1 deletion system/DataConverter/DataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function reconstruct(string $classname, array $row): object
return $classObj;
}

$classSet = Closure::bind(function ($key, $value) {
$classSet = Closure::bind(function ($key, $value): void {
$this->{$key} = $value;
}, $classObj, $classname);

Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ public function tableExists(string $tableName, bool $cached = true): bool
if (! empty($this->dataCache['table_names'])) {
$key = array_search(
strtolower($tableName),
array_map('strtolower', $this->dataCache['table_names']),
array_map(strtolower(...), $this->dataCache['table_names']),
true
);

Expand Down
6 changes: 3 additions & 3 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function dropDatabase(string $dbName): bool
if (! empty($this->db->dataCache['db_names'])) {
$key = array_search(
strtolower($dbName),
array_map('strtolower', $this->db->dataCache['db_names']),
array_map(strtolower(...), $this->db->dataCache['db_names']),
true
);
if ($key !== false) {
Expand Down Expand Up @@ -667,7 +667,7 @@ public function dropTable(string $tableName, bool $ifExists = false, bool $casca
if ($query && ! empty($this->db->dataCache['table_names'])) {
$key = array_search(
strtolower($this->db->DBPrefix . $tableName),
array_map('strtolower', $this->db->dataCache['table_names']),
array_map(strtolower(...), $this->db->dataCache['table_names']),
true
);

Expand Down Expand Up @@ -729,7 +729,7 @@ public function renameTable(string $tableName, string $newTableName)
if ($result && ! empty($this->db->dataCache['table_names'])) {
$key = array_search(
strtolower($this->db->DBPrefix . $tableName),
array_map('strtolower', $this->db->dataCache['table_names']),
array_map(strtolower(...), $this->db->dataCache['table_names']),
true
);

Expand Down
2 changes: 1 addition & 1 deletion system/Database/MigrationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public function getBatches(): array
->get()
->getResultArray();

return array_map('intval', array_column($batches, 'batch'));
return array_map(intval(...), array_column($batches, 'batch'));
}

/**
Expand Down
22 changes: 18 additions & 4 deletions system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,24 @@ class Connection extends BaseConnection
];

protected $validDSNs = [
'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS
// Easy Connect string (Oracle 10g+)
'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i',
'in' => '/^[a-z0-9$_]+$/i', // Instance name (defined in tnsnames.ora)
// TNS
'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/',
// Easy Connect string (Oracle 10g+).
// https://docs.oracle.com/en/database/oracle/oracle-database/23/netag/configuring-naming-methods.html#GUID-36F3A17D-843C-490A-8A23-FB0FE005F8E8
// [//]host[:port][/[service_name][:server_type][/instance_name]]
'ec' => '/^
(\/\/)?
(\[)?[a-z0-9.:_-]+(\])? # Host or IP address
(:[1-9][0-9]{0,4})? # Port
(
(\/)
([a-z0-9.$_]+)? # Service name
(:[a-z]+)? # Server type
(\/[a-z0-9$_]+)? # Instance name
)?
$/ix',
// Instance name (defined in tnsnames.ora)
'in' => '/^[a-z0-9$_]+$/i',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/OCI8/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected function _processColumn(array $processedField): string
$constraint = ' CHECK(' . $this->db->escapeIdentifiers($processedField['name'])
. ' IN ' . $processedField['length'] . ')';

$processedField['length'] = '(' . max(array_map('mb_strlen', explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
$processedField['length'] = '(' . max(array_map(mb_strlen(...), explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
} elseif (isset($this->primaryKeys['fields']) && count($this->primaryKeys['fields']) === 1 && $processedField['name'] === $this->primaryKeys['fields'][0]) {
$processedField['unique'] = '';
}
Expand Down
Loading

0 comments on commit dc9adb1

Please sign in to comment.