Skip to content

Commit

Permalink
Update phpstan-codeigniter and fix new errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Oct 20, 2023
1 parent cf43310 commit e2ed1c0
Show file tree
Hide file tree
Showing 56 changed files with 112 additions and 180 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"require-dev": {
"codeigniter/coding-standard": "^1.5",
"codeigniter/phpstan-codeigniter": "^v1.1",
"codeigniter/phpstan-codeigniter": "^1.1",
"ergebnis/composer-normalize": "^2.28",
"fakerphp/faker": "^1.9",
"kint-php/kint": "^5.0.4",
Expand Down
30 changes: 5 additions & 25 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
'count' => 1,
'path' => __DIR__ . '/system/Cache/Handlers/PredisHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Call to function config with Config\\\\Kint\\:\\:class is discouraged\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/CodeIgniter.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 6,
Expand Down Expand Up @@ -871,16 +876,6 @@
'count' => 4,
'path' => __DIR__ . '/system/Config/BaseConfig.php',
];
$ignoreErrors[] = [
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Config/BaseConfig.php',
];
$ignoreErrors[] = [
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
'count' => 2,
'path' => __DIR__ . '/system/Config/BaseService.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 3,
Expand Down Expand Up @@ -931,11 +926,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Config/Services.php',
];
$ignoreErrors[] = [
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Config/Services.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
Expand Down Expand Up @@ -2011,11 +2001,6 @@
'count' => 4,
'path' => __DIR__ . '/system/Entity/Entity.php',
];
$ignoreErrors[] = [
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Events/Events.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Events\\\\Events\\:\\:on\\(\\) has parameter \\$callback with no signature specified for callable\\.$#',
'count' => 1,
Expand Down Expand Up @@ -2056,11 +2041,6 @@
'count' => 3,
'path' => __DIR__ . '/system/Files/File.php',
];
$ignoreErrors[] = [
'message' => '#^Argument \\#1 \\$name \\(\'Config\\\\\\\\Modules\'\\) passed to function config does not extend CodeIgniter\\\\\\\\Config\\\\\\\\BaseConfig\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Filters/Filters.php',
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 2,
Expand Down
8 changes: 3 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ parameters:
checkGenericClassInNonGenericObjectType: false
checkMissingCallableSignature: true
treatPhpDocTypesAsCertain: false
codeigniter:
additionalConfigNamespaces:
- CodeIgniter\Config
strictRules:
allRules: false
disallowedLooseComparison: true
booleansInConditions: true
disallowedConstructs: true
matchingInheritedMethodNames: true
ignoreErrors:
- '#^Call to function config with Config\\.+\:\:class is discouraged\.$#'
codeigniter:
additionalConfigNamespaces:
- CodeIgniter\Config\
3 changes: 1 addition & 2 deletions system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace CodeIgniter\CLI;

use Config\Exceptions;
use Psr\Log\LoggerInterface;
use ReflectionException;
use Throwable;
Expand Down Expand Up @@ -124,7 +123,7 @@ protected function showError(Throwable $e)
{
$exception = $e;
$message = $e->getMessage();
$config = config(Exceptions::class);
$config = config('Exceptions');

require $config->errorViewPath . '/cli/error_exception.php';
}
Expand Down
3 changes: 1 addition & 2 deletions system/CLI/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace CodeIgniter\CLI;

use CodeIgniter\CodeIgniter;
use Config\App;
use Config\Services;
use Exception;

Expand All @@ -33,7 +32,7 @@ class Console
public function run()
{
// Create CLIRequest
$appConfig = config(App::class);
$appConfig = config('App');
Services::createRequest($appConfig, true);
// Load Routes
Services::routes()->loadRoutes();
Expand Down
3 changes: 1 addition & 2 deletions system/CLI/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace CodeIgniter\CLI;

use Config\Generators;
use Config\Services;
use Throwable;

Expand Down Expand Up @@ -268,7 +267,7 @@ protected function qualifyClassName(): string
protected function renderTemplate(array $data = []): string
{
try {
return view(config(Generators::class)->views[$this->name], $data, ['debug' => false]);
return view(config('Generators')->views[$this->name], $data, ['debug' => false]);
} catch (Throwable $e) {
log_message('error', (string) $e);

Expand Down
3 changes: 1 addition & 2 deletions system/Cache/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Closure;
use CodeIgniter\Cache\CacheInterface;
use Config\Cache;
use Exception;
use InvalidArgumentException;

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

$reserved = config(Cache::class)->reservedCharacters ?? self::RESERVED_CHARACTERS;
$reserved = config('Cache')->reservedCharacters ?? self::RESERVED_CHARACTERS;
if ($reserved && strpbrk($key, $reserved) !== false) {
throw new InvalidArgumentException('Cache key contains reserved characters ' . $reserved);
}
Expand Down
11 changes: 5 additions & 6 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
use CodeIgniter\Router\Router;
use Config\App;
use Config\Cache;
use Config\Feature;
use Config\Kint as KintConfig;
use Config\Services;
use Exception;
use Kint;
use Kint\Kint;
use Kint\Renderer\CliRenderer;
use Kint\Renderer\RichRenderer;
use Locale;
Expand Down Expand Up @@ -358,7 +357,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
$this->spoofRequestMethod();

try {
$this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
$this->response = $this->handleRequest($routes, config('Cache'), $returnResponse);
} catch (ResponsableInterface|DeprecatedRedirectException $e) {
$this->outputBufferingEnd();
if ($e instanceof DeprecatedRedirectException) {
Expand Down Expand Up @@ -458,7 +457,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
// If any filters were specified within the routes file,
// we need to ensure it's active for the current request
if ($routeFilter !== null) {
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
$multipleFiltersEnabled = config('Feature')->multipleFilters ?? false;
if ($multipleFiltersEnabled) {
$filters->enableFilters($routeFilter, 'before');
$filters->enableFilters($routeFilter, 'after');
Expand Down Expand Up @@ -832,7 +831,7 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
$this->benchmark->stop('routing');

// for backward compatibility
$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
$multipleFiltersEnabled = config('Feature')->multipleFilters ?? false;
if (! $multipleFiltersEnabled) {
return $this->router->getFilter();
}
Expand Down Expand Up @@ -973,7 +972,7 @@ protected function display404errors(PageNotFoundException $e)

unset($override);

$cacheConfig = config(Cache::class);
$cacheConfig = config('Cache');
$this->gatherOutput($cacheConfig, $returned);

return $this->response;
Expand Down
3 changes: 1 addition & 2 deletions system/Commands/Cache/ClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use CodeIgniter\Cache\CacheFactory;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Cache;

/**
* Clears current cache.
Expand Down Expand Up @@ -63,7 +62,7 @@ class ClearCache extends BaseCommand
*/
public function run(array $params)
{
$config = config(Cache::class);
$config = config('Cache');
$handler = $params[0] ?? $config->handler;

if (! array_key_exists($handler, $config->validHandlers)) {
Expand Down
3 changes: 1 addition & 2 deletions system/Commands/Cache/InfoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\I18n\Time;
use Config\Cache;

/**
* Shows information on the cache.
Expand Down Expand Up @@ -55,7 +54,7 @@ class InfoCache extends BaseCommand
*/
public function run(array $params)
{
$config = config(Cache::class);
$config = config('Cache');
helper('number');

if ($config->handler !== 'file') {
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function run(array $params)
}

try {
$config = config(Database::class);
$config = config('Database');

// Set to an empty database to prevent connection errors.
$group = ENVIRONMENT === 'testing' ? 'tests' : $config->defaultGroup;
Expand Down
10 changes: 3 additions & 7 deletions system/Commands/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
use Config\Database;
use Config\Migrations;
use Config\Session as SessionConfig;

/**
* Generates a skeleton migration file.
Expand Down Expand Up @@ -108,10 +105,9 @@ protected function prepare(string $class): string
$data['session'] = true;
$data['table'] = is_string($table) ? $table : 'ci_sessions';
$data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default';
$data['DBDriver'] = config(Database::class)->{$data['DBGroup']}['DBDriver'];
$data['DBDriver'] = config('Database')->{$data['DBGroup']}['DBDriver'];

/** @var SessionConfig|null $session */
$session = config(SessionConfig::class);
$session = config('Session');

$data['matchIP'] = $session->matchIP;
}
Expand All @@ -124,6 +120,6 @@ protected function prepare(string $class): string
*/
protected function basename(string $filename): string
{
return gmdate(config(Migrations::class)->timestampFormat) . basename($filename);
return gmdate(config('Migrations')->timestampFormat) . basename($filename);
}
}
6 changes: 2 additions & 4 deletions system/Commands/Generators/SessionMigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CLI\GeneratorTrait;
use Config\App;
use Config\Migrations;

/**
* Generates a migration file for database sessions.
Expand Down Expand Up @@ -95,7 +93,7 @@ protected function prepare(string $class): string
$data['session'] = true;
$data['table'] = $this->getOption('t');
$data['DBGroup'] = $this->getOption('g');
$data['matchIP'] = config(App::class)->sessionMatchIP ?? false;
$data['matchIP'] = config('App')->sessionMatchIP ?? false;

$data['table'] = is_string($data['table']) ? $data['table'] : 'ci_sessions';
$data['DBGroup'] = is_string($data['DBGroup']) ? $data['DBGroup'] : 'default';
Expand All @@ -108,6 +106,6 @@ protected function prepare(string $class): string
*/
protected function basename(string $filename): string
{
return gmdate(config(Migrations::class)->timestampFormat) . basename($filename);
return gmdate(config('Migrations')->timestampFormat) . basename($filename);
}
}
6 changes: 2 additions & 4 deletions system/Commands/Utilities/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use CodeIgniter\Commands\Utilities\Routes\FilterCollector;
use CodeIgniter\Commands\Utilities\Routes\SampleURIGenerator;
use CodeIgniter\Router\DefinedRouteCollector;
use Config\Feature;
use Config\Routing;
use Config\Services;

/**
Expand Down Expand Up @@ -134,7 +132,7 @@ public function run(array $params)
}

if ($collection->shouldAutoRoute()) {
$autoRoutesImproved = config(Feature::class)->autoRoutesImproved ?? false;
$autoRoutesImproved = config('Feature')->autoRoutesImproved ?? false;

if ($autoRoutesImproved) {
$autoRouteCollector = new AutoRouteCollectorImproved(
Expand All @@ -148,7 +146,7 @@ public function run(array $params)
$autoRoutes = $autoRouteCollector->get();

// Check for Module Routes.
if ($routingConfig = config(Routing::class)) {
if ($routingConfig = config('Routing')) {
foreach ($routingConfig->moduleRoutes as $uri => $namespace) {
$autoRouteCollector = new AutoRouteCollectorImproved(
$namespace,
Expand Down
3 changes: 1 addition & 2 deletions system/Commands/Utilities/Routes/FilterCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use CodeIgniter\Filters\Filters;
use CodeIgniter\HTTP\Request;
use CodeIgniter\Router\Router;
use Config\Filters as FiltersConfig;

/**
* Collects filters for a route.
Expand Down Expand Up @@ -75,7 +74,7 @@ private function createRouter(Request $request): Router

private function createFilters(Request $request): Filters
{
$config = config(FiltersConfig::class);
$config = config('Filters');

return new Filters($config, $request, Services::response());
}
Expand Down
3 changes: 1 addition & 2 deletions system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use CodeIgniter\Filters\Filters;
use CodeIgniter\HTTP\Exceptions\RedirectException;
use CodeIgniter\Router\Router;
use Config\Feature;
use Config\Services;

/**
Expand All @@ -38,7 +37,7 @@ private function getRouteFilters(string $uri): array
{
$this->router->handle($uri);

$multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
$multipleFiltersEnabled = config('Feature')->multipleFilters ?? false;
if (! $multipleFiltersEnabled) {
$filter = $this->router->getFilter();

Expand Down
Loading

0 comments on commit e2ed1c0

Please sign in to comment.