Skip to content

Commit be05849

Browse files
committed
fix: eliminate PHPStan baseline errors (types, null coalesce, short ternary)
Refs #7731, #8732 Eliminates 119 PHPStan baseline errors across 4 categories: - missingType.parameter.neon: 31 errors (add @param types) - missingType.property.neon: 47 errors (add @var types) - nullCoalesce.property.neon: 8 errors (make props nullable) - ternary.shortNotAllowed.neon: 33 errors (expand ?: to long ternary) 50+ files changed, 4 baseline files emptied
1 parent 2a1c348 commit be05849

54 files changed

Lines changed: 235 additions & 583 deletions

Some content is hidden

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

public/.user.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
open_basedir=/home/usuario/Development/codeigniter4/:/tmp/

system/CLI/CLI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ public static function getWidth(int $default = 80): int
737737
static::generateDimensions();
738738
}
739739

740-
return static::$width ?: $default;
740+
return static::$width ? static::$width : $default;
741741
}
742742

743743
/**
@@ -749,7 +749,7 @@ public static function getHeight(int $default = 32): int
749749
static::generateDimensions();
750750
}
751751

752-
return static::$height ?: $default;
752+
return static::$height ? static::$height : $default;
753753
}
754754

755755
/**

system/Cookie/Cookie.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ final public function __construct(string $name, string $value = '', array $optio
254254

255255
// to preserve backward compatibility with array-based cookies in previous CI versions
256256
$prefix = ($options['prefix'] === '') ? self::$defaults['prefix'] : $options['prefix'];
257-
$path = $options['path'] ?: self::$defaults['path'];
258-
$domain = $options['domain'] ?: self::$defaults['domain'];
257+
\$path = \$options['path'] ? \$options['path'] : self::\$defaults['path'];
258+
\$domain = \$options['domain'] ? \$options['domain'] : self::\$defaults['domain'];
259259

260260
// empty string SameSite should use the default for browsers
261-
$samesite = $options['samesite'] ?: self::$defaults['samesite'];
261+
\$samesite = \$options['samesite'] ? \$options['samesite'] : self::\$defaults['samesite'];
262262

263263
$raw = $options['raw'];
264264
$secure = $options['secure'];
@@ -429,7 +429,7 @@ public function getOptions(): array
429429
'domain' => $this->domain,
430430
'secure' => $this->secure,
431431
'httponly' => $this->httponly,
432-
'samesite' => $this->samesite ?: ucfirst(self::SAMESITE_LAX),
432+
'samesite' => \$this->samesite ? \$this->samesite : ucfirst(self::SAMESITE_LAX),
433433
];
434434
}
435435

system/Database/BasePreparedQuery.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ abstract public function _prepare(string $sql, array $options = []);
110110
* Takes a new set of data and runs it against the currently
111111
* prepared query. Upon success, will return a Results object.
112112
*
113+
* @param mixed ...$data
114+
*
113115
* @return bool|ResultInterface<TConnection, TResult>
114116
*
115117
* @throws DatabaseException

system/Database/OCI8/Connection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class Connection extends BaseConnection
5353
'rownum',
5454
];
5555

56+
/**
57+
* @var list<string>
58+
*/
5659
protected $validDSNs = [
5760
// TNS
5861
'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/',
@@ -80,6 +83,9 @@ class Connection extends BaseConnection
8083
* Used by storedProcedure() to prevent execute() from
8184
* re-setting the statement ID.
8285
*/
86+
/**
87+
* @var bool
88+
*/
8389
protected $resetStmtId = true;
8490

8591
/**

system/Database/Postgre/Connection.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,24 @@ class Connection extends BaseConnection
5151
*/
5252
public $escapeChar = '"';
5353

54+
/**
55+
* @var int
56+
*/
5457
protected $connect_timeout;
58+
59+
/**
60+
* @var string
61+
*/
5562
protected $options;
63+
64+
/**
65+
* @var string
66+
*/
5667
protected $sslmode;
68+
69+
/**
70+
* @var string
71+
*/
5772
protected $service;
5873

5974
/**

system/Database/PreparedQueryInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ interface PreparedQueryInterface
2828
*
2929
* @return bool|ResultInterface<TConnection, TResult>
3030
*/
31+
/**
32+
* @param mixed ...$data
33+
*/
3134
public function execute(...$data);
3235

3336
/**

system/Debug/Toolbar/Collectors/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static function collect(Query $query)
8888
$config = config(Toolbar::class);
8989

9090
// Provide default in case it's not set
91-
$max = $config->maxQueries ?: 100;
91+
\$max = \$config->maxQueries ? \$config->maxQueries : 100;
9292

9393
if (count(static::$queries) < $max) {
9494
$queryString = $query->getQuery();

system/HTTP/Files/UploadedFile.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ class UploadedFile extends File implements UploadedFileInterface
6565
/**
6666
* The error constant of the upload
6767
* (one of PHP's UPLOADERRXXX constants)
68-
*
69-
* @var int
7068
*/
71-
protected $error;
69+
protected ?int $error = null;
7270

7371
/**
7472
* Whether the file has been moved already or not.

system/HTTP/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Message implements MessageInterface
2727
/**
2828
* Protocol version
2929
*
30-
* @var string
30+
* @var string|null
3131
*/
3232
protected $protocolVersion;
3333

0 commit comments

Comments
 (0)