Skip to content

Commit fc76603

Browse files
committed
fixed PHPStan errors
1 parent a21287e commit fc76603

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

phpstan.neon

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
parameters:
2-
level: 5
2+
level: 8
33

44
paths:
55
- src
6+
7+
checkMissingCallableSignature: true
8+
9+
ignoreErrors:
10+
-
11+
message: '#^Method Nette\\Loaders\\RobotLoader\:\:scanPhp\(\) should return list\<class\-string\> but returns list\<non\-falsy\-string\>\.$#'
12+
identifier: return.type
13+
count: 1
14+
path: src/RobotLoader/RobotLoader.php
15+
16+
-
17+
message: '#^Parameter \#1 \$code of static method PhpToken\:\:tokenize\(\) expects string, string\|false given\.$#'
18+
identifier: argument.type
19+
count: 1
20+
path: src/RobotLoader/RobotLoader.php
21+

src/RobotLoader/RobotLoader.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ public function tryLoad(string $type): void
9797
return;
9898
}
9999

100-
[$file, $mtime] = $this->classes[$type] ?? null;
100+
[$file, $mtime] = $this->classes[$type] ?? [null, null];
101101

102102
if ($this->autoRebuild) {
103103
if (!$this->refreshed) {
104104
if (!$file || !is_file($file)) {
105105
$this->refreshClasses();
106-
[$file] = $this->classes[$type] ?? null;
106+
[$file] = $this->classes[$type] ?? [null, null];
107107
$this->needSave = true;
108108

109109
} elseif (filemtime($file) !== $mtime) {
110110
$this->updateFile($file);
111-
[$file] = $this->classes[$type] ?? null;
111+
[$file] = $this->classes[$type] ?? [null, null];
112112
$this->needSave = true;
113113
}
114114
}
@@ -132,7 +132,7 @@ public function tryLoad(string $type): void
132132
*/
133133
public function addDirectory(string ...$paths): static
134134
{
135-
$this->scanPaths = array_merge($this->scanPaths, $paths);
135+
$this->scanPaths = array_merge($this->scanPaths, array_values($paths));
136136
return $this;
137137
}
138138

@@ -149,7 +149,7 @@ public function reportParseErrors(bool $state = true): static
149149
*/
150150
public function excludeDirectory(string ...$paths): static
151151
{
152-
$this->excludeDirs = array_merge($this->excludeDirs, $paths);
152+
$this->excludeDirs = array_merge($this->excludeDirs, array_values($paths));
153153
return $this;
154154
}
155155

@@ -285,11 +285,11 @@ private function updateFile(string $file): void
285285
$foundClasses = is_file($file) ? $this->scanPhp($file) : [];
286286

287287
foreach ($foundClasses as $class) {
288-
[$prevFile, $prevMtime] = $this->classes[$class] ?? null;
288+
[$prevFile, $prevMtime] = $this->classes[$class] ?? [null, null];
289289

290290
if (isset($prevFile) && @filemtime($prevFile) !== $prevMtime) { // @ file may not exist
291291
$this->updateFile($prevFile);
292-
[$prevFile] = $this->classes[$class] ?? null;
292+
[$prevFile] = $this->classes[$class] ?? [null, null];
293293
}
294294

295295
if (isset($prevFile)) {
@@ -301,7 +301,7 @@ private function updateFile(string $file): void
301301
));
302302
}
303303

304-
$this->classes[$class] = [$file, filemtime($file)];
304+
$this->classes[$class] = [$file, (int) filemtime($file)];
305305
}
306306
}
307307

@@ -485,13 +485,13 @@ private function acquireLock(string $file, int $mode)
485485
{
486486
$handle = @fopen($file, 'w'); // @ is escalated to exception
487487
if (!$handle) {
488-
throw new \RuntimeException(sprintf("Unable to create file '%s'. %s", $file, error_get_last()['message']));
488+
throw new \RuntimeException(sprintf("Unable to create file '%s'. %s", $file, error_get_last()['message'] ?? ''));
489489
} elseif (!@flock($handle, $mode)) { // @ is escalated to exception
490490
throw new \RuntimeException(sprintf(
491491
"Unable to acquire %s lock on file '%s'. %s",
492492
$mode & LOCK_EX ? 'exclusive' : 'shared',
493493
$file,
494-
error_get_last()['message'],
494+
error_get_last()['message'] ?? '',
495495
));
496496
}
497497

0 commit comments

Comments
 (0)