Skip to content

Commit 8240f83

Browse files
dev: PHPStan v2 and Level 10 (#213)
2 parents 85f0529 + 7388a4a commit 8240f83

File tree

224 files changed

+989
-996
lines changed

Some content is hidden

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

224 files changed

+989
-996
lines changed

.github/workflows/phpunit.yml

+9
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ jobs:
149149
composer require --no-interaction --no-progress --ansi --no-update "${PKG}:${{ matrix.laravel }}"
150150
done <<< "${PACKAGES}"
151151
152+
# PHPStan dev packages may prevent installing the lowest version of the Laravel
153+
- name: Remove PHPStan packages
154+
shell: bash
155+
working-directory: ${{ env.WORKING_DIRECTORY }}
156+
run: |
157+
composer remove --no-interaction --no-progress --ansi --no-update --dev "phpstan/*"
158+
composer remove --no-interaction --no-progress --ansi --no-update --dev "larastan/larastan"
159+
composer remove --no-interaction --no-progress --ansi --no-update --dev "spaze/phpstan-disallowed-calls"
160+
152161
- name: Remove optional packages
153162
if: ${{ matrix.optional != 'null' }}
154163
shell: bash

composer-dependency-analyser.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
if ($root) {
3232
$config
33+
->ignoreErrorsOnPackage('larastan/larastan', [ErrorType::UNUSED_DEPENDENCY])
3334
->ignoreErrorsOnPackage('phpstan/phpstan-mockery', [ErrorType::UNUSED_DEPENDENCY])
3435
->ignoreErrorsOnPackage('phpstan/phpstan-phpunit', [ErrorType::UNUSED_DEPENDENCY])
3536
->ignoreErrorsOnPackage('phpstan/phpstan-strict-rules', [ErrorType::UNUSED_DEPENDENCY])

composer.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,16 @@
6161
"illuminate/testing": "^11.0.8",
6262
"illuminate/translation": "^11.0.8",
6363
"illuminate/validation": "^11.0.8",
64-
"larastan/larastan": "^2.8.1",
6564
"league/commonmark": "^2.6.0",
6665
"league/config": "^1.1.1",
6766
"mockery/mockery": "^1.6.5",
6867
"nette/neon": "^3.4.1",
69-
"nikic/php-parser": "^5.0",
68+
"nikic/php-parser": "^5.4.0",
7069
"nuwave/lighthouse": "^6.36.0",
7170
"opis/json-schema": "^2.3.0",
7271
"phpdocumentor/type-resolver": "^1.7",
73-
"phpstan/phpdoc-parser": "^1.25",
74-
"phpstan/phpstan": "^1.10",
72+
"phpstan/phpdoc-parser": "^2.0.0",
73+
"phpstan/phpstan": "^2.1.1",
7574
"phpunit/phpunit": "^10.5.0|^11.0.0",
7675
"psr/http-message": "^1.0.0|^2.0.0",
7776
"sebastian/comparator": "^5.0|^6.0.0",
@@ -84,7 +83,7 @@
8483
"symfony/http-kernel": "^7.0.0",
8584
"symfony/mime": "^7.0.0",
8685
"symfony/property-access": "^7.0.0",
87-
"symfony/property-info": "^7.0.0",
86+
"symfony/property-info": "^7.1.10",
8887
"symfony/psr-http-message-bridge": "^7.0.0",
8988
"symfony/serializer": "^7.0.0",
9089
"symfony/var-dumper": "^7.0.0",
@@ -98,12 +97,13 @@
9897
"illuminate/cache": "^11.0.8",
9998
"illuminate/config": "^11.0.8",
10099
"laravel/scout": "^10.8.0",
100+
"larastan/larastan": "^3.0.2",
101101
"orchestra/testbench": "^9.0.0",
102-
"phpstan/phpstan": "1.12.14",
103-
"phpstan/phpstan-mockery": "^1.1",
104-
"phpstan/phpstan-phpunit": "^1.3",
105-
"phpstan/phpstan-strict-rules": "^1.5",
106-
"spaze/phpstan-disallowed-calls": "^3.0"
102+
"phpstan/phpstan": "2.1.1",
103+
"phpstan/phpstan-mockery": "^2.0.0",
104+
"phpstan/phpstan-phpunit": "^2.0.3",
105+
"phpstan/phpstan-strict-rules": "^2.0.1",
106+
"spaze/phpstan-disallowed-calls": "^4.0.1"
107107
},
108108
"autoload": {
109109
"files": [
@@ -215,7 +215,7 @@
215215
"jq --indent 2 '.' composer.json > composer.tmp && mv composer.tmp composer.json"
216216
],
217217
"phpstan": [
218-
"./vendor/bin/phpstan analyse -v"
218+
"./vendor/bin/phpstan analyse"
219219
],
220220
"phpunit": [
221221
"./vendor/bin/phpunit"

packages/core/UPGRADE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
7373
[code-links/8b4dc3d615948332]: src/Provider.php
7474
"\LastDragon_ru\LaraASP\Core\Provider"
7575

76-
[code-links/141085a29c14a778]: src/Provider/WithRoutes.php#L16-L41
76+
[code-links/141085a29c14a778]: src/Provider/WithRoutes.php#L18-L45
7777
"\LastDragon_ru\LaraASP\Core\Provider\WithRoutes::bootRoutes()"
7878

7979
[//]: # (end: code-links)

packages/core/src/Helpers/TranslatorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function getName(): string {
4444
}
4545
};
4646

47-
self::assertEquals($expected, $translator->choice($key, $number, $replace, $locale));
47+
self::assertSame($expected, $translator->choice($key, $number, $replace, $locale));
4848
}
4949

5050
/**
@@ -70,7 +70,7 @@ protected function getName(): string {
7070
}
7171
};
7272

73-
self::assertEquals($expected, $translator->get($key, $replace, $locale));
73+
self::assertSame($expected, $translator->get($key, $replace, $locale));
7474
}
7575
//</editor-fold>
7676

packages/core/src/Helpers/ViewerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ public function testRender(): void {
6464
->once()
6565
->andReturn($template);
6666

67-
self::assertEquals($content, $viewer->render($view, $data));
67+
self::assertSame($content, $viewer->render($view, $data));
6868
}
6969
}

packages/core/src/Path/DirectoryPathTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@ public function testGetFilePath(): void {
1414
$relative = (new DirectoryPath('relative/path/to/directory'))->getFilePath('file.b');
1515
$absolute = (new DirectoryPath('/path/to/directory'))->getFilePath('/file.b');
1616

17-
self::assertEquals('relative/path/to/directory/file.b', (string) $relative);
17+
self::assertSame('relative/path/to/directory/file.b', (string) $relative);
1818

19-
self::assertEquals('/file.b', (string) $absolute);
19+
self::assertSame('/file.b', (string) $absolute);
2020
}
2121

2222
public function testGetDirectoryPath(): void {
2323
$relative = (new DirectoryPath('relative/path/to'))->getDirectoryPath('directory');
2424
$absolute = (new DirectoryPath('/path/to'))->getDirectoryPath('/directory');
2525
$null = (new DirectoryPath('/path/to'))->getDirectoryPath();
2626

27-
self::assertEquals('relative/path/to/directory', (string) $relative);
27+
self::assertSame('relative/path/to/directory', (string) $relative);
2828

29-
self::assertEquals('/directory', (string) $absolute);
29+
self::assertSame('/directory', (string) $absolute);
3030

31-
self::assertEquals('/path', (string) $null);
31+
self::assertSame('/path', (string) $null);
3232
}
3333

3434
public function testGetParentPath(): void {
3535
$relative = new DirectoryPath('relative/path/to/file');
3636
$absolute = new DirectoryPath('/absolute/path/to/file');
3737

38-
self::assertEquals('relative/path/to', (string) $relative->getParentPath());
39-
self::assertEquals('relative/path', (string) $relative->getParentPath()->getParentPath());
38+
self::assertSame('relative/path/to', (string) $relative->getParentPath());
39+
self::assertSame('relative/path', (string) $relative->getParentPath()->getParentPath());
4040

41-
self::assertEquals('/absolute/path/to', (string) $absolute->getParentPath());
42-
self::assertEquals('/absolute/path', (string) $absolute->getParentPath()->getParentPath());
41+
self::assertSame('/absolute/path/to', (string) $absolute->getParentPath());
42+
self::assertSame('/absolute/path', (string) $absolute->getParentPath()->getParentPath());
4343

44-
self::assertEquals((string) $relative->getDirectoryPath(), (string) $relative->getParentPath());
45-
self::assertEquals((string) $absolute->getDirectoryPath(), (string) $absolute->getParentPath());
44+
self::assertSame((string) $relative->getDirectoryPath(), (string) $relative->getParentPath());
45+
self::assertSame((string) $absolute->getDirectoryPath(), (string) $absolute->getParentPath());
4646
}
4747

4848
public function testIsInside(): void {

packages/core/src/Path/FilePathTest.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ public function testGetFilePath(): void {
1414
$relative = (new FilePath('relative/path/to/file.a'))->getFilePath('file.b');
1515
$absolute = (new FilePath('/path/to/file.a'))->getFilePath('/file.b');
1616

17-
self::assertEquals('relative/path/to/file.b', (string) $relative);
17+
self::assertSame('relative/path/to/file.b', (string) $relative);
1818

19-
self::assertEquals('/file.b', (string) $absolute);
19+
self::assertSame('/file.b', (string) $absolute);
2020
}
2121

2222
public function testGetParentPath(): void {
2323
$relative = (new FilePath('relative/path/to/file.a'))->getParentPath();
2424
$absolute = (new FilePath('/path/to/file.a'))->getParentPath();
2525

26-
self::assertEquals('relative/path/to', (string) $relative);
27-
self::assertEquals('/path/to', (string) $absolute);
26+
self::assertSame('relative/path/to', (string) $relative);
27+
self::assertSame('/path/to', (string) $absolute);
2828
}
2929

3030
public function testGetDirectoryPath(): void {
3131
$relative = (new FilePath('relative/path/to/file.a'))->getDirectoryPath('directory');
3232
$absolute = (new FilePath('/path/to/file.a'))->getDirectoryPath('/directory');
3333
$null = (new FilePath('/path/to/file.a'))->getDirectoryPath();
3434

35-
self::assertEquals('relative/path/to/directory', (string) $relative);
35+
self::assertSame('relative/path/to/directory', (string) $relative);
3636

37-
self::assertEquals('/directory', (string) $absolute);
37+
self::assertSame('/directory', (string) $absolute);
3838

39-
self::assertEquals('/path/to', (string) $null);
39+
self::assertSame('/path/to', (string) $null);
4040
}
4141

4242
public function testGetExtension(): void {
43-
self::assertEquals('txt', (new FilePath('relative/path/to/file.txt'))->getExtension());
43+
self::assertSame('txt', (new FilePath('relative/path/to/file.txt'))->getExtension());
4444
self::assertNull((new FilePath('relative/path/to/file'))->getExtension());
4545
}
4646
}

packages/core/src/Path/PathTest.php

+31-31
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public function testToString(): void {
1717
$path = '/a/b/c';
1818
$object = new PathTest_Path($path);
1919

20-
self::assertEquals($path, (string) $object);
20+
self::assertSame($path, (string) $object);
2121
}
2222

2323
public function testGetName(): void {
2424
$path = '/a/b/c';
2525
$object = new PathTest_Path($path);
2626

27-
self::assertEquals(basename($path), $object->getName());
27+
self::assertSame(basename($path), $object->getName());
2828
}
2929

3030
public function testGetPathToAbsolute(): void {
@@ -33,38 +33,38 @@ public function testGetPathToAbsolute(): void {
3333
$absolute = (new PathTest_Path('/absolute/path'))->getPath($to);
3434

3535
self::assertNotSame($to, $relative);
36-
self::assertEquals('/to/absolute/path', (string) $relative);
36+
self::assertSame('/to/absolute/path', (string) $relative);
3737

3838
self::assertNotSame($to, $absolute);
39-
self::assertEquals('/to/absolute/path', (string) $absolute);
39+
self::assertSame('/to/absolute/path', (string) $absolute);
4040
}
4141

4242
public function testGetPathToRelative(): void {
4343
$fromRelative = new PathTest_Path('relative/path');
4444
$fromAbsolute = new PathTest_Path('/absolute/path');
4545
$to = new PathTest_Path('to/../relative/./path');
4646

47-
self::assertEquals('/absolute/path/relative/path', (string) $fromAbsolute->getPath($to));
48-
self::assertEquals('relative/path/relative/path', (string) $fromRelative->getPath($to));
47+
self::assertSame('/absolute/path/relative/path', (string) $fromAbsolute->getPath($to));
48+
self::assertSame('relative/path/relative/path', (string) $fromRelative->getPath($to));
4949
}
5050

5151
public function testGetNormalizedPath(): void {
52-
self::assertEquals('/any/path', (string) (new PathTest_Path('/any/path'))->getNormalizedPath());
53-
self::assertEquals('any/path', (string) (new PathTest_Path('any/path'))->getNormalizedPath());
54-
self::assertEquals('any/path', (string) (new PathTest_Path('./any/path'))->getNormalizedPath());
55-
self::assertEquals('any/path', (string) (new PathTest_Path('././any/path'))->getNormalizedPath());
56-
self::assertEquals('../any/path', (string) (new PathTest_Path('./../any/path'))->getNormalizedPath());
57-
self::assertEquals('path', (string) (new PathTest_Path('./any/../path'))->getNormalizedPath());
58-
self::assertEquals('', (string) (new PathTest_Path('./'))->getNormalizedPath());
59-
self::assertEquals('', (string) (new PathTest_Path('.'))->getNormalizedPath());
60-
self::assertEquals('..', (string) (new PathTest_Path('../'))->getNormalizedPath());
61-
self::assertEquals('..', (string) (new PathTest_Path('..'))->getNormalizedPath());
62-
self::assertEquals('path', (string) (new PathTest_Path('./any/../path/.'))->getNormalizedPath());
63-
self::assertEquals('/', (string) (new PathTest_Path('/..'))->getNormalizedPath());
64-
self::assertEquals('../any/path', (string) (new PathTest_Path('.\\..\\any\\path'))->getNormalizedPath());
65-
self::assertEquals('any/path', (string) (new PathTest_Path('any\\path'))->getNormalizedPath());
66-
self::assertEquals('/any/path', (string) (new PathTest_Path('/any/path/'))->getNormalizedPath());
67-
self::assertEquals('any/path', (string) (new PathTest_Path('any/path/'))->getNormalizedPath());
52+
self::assertSame('/any/path', (string) (new PathTest_Path('/any/path'))->getNormalizedPath());
53+
self::assertSame('any/path', (string) (new PathTest_Path('any/path'))->getNormalizedPath());
54+
self::assertSame('any/path', (string) (new PathTest_Path('./any/path'))->getNormalizedPath());
55+
self::assertSame('any/path', (string) (new PathTest_Path('././any/path'))->getNormalizedPath());
56+
self::assertSame('../any/path', (string) (new PathTest_Path('./../any/path'))->getNormalizedPath());
57+
self::assertSame('path', (string) (new PathTest_Path('./any/../path'))->getNormalizedPath());
58+
self::assertSame('', (string) (new PathTest_Path('./'))->getNormalizedPath());
59+
self::assertSame('', (string) (new PathTest_Path('.'))->getNormalizedPath());
60+
self::assertSame('..', (string) (new PathTest_Path('../'))->getNormalizedPath());
61+
self::assertSame('..', (string) (new PathTest_Path('..'))->getNormalizedPath());
62+
self::assertSame('path', (string) (new PathTest_Path('./any/../path/.'))->getNormalizedPath());
63+
self::assertSame('/', (string) (new PathTest_Path('/..'))->getNormalizedPath());
64+
self::assertSame('../any/path', (string) (new PathTest_Path('.\\..\\any\\path'))->getNormalizedPath());
65+
self::assertSame('any/path', (string) (new PathTest_Path('any\\path'))->getNormalizedPath());
66+
self::assertSame('/any/path', (string) (new PathTest_Path('/any/path/'))->getNormalizedPath());
67+
self::assertSame('any/path', (string) (new PathTest_Path('any/path/'))->getNormalizedPath());
6868
}
6969

7070
public function testIsNormalized(): void {
@@ -76,19 +76,19 @@ public function testIsNormalized(): void {
7676
}
7777

7878
public function testGetRelativePath(): void {
79-
self::assertEquals(
79+
self::assertSame(
8080
'../to/file',
8181
(string) (new PathTest_Path('/any/path'))->getRelativePath(new PathTest_Path('/any/path/../to/file')),
8282
);
83-
self::assertEquals(
83+
self::assertSame(
8484
'',
8585
(string) (new PathTest_Path('/any/path'))->getRelativePath(new PathTest_Path('/any/path')),
8686
);
87-
self::assertEquals(
87+
self::assertSame(
8888
'to/file',
8989
(string) (new PathTest_Path('/absolute/path'))->getRelativePath(new PathTest_Path('to/./file')),
9090
);
91-
self::assertEquals(
91+
self::assertSame(
9292
basename(__FILE__),
9393
(string) (new PathTest_Path(__DIR__))->getRelativePath(new PathTest_Path(__FILE__)),
9494
);
@@ -114,20 +114,20 @@ public function testGetFilePath(): void {
114114
$relative = (new PathTest_Path('relative/path/to'))->getFilePath('file');
115115
$absolute = (new PathTest_Path('/path/to'))->getFilePath('/file');
116116

117-
self::assertEquals('relative/path/to/file', (string) $relative);
117+
self::assertSame('relative/path/to/file', (string) $relative);
118118

119-
self::assertEquals('/file', (string) $absolute);
119+
self::assertSame('/file', (string) $absolute);
120120
}
121121

122122
public function testGetDirectoryPath(): void {
123123
$relative = (new PathTest_Path('relative/path/to'))->getDirectoryPath('directory');
124124
$absolute = (new PathTest_Path('/path/to'))->getDirectoryPath('/directory');
125125
$null = (new PathTest_Path('/path/to'))->getDirectoryPath();
126126

127-
self::assertEquals('relative/path/to/directory', (string) $relative);
127+
self::assertSame('relative/path/to/directory', (string) $relative);
128128

129-
self::assertEquals('/directory', (string) $absolute);
130-
self::assertEquals('/path', (string) $null);
129+
self::assertSame('/directory', (string) $absolute);
130+
self::assertSame('/path', (string) $null);
131131
}
132132

133133
public function testIsEqual(): void {

packages/core/src/Provider/WithRoutes.php

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Illuminate\Contracts\Routing\Registrar;
88
use Illuminate\Support\ServiceProvider;
99

10+
use function assert;
11+
1012
/**
1113
* @phpstan-require-extends ServiceProvider
1214
*/
@@ -36,6 +38,8 @@ protected function bootRoutes(Closure $settings): void {
3638
$routes = require $path;
3739
$registrar = $this->app->make(Registrar::class);
3840

41+
assert($routes instanceof Closure);
42+
3943
$registrar->group($settings['attributes'], $routes);
4044
});
4145
}

packages/core/src/Utils/Cast.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static function toStringable(mixed $value): Stringable|string {
9393
}
9494

9595
/**
96-
* @return iterable<array-key, mixed>
96+
* @return iterable<mixed, mixed>
9797
*/
9898
public static function toIterable(mixed $value): iterable {
9999
assert(is_iterable($value));

packages/core/src/Utils/ConfigMerger.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ protected function setStrict(bool $strict): static {
6060
* @see ConfigMerger::Replace
6161
* @see ConfigMerger::Strict
6262
*
63-
* @param array<array-key, mixed> $target
64-
* @param array<array-key, mixed> $configs
63+
* @template A of array-key
64+
* @template B of array-key
65+
*
66+
* @param array<A, mixed> $target
67+
* @param array<B, mixed> $configs
6568
*
66-
* @return array<array-key, mixed>
69+
* @return array<A|B, mixed>
6770
*/
6871
public function merge(array $target, array ...$configs): array {
6972
// Enable strict mode (just for case)
@@ -78,7 +81,7 @@ public function merge(array $target, array ...$configs): array {
7881
$this->cleanup($target, true);
7982

8083
// Return
81-
return $target;
84+
return $target; // @phpstan-ignore return.type (class is deprecated, so the way is not very important)
8285
}
8386

8487
/**

0 commit comments

Comments
 (0)