Skip to content

Commit e430f85

Browse files
committed
refactor: fix minor type inaccuracies found via PHPStan bleeding edge
1 parent e7aa212 commit e430f85

5 files changed

Lines changed: 19 additions & 21 deletions

File tree

‎system/Database/Database.php‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function load(array $params = [], string $alias = '')
5858
throw new InvalidArgumentException('You have not selected a database type to connect to.');
5959
}
6060

61-
assert($this->checkDbExtension($params['DBDriver']));
61+
$this->checkDbExtension($params['DBDriver']);
6262

6363
$this->connections[$alias] = $this->initDriver($params['DBDriver'], 'Connection', $params);
6464

@@ -154,15 +154,17 @@ protected function initDriver(string $driver, string $class, $argument): object
154154
}
155155

156156
/**
157-
* Check the PHP database extension is loaded.
157+
* Check if the PHP database extension is loaded.
158158
*
159159
* @param string $driver DB driver or FQCN for custom driver
160+
*
161+
* @throws ConfigException if the driver is invalid
162+
* @throws CriticalError if the required PHP extension is not loaded
160163
*/
161-
private function checkDbExtension(string $driver): bool
164+
private function checkDbExtension(string $driver): void
162165
{
163166
if (str_contains($driver, '\\')) {
164-
// Cannot check a fully qualified classname for a custom driver.
165-
return true;
167+
return; // Cannot check a fully qualified classname for a custom driver.
166168
}
167169

168170
$extensionMap = [
@@ -174,21 +176,17 @@ private function checkDbExtension(string $driver): bool
174176
'OCI8' => 'oci8',
175177
];
176178

177-
$extension = $extensionMap[$driver] ?? '';
178-
179-
if ($extension === '') {
180-
$message = 'Invalid DBDriver name: "' . $driver . '"';
181-
182-
throw new ConfigException($message);
183-
}
179+
$extension = $extensionMap[$driver]
180+
?? throw new ConfigException(sprintf('Invalid DBDriver name: "%s".', $driver));
184181

185182
if (extension_loaded($extension)) {
186-
return true;
183+
return;
187184
}
188185

189-
$message = 'The required PHP extension "' . $extension . '" is not loaded.'
190-
. ' Install and enable it to use "' . $driver . '" driver.';
191-
192-
throw new CriticalError($message);
186+
throw new CriticalError(sprintf(
187+
'The required PHP extension "%s" is not loaded. Install and enable it to use "%s" driver.',
188+
$extension,
189+
$driver,
190+
));
193191
}
194192
}

‎system/HTTP/Files/FileCollection.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected function createFileObject(array $array)
189189

190190
return new UploadedFile(
191191
$array['tmp_name'] ?? null,
192-
$array['name'] ?? null,
192+
$array['name'],
193193
$array['type'] ?? null,
194194
($array['size'] ?? null) === null ? null : (int) $array['size'],
195195
$array['error'] ?? null,

‎system/HTTP/SiteURIFactory.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private function createURIFromRoutePath(string $routePath): SiteURI
227227
*/
228228
private function getHost(): ?string
229229
{
230-
$httpHostPort = $this->superglobals->server('HTTP_HOST') ?? null;
230+
$httpHostPort = $this->superglobals->server('HTTP_HOST');
231231

232232
if ($httpHostPort !== null) {
233233
[$httpHost] = explode(':', $httpHostPort, 2);

‎system/Helpers/Array/ArrayHelper.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public static function recursiveCount(array $array, int $counter = 0): int
324324
* @param list<int|list<int|string>|string> $array
325325
* @param int|string|null $sortByIndex
326326
*/
327-
public static function sortValuesByNatural(array &$array, $sortByIndex = null): bool
327+
public static function sortValuesByNatural(array &$array, $sortByIndex = null): true
328328
{
329329
return usort($array, static function ($currentValue, $nextValue) use ($sortByIndex): int {
330330
if ($sortByIndex !== null) {

‎system/Router/RouteCollection.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ private function checkSubdomains($subdomains): bool
15201520

15211521
// Routes can be limited to any sub-domain. In that case, though,
15221522
// it does require a sub-domain to be present.
1523-
if (! in_array($this->currentSubdomain, [null, ''], true) && in_array('*', $subdomains, true)) {
1523+
if ($this->currentSubdomain !== '' && in_array('*', $subdomains, true)) {
15241524
return true;
15251525
}
15261526

0 commit comments

Comments
 (0)