Skip to content

Commit 01ac45a

Browse files
kenjispaulbalandan
authored andcommitted
Update phpstan-codeigniter and fix new errors
2 parents 815b802 + dc84d18 commit 01ac45a

Some content is hidden

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

58 files changed

+125
-176
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"require-dev": {
2121
"codeigniter/coding-standard": "^1.5",
22-
"codeigniter/phpstan-codeigniter": "^v1.1",
22+
"codeigniter/phpstan-codeigniter": "^1.1",
2323
"ergebnis/composer-normalize": "^2.28",
2424
"fakerphp/faker": "^1.9",
2525
"kint-php/kint": "^5.0.4",

phpstan-baseline.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@
221221
'count' => 1,
222222
'path' => __DIR__ . '/system/Cache/Handlers/RedisHandler.php',
223223
];
224+
$ignoreErrors[] = [
225+
'message' => '#^Call to function config with Config\\\\Kint\\:\\:class is discouraged\\.$#',
226+
'count' => 1,
227+
'path' => __DIR__ . '/system/CodeIgniter.php',
228+
];
224229
$ignoreErrors[] = [
225230
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
226231
'count' => 6,
@@ -916,16 +921,6 @@
916921
'count' => 4,
917922
'path' => __DIR__ . '/system/Config/BaseConfig.php',
918923
];
919-
$ignoreErrors[] = [
920-
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
921-
'count' => 1,
922-
'path' => __DIR__ . '/system/Config/BaseConfig.php',
923-
];
924-
$ignoreErrors[] = [
925-
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
926-
'count' => 2,
927-
'path' => __DIR__ . '/system/Config/BaseService.php',
928-
];
929924
$ignoreErrors[] = [
930925
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
931926
'count' => 3,
@@ -981,11 +976,6 @@
981976
'count' => 1,
982977
'path' => __DIR__ . '/system/Config/Services.php',
983978
];
984-
$ignoreErrors[] = [
985-
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
986-
'count' => 1,
987-
'path' => __DIR__ . '/system/Config/Services.php',
988-
];
989979
$ignoreErrors[] = [
990980
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
991981
'count' => 1,
@@ -2086,11 +2076,6 @@
20862076
'count' => 4,
20872077
'path' => __DIR__ . '/system/Entity/Entity.php',
20882078
];
2089-
$ignoreErrors[] = [
2090-
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
2091-
'count' => 1,
2092-
'path' => __DIR__ . '/system/Events/Events.php',
2093-
];
20942079
$ignoreErrors[] = [
20952080
'message' => '#^Method CodeIgniter\\\\Events\\\\Events\\:\\:on\\(\\) has parameter \\$callback with no signature specified for callable\\.$#',
20962081
'count' => 1,
@@ -2131,11 +2116,6 @@
21312116
'count' => 3,
21322117
'path' => __DIR__ . '/system/Files/File.php',
21332118
];
2134-
$ignoreErrors[] = [
2135-
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
2136-
'count' => 1,
2137-
'path' => __DIR__ . '/system/Filters/Filters.php',
2138-
];
21392119
$ignoreErrors[] = [
21402120
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
21412121
'count' => 2,

phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ parameters:
3232
checkGenericClassInNonGenericObjectType: false
3333
checkMissingCallableSignature: true
3434
treatPhpDocTypesAsCertain: false
35+
codeigniter:
36+
additionalConfigNamespaces:
37+
- CodeIgniter\Config
3538
strictRules:
3639
allRules: false
3740
disallowedLooseComparison: true

system/CLI/BaseCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace CodeIgniter\CLI;
1313

14-
use Config\Exceptions;
1514
use Psr\Log\LoggerInterface;
1615
use ReflectionException;
1716
use Throwable;
@@ -124,7 +123,7 @@ protected function showError(Throwable $e)
124123
{
125124
$exception = $e;
126125
$message = $e->getMessage();
127-
$config = config(Exceptions::class);
126+
$config = config('Exceptions');
128127

129128
require $config->errorViewPath . '/cli/error_exception.php';
130129
}

system/CLI/CLI.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ class CLI
4242
* Is the readline library on the system?
4343
*
4444
* @var bool
45+
*
46+
* @deprecated 4.4.2 Should be protected.
47+
* @TODO Fix to camelCase in the next major version.
4548
*/
4649
public static $readline_support = false;
4750

4851
/**
4952
* The message displayed at prompts.
5053
*
5154
* @var string
55+
*
56+
* @deprecated 4.4.2 Should be protected.
57+
* @TODO Fix to camelCase in the next major version.
5258
*/
5359
public static $wait_msg = 'Press any key to continue...';
5460

@@ -63,6 +69,8 @@ class CLI
6369
* Foreground color list
6470
*
6571
* @var array<string, string>
72+
*
73+
* @TODO Fix to camelCase in the next major version.
6674
*/
6775
protected static $foreground_colors = [
6876
'black' => '0;30',
@@ -88,6 +96,8 @@ class CLI
8896
* Background color list
8997
*
9098
* @var array<string, string>
99+
*
100+
* @TODO Fix to camelCase in the next major version.
91101
*/
92102
protected static $background_colors = [
93103
'black' => '40',

system/CLI/Console.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace CodeIgniter\CLI;
1313

1414
use CodeIgniter\CodeIgniter;
15-
use Config\App;
1615
use Config\Services;
1716
use Exception;
1817

@@ -33,7 +32,7 @@ class Console
3332
public function run()
3433
{
3534
// Create CLIRequest
36-
$appConfig = config(App::class);
35+
$appConfig = config('App');
3736
Services::createRequest($appConfig, true);
3837

3938
$runner = Services::commands();

system/CLI/GeneratorTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace CodeIgniter\CLI;
1313

14-
use Config\Generators;
1514
use Config\Services;
1615
use Throwable;
1716

@@ -268,7 +267,7 @@ protected function qualifyClassName(): string
268267
protected function renderTemplate(array $data = []): string
269268
{
270269
try {
271-
return view(config(Generators::class)->views[$this->name], $data, ['debug' => false]);
270+
return view(config('Generators')->views[$this->name], $data, ['debug' => false]);
272271
} catch (Throwable $e) {
273272
log_message('error', (string) $e);
274273

system/Cache/Handlers/BaseHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Closure;
1515
use CodeIgniter\Cache\CacheInterface;
16-
use Config\Cache;
1716
use Exception;
1817
use InvalidArgumentException;
1918

@@ -64,7 +63,7 @@ public static function validateKey($key, $prefix = ''): string
6463
throw new InvalidArgumentException('Cache key cannot be empty.');
6564
}
6665

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

system/CodeIgniter.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
use CodeIgniter\Router\Router;
3232
use Config\App;
3333
use Config\Cache;
34-
use Config\Feature;
3534
use Config\Kint as KintConfig;
3635
use Config\Services;
3736
use Exception;
38-
use Kint;
37+
use Kint\Kint;
3938
use Kint\Renderer\CliRenderer;
4039
use Kint\Renderer\RichRenderer;
4140
use Locale;
@@ -358,7 +357,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
358357
$this->spoofRequestMethod();
359358

360359
try {
361-
$this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
360+
$this->response = $this->handleRequest($routes, config('Cache'), $returnResponse);
362361
} catch (ResponsableInterface|DeprecatedRedirectException $e) {
363362
$this->outputBufferingEnd();
364363
if ($e instanceof DeprecatedRedirectException) {
@@ -458,7 +457,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
458457
// If any filters were specified within the routes file,
459458
// we need to ensure it's active for the current request
460459
if ($routeFilter !== null) {
461-
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
460+
$multipleFiltersEnabled = config('Feature')->multipleFilters ?? false;
462461
if ($multipleFiltersEnabled) {
463462
$filters->enableFilters($routeFilter, 'before');
464463
$filters->enableFilters($routeFilter, 'after');
@@ -829,7 +828,7 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
829828
$this->benchmark->stop('routing');
830829

831830
// for backward compatibility
832-
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
831+
$multipleFiltersEnabled = config('Feature')->multipleFilters ?? false;
833832
if (! $multipleFiltersEnabled) {
834833
return $this->router->getFilter();
835834
}
@@ -970,7 +969,7 @@ protected function display404errors(PageNotFoundException $e)
970969

971970
unset($override);
972971

973-
$cacheConfig = config(Cache::class);
972+
$cacheConfig = config('Cache');
974973
$this->gatherOutput($cacheConfig, $returned);
975974

976975
return $this->response;

system/Commands/Cache/ClearCache.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use CodeIgniter\Cache\CacheFactory;
1515
use CodeIgniter\CLI\BaseCommand;
1616
use CodeIgniter\CLI\CLI;
17-
use Config\Cache;
1817

1918
/**
2019
* Clears current cache.
@@ -63,7 +62,7 @@ class ClearCache extends BaseCommand
6362
*/
6463
public function run(array $params)
6564
{
66-
$config = config(Cache::class);
65+
$config = config('Cache');
6766
$handler = $params[0] ?? $config->handler;
6867

6968
if (! array_key_exists($handler, $config->validHandlers)) {

0 commit comments

Comments
 (0)