Skip to content

Commit fc737a5

Browse files
authored
chore: resolve PHPStan nullCoalesce and isset errors on Config properties (#10081)
* chore: resolve PHPStan nullCoalesce and isset errors on Config properties * fix tests
1 parent 8e46f1f commit fc737a5

File tree

30 files changed

+65
-98
lines changed

30 files changed

+65
-98
lines changed

system/BaseModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ public function findColumn(string $columnName)
653653
*/
654654
public function findAll(?int $limit = null, int $offset = 0)
655655
{
656-
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
656+
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true; // @phpstan-ignore nullCoalesce.property
657657
if ($limitZeroAsAll) {
658658
$limit ??= 0;
659659
}

system/Boot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static function preload(Paths $paths): void
205205
protected static function loadDotEnv(Paths $paths): void
206206
{
207207
require_once $paths->systemDirectory . '/Config/DotEnv.php';
208-
$envDirectory = $paths->envDirectory ?? $paths->appDirectory . '/../';
208+
$envDirectory = $paths->envDirectory ?? $paths->appDirectory . '/../'; // @phpstan-ignore nullCoalesce.property
209209
(new DotEnv($envDirectory))->load();
210210
}
211211

system/Cache/CacheFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,10 @@ class CacheFactory
4949
*/
5050
public static function getHandler(Cache $config, ?string $handler = null, ?string $backup = null)
5151
{
52-
if (! isset($config->validHandlers) || $config->validHandlers === []) {
52+
if ($config->validHandlers === []) {
5353
throw CacheException::forInvalidHandlers();
5454
}
5555

56-
if (! isset($config->handler) || ! isset($config->backupHandler)) {
57-
throw CacheException::forNoBackup();
58-
}
59-
6056
$handler ??= $config->handler;
6157
$backup ??= $config->backupHandler;
6258

system/Cache/Handlers/PredisHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public function __construct(Cache $config)
6565
{
6666
$this->prefix = $config->prefix;
6767

68-
if (isset($config->redis)) {
69-
$this->config = array_merge($this->config, $config->redis);
70-
}
68+
$this->config = array_merge($this->config, $config->redis);
7169
}
7270

7371
public function initialize(): void

system/CodeIgniter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ public function __construct(App $config)
186186
public function initialize()
187187
{
188188
// Set default locale on the server
189-
Locale::setDefault($this->config->defaultLocale ?? 'en');
189+
Locale::setDefault($this->config->defaultLocale);
190190

191191
// Set default timezone on the server
192-
date_default_timezone_set($this->config->appTimezone ?? 'UTC');
192+
date_default_timezone_set($this->config->appTimezone);
193193
}
194194

195195
/**
@@ -452,7 +452,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
452452
if ($routeFilters !== null) {
453453
$filters->enableFilters($routeFilters, 'before');
454454

455-
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
455+
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false; // @phpstan-ignore nullCoalesce.property
456456
if (! $oldFilterOrder) {
457457
$routeFilters = array_reverse($routeFilters);
458458
}
@@ -521,7 +521,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
521521
}
522522

523523
// Execute controller attributes' after() methods AFTER framework filters
524-
if ((config('Routing')->useControllerAttributes ?? true) === true) {
524+
if ((config('Routing')->useControllerAttributes ?? true) === true) { // @phpstan-ignore nullCoalesce.property
525525
$this->benchmark->start('route_attributes_after');
526526
$this->response = $this->router->executeAfterAttributes($this->request, $this->response);
527527
$this->benchmark->stop('route_attributes_after');
@@ -887,7 +887,7 @@ protected function startController()
887887

888888
// Execute route attributes' before() methods
889889
// This runs after routing/validation but BEFORE expensive controller instantiation
890-
if ((config('Routing')->useControllerAttributes ?? true) === true) {
890+
if ((config('Routing')->useControllerAttributes ?? true) === true) { // @phpstan-ignore nullCoalesce.property
891891
$this->benchmark->start('route_attributes_before');
892892
$attributeResponse = $this->router->executeBeforeAttributes($this->request);
893893
$this->benchmark->stop('route_attributes_before');

system/Commands/Encryption/GenerateKey.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function run(array $params)
102102
// force DotEnv to reload the new env vars
103103
putenv('encryption.key');
104104
unset($_ENV['encryption.key'], $_SERVER['encryption.key']);
105-
$dotenv = new DotEnv((new Paths())->envDirectory ?? ROOTPATH);
105+
$dotenv = new DotEnv((new Paths())->envDirectory ?? ROOTPATH); // @phpstan-ignore nullCoalesce.property
106106
$dotenv->load();
107107

108108
CLI::write('Application\'s new encryption key was successfully set.', 'green');
@@ -156,7 +156,7 @@ protected function confirmOverwrite(array $params): bool
156156
protected function writeNewEncryptionKeyToFile(string $oldKey, string $newKey): bool
157157
{
158158
$baseEnv = ROOTPATH . 'env';
159-
$envFile = ((new Paths())->envDirectory ?? ROOTPATH) . '.env';
159+
$envFile = ((new Paths())->envDirectory ?? ROOTPATH) . '.env'; // @phpstan-ignore nullCoalesce.property
160160

161161
if (! is_file($envFile)) {
162162
if (! is_file($baseEnv)) {

system/Commands/Utilities/Environment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function run(array $params)
121121
putenv('CI_ENVIRONMENT');
122122
unset($_ENV['CI_ENVIRONMENT']);
123123
service('superglobals')->unsetServer('CI_ENVIRONMENT');
124-
(new DotEnv((new Paths())->envDirectory ?? ROOTPATH))->load();
124+
(new DotEnv((new Paths())->envDirectory ?? ROOTPATH))->load(); // @phpstan-ignore nullCoalesce.property
125125

126126
CLI::write(sprintf('Environment is successfully changed to "%s".', $env), 'green');
127127
CLI::write('The ENVIRONMENT constant will be changed in the next script execution.');
@@ -136,7 +136,7 @@ public function run(array $params)
136136
private function writeNewEnvironmentToEnvFile(string $newEnv): bool
137137
{
138138
$baseEnv = ROOTPATH . 'env';
139-
$envFile = ((new Paths())->envDirectory ?? ROOTPATH) . '.env';
139+
$envFile = ((new Paths())->envDirectory ?? ROOTPATH) . '.env'; // @phpstan-ignore nullCoalesce.property
140140

141141
if (! is_file($envFile)) {
142142
if (! is_file($baseEnv)) {

system/Commands/Utilities/Routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function run(array $params)
122122
}
123123

124124
if ($collection->shouldAutoRoute()) {
125-
$autoRoutesImproved = config(Feature::class)->autoRoutesImproved ?? false;
125+
$autoRoutesImproved = config(Feature::class)->autoRoutesImproved;
126126

127127
if ($autoRoutesImproved) {
128128
$autoRouteCollector = new AutoRouteCollectorImproved(

system/Commands/Utilities/Routes/FilterFinder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function find(string $uri): array
5656
// Add route filters
5757
$routeFilters = $this->getRouteFilters($uri);
5858
$this->filters->enableFilters($routeFilters, 'before');
59-
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
59+
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false; // @phpstan-ignore nullCoalesce.property
6060
if (! $oldFilterOrder) {
6161
$routeFilters = array_reverse($routeFilters);
6262
}
@@ -91,7 +91,7 @@ public function findClasses(string $uri): array
9191
// Add route filters
9292
$routeFilters = $this->getRouteFilters($uri);
9393
$this->filters->enableFilters($routeFilters, 'before');
94-
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false;
94+
$oldFilterOrder = config(Feature::class)->oldFilterOrder ?? false; // @phpstan-ignore nullCoalesce.property
9595
if (! $oldFilterOrder) {
9696
$routeFilters = array_reverse($routeFilters);
9797
}

system/Database/BaseBuilder.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
15131513
*/
15141514
public function limit(?int $value = null, ?int $offset = 0)
15151515
{
1516-
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
1516+
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true; // @phpstan-ignore nullCoalesce.property
15171517
if ($limitZeroAsAll && $value === 0) {
15181518
$value = null;
15191519
}
@@ -1635,7 +1635,7 @@ protected function compileFinalQuery(string $sql): string
16351635
*/
16361636
public function get(?int $limit = null, int $offset = 0, bool $reset = true)
16371637
{
1638-
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
1638+
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true; // @phpstan-ignore nullCoalesce.property
16391639
if ($limitZeroAsAll && $limit === 0) {
16401640
$limit = null;
16411641
}
@@ -1773,7 +1773,7 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
17731773
$this->where($where);
17741774
}
17751775

1776-
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
1776+
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true; // @phpstan-ignore nullCoalesce.property
17771777
if ($limitZeroAsAll && $limit === 0) {
17781778
$limit = null;
17791779
}
@@ -2500,7 +2500,7 @@ public function update($set = null, $where = null, ?int $limit = null): bool
25002500
$this->where($where);
25012501
}
25022502

2503-
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
2503+
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true; // @phpstan-ignore nullCoalesce.property
25042504
if ($limitZeroAsAll && $limit === 0) {
25052505
$limit = null;
25062506
}
@@ -2547,7 +2547,7 @@ protected function _update(string $table, array $values): string
25472547
$valStr[] = $key . ' = ' . $val;
25482548
}
25492549

2550-
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
2550+
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true; // @phpstan-ignore nullCoalesce.property
25512551
if ($limitZeroAsAll) {
25522552
return 'UPDATE ' . $this->compileIgnore('update') . $table . ' SET ' . implode(', ', $valStr)
25532553
. $this->compileWhereHaving('QBWhere')
@@ -2824,7 +2824,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
28242824

28252825
$sql = $this->_delete($this->removeAlias($table));
28262826

2827-
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
2827+
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true; // @phpstan-ignore nullCoalesce.property
28282828
if ($limitZeroAsAll && $limit === 0) {
28292829
$limit = null;
28302830
}
@@ -3099,7 +3099,7 @@ protected function compileSelect($selectOverride = false): string
30993099
. $this->compileWhereHaving('QBHaving')
31003100
. $this->compileOrderBy();
31013101

3102-
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true;
3102+
$limitZeroAsAll = config(Feature::class)->limitZeroAsAll ?? true; // @phpstan-ignore nullCoalesce.property
31033103
if ($limitZeroAsAll) {
31043104
if ($this->QBLimit) {
31053105
$sql = $this->_limit($sql . "\n");

0 commit comments

Comments
 (0)