Skip to content

Commit 392b60a

Browse files
committed
fixed PHPStan errors
1 parent 52e2f9e commit 392b60a

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

phpstan.neon

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
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

src/RobotLoader/RobotLoader.php

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

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

100100
if ($this->autoRebuild) {
101101
if (!$this->refreshed) {
102102
if (!$file || !is_file($file)) {
103103
$this->refreshClasses();
104-
[$file] = $this->classes[$type] ?? null;
104+
[$file] = $this->classes[$type] ?? [null, null];
105105
$this->needSave = true;
106106

107107
} elseif (filemtime($file) !== $mtime) {
108108
$this->updateFile($file);
109-
[$file] = $this->classes[$type] ?? null;
109+
[$file] = $this->classes[$type] ?? [null, null];
110110
$this->needSave = true;
111111
}
112112
}
@@ -130,7 +130,7 @@ public function tryLoad(string $type): void
130130
*/
131131
public function addDirectory(string ...$paths): static
132132
{
133-
$this->scanPaths = array_merge($this->scanPaths, $paths);
133+
$this->scanPaths = array_merge($this->scanPaths, array_values($paths));
134134
return $this;
135135
}
136136

@@ -147,7 +147,7 @@ public function reportParseErrors(bool $state = true): static
147147
*/
148148
public function excludeDirectory(string ...$paths): static
149149
{
150-
$this->excludeDirs = array_merge($this->excludeDirs, $paths);
150+
$this->excludeDirs = array_merge($this->excludeDirs, array_values($paths));
151151
return $this;
152152
}
153153

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

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

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

293293
if (isset($prevFile)) {
@@ -299,7 +299,7 @@ private function updateFile(string $file): void
299299
));
300300
}
301301

302-
$this->classes[$class] = [$file, filemtime($file)];
302+
$this->classes[$class] = [$file, (int) filemtime($file)];
303303
}
304304
}
305305

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

0 commit comments

Comments
 (0)