Skip to content

Commit 3e62428

Browse files
authored
Merge branch 'develop' into develop
2 parents 4fd7ac5 + 116f663 commit 3e62428

62 files changed

Lines changed: 1291 additions & 442 deletions

Some content is hidden

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

.github/workflows/deploy-userguide-latest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
# Create an artifact of the html output
3131
- name: Upload artifact
32-
uses: actions/upload-artifact@v2
32+
uses: actions/upload-artifact@v3
3333
with:
3434
name: HTML Documentation
3535
path: user_guide_src/build/html/

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"mikey179/vfsstream": "^1.6",
2222
"nexusphp/cs-config": "^3.3",
2323
"nexusphp/tachycardia": "^1.0",
24-
"phpstan/phpstan": "^1.0",
24+
"phpstan/phpstan": "^1.5.6",
2525
"phpunit/phpunit": "^9.1",
2626
"predis/predis": "^1.1",
27-
"rector/rector": "0.12.20"
27+
"rector/rector": "0.12.21"
2828
},
2929
"suggest": {
3030
"ext-fileinfo": "Improves mime type detection for files"

env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#--------------------------------------------------------------------
2222

2323
# app.baseURL = ''
24+
# If you have trouble with `.`, you could also use `_`.
25+
# app_baseURL = ''
2426
# app.forceGlobalSecureRequests = false
2527

2628
# app.sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler'

phpstan-baseline.neon.dist

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ parameters:
115115
count: 1
116116
path: system/CodeIgniter.php
117117

118-
-
119-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
120-
count: 1
121-
path: system/CodeIgniter.php
122-
123118
-
124119
message: "#^Binary operation \"\\+\" between array\\<string, class\\-string\\>\\|false and non\\-empty\\-array\\<string, string\\> results in an error\\.$#"
125120
count: 1
@@ -715,14 +710,19 @@ parameters:
715710
count: 1
716711
path: system/Router/Router.php
717712

713+
-
714+
message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getRegisteredControllers\\(\\)\\.$#"
715+
count: 1
716+
path: system/Router/Router.php
717+
718718
-
719719
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
720720
count: 1
721721
path: system/Router/Router.php
722722

723723
-
724724
message: "#^Method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getRoutes\\(\\) invoked with 1 parameter, 0 required\\.$#"
725-
count: 2
725+
count: 1
726726
path: system/Router/Router.php
727727

728728
-

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
conditionalTags:
2+
PhpParser\NodeVisitor\NodeConnectingVisitor:
3+
phpstan.parser.richParserNodeVisitor: true
4+
15
services:
26
-
37
class: Utils\PHPStan\CheckUseStatementsAfterLicenseRule

rector.php

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
1818
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
1919
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
20+
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
2021
use Rector\CodeQuality\Rector\If_\CombineIfRector;
2122
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
2223
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
2324
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
24-
use Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector;
2525
use Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector;
2626
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
2727
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
2828
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
29-
use Rector\Core\Configuration\Option;
29+
use Rector\Config\RectorConfig;
3030
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
3131
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
3232
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
@@ -45,31 +45,31 @@
4545
use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector;
4646
use Rector\Set\ValueObject\LevelSetList;
4747
use Rector\Set\ValueObject\SetList;
48-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
4948
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
5049
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
5150
use Utils\Rector\RemoveVarTagFromClassConstantRector;
5251
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;
5352

54-
return static function (ContainerConfigurator $containerConfigurator): void {
55-
$containerConfigurator->import(SetList::DEAD_CODE);
56-
$containerConfigurator->import(LevelSetList::UP_TO_PHP_74);
57-
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD);
58-
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_80);
53+
return static function (RectorConfig $rectorConfig): void {
54+
$rectorConfig->sets([
55+
SetList::DEAD_CODE,
56+
LevelSetList::UP_TO_PHP_74,
57+
PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD,
58+
PHPUnitSetList::PHPUNIT_80,
59+
]);
5960

60-
$parameters = $containerConfigurator->parameters();
61+
$rectorConfig->parallel();
6162

62-
$parameters->set(Option::PARALLEL, true);
6363
// paths to refactor; solid alternative to CLI arguments
64-
$parameters->set(Option::PATHS, [__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils/Rector']);
64+
$rectorConfig->paths([__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils/Rector']);
6565

6666
// do you need to include constants, class aliases or custom autoloader? files listed will be executed
67-
$parameters->set(Option::BOOTSTRAP_FILES, [
67+
$rectorConfig->bootstrapFiles([
6868
__DIR__ . '/system/Test/bootstrap.php',
6969
]);
7070

7171
// is there a file you need to skip?
72-
$parameters->set(Option::SKIP, [
72+
$rectorConfig->skip([
7373
__DIR__ . '/app/Views',
7474
__DIR__ . '/system/Debug/Toolbar/Views/toolbar.tpl.php',
7575
__DIR__ . '/system/ThirdParty',
@@ -124,42 +124,40 @@
124124
]);
125125

126126
// auto import fully qualified class names
127-
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
128-
129-
$services = $containerConfigurator->services();
130-
$services->set(UnderscoreToCamelCaseVariableNameRector::class);
131-
$services->set(SimplifyUselessVariableRector::class);
132-
$services->set(RemoveAlwaysElseRector::class);
133-
$services->set(PassStrictParameterToFunctionParameterRector::class);
134-
$services->set(CountArrayToEmptyArrayComparisonRector::class);
135-
$services->set(ForToForeachRector::class);
136-
$services->set(ChangeNestedForeachIfsToEarlyContinueRector::class);
137-
$services->set(ChangeIfElseValueAssignToEarlyReturnRector::class);
138-
$services->set(SimplifyStrposLowerRector::class);
139-
$services->set(CombineIfRector::class);
140-
$services->set(SimplifyIfReturnBoolRector::class);
141-
$services->set(InlineIfToExplicitIfRector::class);
142-
$services->set(PreparedValueToEarlyReturnRector::class);
143-
$services->set(ShortenElseIfRector::class);
144-
$services->set(SimplifyIfElseToTernaryRector::class);
145-
$services->set(UnusedForeachValueToArrayKeysRector::class);
146-
$services->set(ChangeArrayPushToArrayAssignRector::class);
147-
$services->set(UnnecessaryTernaryExpressionRector::class);
148-
$services->set(RemoveErrorSuppressInTryCatchStmtsRector::class);
149-
$services->set(RemoveVarTagFromClassConstantRector::class);
150-
$services->set(AddPregQuoteDelimiterRector::class);
151-
$services->set(SimplifyRegexPatternRector::class);
152-
$services->set(FuncGetArgsToVariadicParamRector::class);
153-
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
154-
$services->set(SimplifyEmptyArrayCheckRector::class);
155-
$services->set(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
156-
$services->set(StringClassNameToClassConstantRector::class)
157-
->configure([
158-
'Error',
159-
'Exception',
160-
'InvalidArgumentException',
161-
'Closure',
162-
'stdClass',
163-
'SQLite3',
164-
]);
127+
$rectorConfig->importNames();
128+
129+
$rectorConfig->rule(UnderscoreToCamelCaseVariableNameRector::class);
130+
$rectorConfig->rule(SimplifyUselessVariableRector::class);
131+
$rectorConfig->rule(RemoveAlwaysElseRector::class);
132+
$rectorConfig->rule(PassStrictParameterToFunctionParameterRector::class);
133+
$rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);
134+
$rectorConfig->rule(ForToForeachRector::class);
135+
$rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class);
136+
$rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class);
137+
$rectorConfig->rule(SimplifyStrposLowerRector::class);
138+
$rectorConfig->rule(CombineIfRector::class);
139+
$rectorConfig->rule(SimplifyIfReturnBoolRector::class);
140+
$rectorConfig->rule(InlineIfToExplicitIfRector::class);
141+
$rectorConfig->rule(PreparedValueToEarlyReturnRector::class);
142+
$rectorConfig->rule(ShortenElseIfRector::class);
143+
$rectorConfig->rule(SimplifyIfElseToTernaryRector::class);
144+
$rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class);
145+
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
146+
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
147+
$rectorConfig->rule(RemoveErrorSuppressInTryCatchStmtsRector::class);
148+
$rectorConfig->rule(RemoveVarTagFromClassConstantRector::class);
149+
$rectorConfig->rule(AddPregQuoteDelimiterRector::class);
150+
$rectorConfig->rule(SimplifyRegexPatternRector::class);
151+
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
152+
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
153+
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
154+
$rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
155+
$rectorConfig->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
156+
'Error',
157+
'Exception',
158+
'InvalidArgumentException',
159+
'Closure',
160+
'stdClass',
161+
'SQLite3',
162+
]);
165163
};

system/Autoloader/Autoloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private function loadComposerNamespaces(ClassLoader $composer): void
328328
$newPaths[rtrim($key, '\\ ')] = $value;
329329
}
330330

331-
$this->prefixes = array_merge($this->prefixes, $newPaths);
331+
$this->addNamespace($newPaths);
332332
}
333333

334334
private function loadComposerClassmap(ClassLoader $composer): void

system/CLI/CLI.php

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public static function clearScreen()
469469
*/
470470
public static function color(string $text, string $foreground, ?string $background = null, ?string $format = null): string
471471
{
472-
if (! static::$isColored) {
472+
if (! static::$isColored || $text === '') {
473473
return $text;
474474
}
475475

@@ -481,6 +481,48 @@ public static function color(string $text, string $foreground, ?string $backgrou
481481
throw CLIException::forInvalidColor('background', $background);
482482
}
483483

484+
$newText = '';
485+
486+
// Detect if color method was already in use with this text
487+
if (strpos($text, "\033[0m") !== false) {
488+
$pattern = '/\\033\\[0;.+?\\033\\[0m/u';
489+
490+
preg_match_all($pattern, $text, $matches);
491+
$coloredStrings = $matches[0];
492+
493+
// No colored string found. Invalid strings with no `\033[0;??`.
494+
if ($coloredStrings === []) {
495+
return $newText . self::getColoredText($text, $foreground, $background, $format);
496+
}
497+
498+
$nonColoredText = preg_replace(
499+
$pattern,
500+
'<<__colored_string__>>',
501+
$text
502+
);
503+
$nonColoredChunks = preg_split(
504+
'/<<__colored_string__>>/u',
505+
$nonColoredText
506+
);
507+
508+
foreach ($nonColoredChunks as $i => $chunk) {
509+
if ($chunk !== '') {
510+
$newText .= self::getColoredText($chunk, $foreground, $background, $format);
511+
}
512+
513+
if (isset($coloredStrings[$i])) {
514+
$newText .= $coloredStrings[$i];
515+
}
516+
}
517+
} else {
518+
$newText .= self::getColoredText($text, $foreground, $background, $format);
519+
}
520+
521+
return $newText;
522+
}
523+
524+
private static function getColoredText(string $text, string $foreground, ?string $background, ?string $format): string
525+
{
484526
$string = "\033[" . static::$foreground_colors[$foreground] . 'm';
485527

486528
if ($background !== null) {
@@ -491,30 +533,6 @@ public static function color(string $text, string $foreground, ?string $backgrou
491533
$string .= "\033[4m";
492534
}
493535

494-
// Detect if color method was already in use with this text
495-
if (strpos($text, "\033[0m") !== false) {
496-
// Split the text into parts so that we can see
497-
// if any part missing the color definition
498-
$chunks = mb_split('\\033\\[0m', $text);
499-
// Reset text
500-
$text = '';
501-
502-
foreach ($chunks as $chunk) {
503-
if ($chunk === '') {
504-
continue;
505-
}
506-
507-
// If chunk doesn't have colors defined we need to add them
508-
if (strpos($chunk, "\033[") === false) {
509-
$chunk = static::color($chunk, $foreground, $background, $format);
510-
// Add color reset before chunk and clear end of the string
511-
$text .= rtrim("\033[0m" . $chunk, "\033[0m");
512-
} else {
513-
$text .= $chunk;
514-
}
515-
}
516-
}
517-
518536
return $string . $text . "\033[0m";
519537
}
520538

system/CodeIgniter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CodeIgniter
8080
/**
8181
* Current request.
8282
*
83-
* @var CLIRequest|IncomingRequest|Request
83+
* @var CLIRequest|IncomingRequest|Request|null
8484
*/
8585
protected $request;
8686

@@ -792,6 +792,8 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
792792
/**
793793
* Determines the path to use for us to try to route to, based
794794
* on user input (setPath), or the CLI/IncomingRequest path.
795+
*
796+
* @return string
795797
*/
796798
protected function determinePath()
797799
{

system/Config/AutoloadConfig.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
namespace CodeIgniter\Config;
1313

1414
use Laminas\Escaper\Escaper;
15+
use Laminas\Escaper\Exception\ExceptionInterface;
16+
use Laminas\Escaper\Exception\InvalidArgumentException as EscaperInvalidArgumentException;
17+
use Laminas\Escaper\Exception\RuntimeException;
1518
use Psr\Log\AbstractLogger;
1619
use Psr\Log\InvalidArgumentException;
1720
use Psr\Log\LoggerAwareInterface;
@@ -103,15 +106,18 @@ class AutoloadConfig
103106
* @var array<string, string>
104107
*/
105108
protected $coreClassmap = [
106-
AbstractLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php',
107-
InvalidArgumentException::class => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php',
108-
LoggerAwareInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php',
109-
LoggerAwareTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php',
110-
LoggerInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php',
111-
LoggerTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php',
112-
LogLevel::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php',
113-
NullLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php',
114-
Escaper::class => SYSTEMPATH . 'ThirdParty/Escaper/Escaper.php',
109+
AbstractLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php',
110+
InvalidArgumentException::class => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php',
111+
LoggerAwareInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php',
112+
LoggerAwareTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php',
113+
LoggerInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php',
114+
LoggerTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php',
115+
LogLevel::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php',
116+
NullLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php',
117+
ExceptionInterface::class => SYSTEMPATH . 'ThirdParty/Escaper/Exception/ExceptionInterface.php',
118+
EscaperInvalidArgumentException::class => SYSTEMPATH . 'ThirdParty/Escaper/Exception/InvalidArgumentException.php',
119+
RuntimeException::class => SYSTEMPATH . 'ThirdParty/Escaper/Exception/RuntimeException.php',
120+
Escaper::class => SYSTEMPATH . 'ThirdParty/Escaper/Escaper.php',
115121
];
116122

117123
/**

0 commit comments

Comments
 (0)