Skip to content

Commit

Permalink
dev: PHPStan v2 and Level 10 (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru authored Jan 11, 2025
2 parents 85f0529 + 7388a4a commit 8240f83
Show file tree
Hide file tree
Showing 224 changed files with 989 additions and 996 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ jobs:
composer require --no-interaction --no-progress --ansi --no-update "${PKG}:${{ matrix.laravel }}"
done <<< "${PACKAGES}"
# PHPStan dev packages may prevent installing the lowest version of the Laravel
- name: Remove PHPStan packages
shell: bash
working-directory: ${{ env.WORKING_DIRECTORY }}
run: |
composer remove --no-interaction --no-progress --ansi --no-update --dev "phpstan/*"
composer remove --no-interaction --no-progress --ansi --no-update --dev "larastan/larastan"
composer remove --no-interaction --no-progress --ansi --no-update --dev "spaze/phpstan-disallowed-calls"
- name: Remove optional packages
if: ${{ matrix.optional != 'null' }}
shell: bash
Expand Down
1 change: 1 addition & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

if ($root) {
$config
->ignoreErrorsOnPackage('larastan/larastan', [ErrorType::UNUSED_DEPENDENCY])
->ignoreErrorsOnPackage('phpstan/phpstan-mockery', [ErrorType::UNUSED_DEPENDENCY])
->ignoreErrorsOnPackage('phpstan/phpstan-phpunit', [ErrorType::UNUSED_DEPENDENCY])
->ignoreErrorsOnPackage('phpstan/phpstan-strict-rules', [ErrorType::UNUSED_DEPENDENCY])
Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,16 @@
"illuminate/testing": "^11.0.8",
"illuminate/translation": "^11.0.8",
"illuminate/validation": "^11.0.8",
"larastan/larastan": "^2.8.1",
"league/commonmark": "^2.6.0",
"league/config": "^1.1.1",
"mockery/mockery": "^1.6.5",
"nette/neon": "^3.4.1",
"nikic/php-parser": "^5.0",
"nikic/php-parser": "^5.4.0",
"nuwave/lighthouse": "^6.36.0",
"opis/json-schema": "^2.3.0",
"phpdocumentor/type-resolver": "^1.7",
"phpstan/phpdoc-parser": "^1.25",
"phpstan/phpstan": "^1.10",
"phpstan/phpdoc-parser": "^2.0.0",
"phpstan/phpstan": "^2.1.1",
"phpunit/phpunit": "^10.5.0|^11.0.0",
"psr/http-message": "^1.0.0|^2.0.0",
"sebastian/comparator": "^5.0|^6.0.0",
Expand All @@ -84,7 +83,7 @@
"symfony/http-kernel": "^7.0.0",
"symfony/mime": "^7.0.0",
"symfony/property-access": "^7.0.0",
"symfony/property-info": "^7.0.0",
"symfony/property-info": "^7.1.10",
"symfony/psr-http-message-bridge": "^7.0.0",
"symfony/serializer": "^7.0.0",
"symfony/var-dumper": "^7.0.0",
Expand All @@ -98,12 +97,13 @@
"illuminate/cache": "^11.0.8",
"illuminate/config": "^11.0.8",
"laravel/scout": "^10.8.0",
"larastan/larastan": "^3.0.2",
"orchestra/testbench": "^9.0.0",
"phpstan/phpstan": "1.12.14",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"spaze/phpstan-disallowed-calls": "^3.0"
"phpstan/phpstan": "2.1.1",
"phpstan/phpstan-mockery": "^2.0.0",
"phpstan/phpstan-phpunit": "^2.0.3",
"phpstan/phpstan-strict-rules": "^2.0.1",
"spaze/phpstan-disallowed-calls": "^4.0.1"
},
"autoload": {
"files": [
Expand Down Expand Up @@ -215,7 +215,7 @@
"jq --indent 2 '.' composer.json > composer.tmp && mv composer.tmp composer.json"
],
"phpstan": [
"./vendor/bin/phpstan analyse -v"
"./vendor/bin/phpstan analyse"
],
"phpunit": [
"./vendor/bin/phpunit"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Please also see [changelog](https://github.com/LastDragon-ru/lara-asp/releases)
[code-links/8b4dc3d615948332]: src/Provider.php
"\LastDragon_ru\LaraASP\Core\Provider"

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

[//]: # (end: code-links)
4 changes: 2 additions & 2 deletions packages/core/src/Helpers/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function getName(): string {
}
};

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

/**
Expand All @@ -70,7 +70,7 @@ protected function getName(): string {
}
};

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

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Helpers/ViewerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public function testRender(): void {
->once()
->andReturn($template);

self::assertEquals($content, $viewer->render($view, $data));
self::assertSame($content, $viewer->render($view, $data));
}
}
22 changes: 11 additions & 11 deletions packages/core/src/Path/DirectoryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@ public function testGetFilePath(): void {
$relative = (new DirectoryPath('relative/path/to/directory'))->getFilePath('file.b');
$absolute = (new DirectoryPath('/path/to/directory'))->getFilePath('/file.b');

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

self::assertEquals('/file.b', (string) $absolute);
self::assertSame('/file.b', (string) $absolute);
}

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

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

self::assertEquals('/directory', (string) $absolute);
self::assertSame('/directory', (string) $absolute);

self::assertEquals('/path', (string) $null);
self::assertSame('/path', (string) $null);
}

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

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

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

self::assertEquals((string) $relative->getDirectoryPath(), (string) $relative->getParentPath());
self::assertEquals((string) $absolute->getDirectoryPath(), (string) $absolute->getParentPath());
self::assertSame((string) $relative->getDirectoryPath(), (string) $relative->getParentPath());
self::assertSame((string) $absolute->getDirectoryPath(), (string) $absolute->getParentPath());
}

public function testIsInside(): void {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/Path/FilePathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ public function testGetFilePath(): void {
$relative = (new FilePath('relative/path/to/file.a'))->getFilePath('file.b');
$absolute = (new FilePath('/path/to/file.a'))->getFilePath('/file.b');

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

self::assertEquals('/file.b', (string) $absolute);
self::assertSame('/file.b', (string) $absolute);
}

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

self::assertEquals('relative/path/to', (string) $relative);
self::assertEquals('/path/to', (string) $absolute);
self::assertSame('relative/path/to', (string) $relative);
self::assertSame('/path/to', (string) $absolute);
}

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

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

self::assertEquals('/directory', (string) $absolute);
self::assertSame('/directory', (string) $absolute);

self::assertEquals('/path/to', (string) $null);
self::assertSame('/path/to', (string) $null);
}

public function testGetExtension(): void {
self::assertEquals('txt', (new FilePath('relative/path/to/file.txt'))->getExtension());
self::assertSame('txt', (new FilePath('relative/path/to/file.txt'))->getExtension());
self::assertNull((new FilePath('relative/path/to/file'))->getExtension());
}
}
62 changes: 31 additions & 31 deletions packages/core/src/Path/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public function testToString(): void {
$path = '/a/b/c';
$object = new PathTest_Path($path);

self::assertEquals($path, (string) $object);
self::assertSame($path, (string) $object);
}

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

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

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

self::assertNotSame($to, $relative);
self::assertEquals('/to/absolute/path', (string) $relative);
self::assertSame('/to/absolute/path', (string) $relative);

self::assertNotSame($to, $absolute);
self::assertEquals('/to/absolute/path', (string) $absolute);
self::assertSame('/to/absolute/path', (string) $absolute);
}

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

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

public function testGetNormalizedPath(): void {
self::assertEquals('/any/path', (string) (new PathTest_Path('/any/path'))->getNormalizedPath());
self::assertEquals('any/path', (string) (new PathTest_Path('any/path'))->getNormalizedPath());
self::assertEquals('any/path', (string) (new PathTest_Path('./any/path'))->getNormalizedPath());
self::assertEquals('any/path', (string) (new PathTest_Path('././any/path'))->getNormalizedPath());
self::assertEquals('../any/path', (string) (new PathTest_Path('./../any/path'))->getNormalizedPath());
self::assertEquals('path', (string) (new PathTest_Path('./any/../path'))->getNormalizedPath());
self::assertEquals('', (string) (new PathTest_Path('./'))->getNormalizedPath());
self::assertEquals('', (string) (new PathTest_Path('.'))->getNormalizedPath());
self::assertEquals('..', (string) (new PathTest_Path('../'))->getNormalizedPath());
self::assertEquals('..', (string) (new PathTest_Path('..'))->getNormalizedPath());
self::assertEquals('path', (string) (new PathTest_Path('./any/../path/.'))->getNormalizedPath());
self::assertEquals('/', (string) (new PathTest_Path('/..'))->getNormalizedPath());
self::assertEquals('../any/path', (string) (new PathTest_Path('.\\..\\any\\path'))->getNormalizedPath());
self::assertEquals('any/path', (string) (new PathTest_Path('any\\path'))->getNormalizedPath());
self::assertEquals('/any/path', (string) (new PathTest_Path('/any/path/'))->getNormalizedPath());
self::assertEquals('any/path', (string) (new PathTest_Path('any/path/'))->getNormalizedPath());
self::assertSame('/any/path', (string) (new PathTest_Path('/any/path'))->getNormalizedPath());
self::assertSame('any/path', (string) (new PathTest_Path('any/path'))->getNormalizedPath());
self::assertSame('any/path', (string) (new PathTest_Path('./any/path'))->getNormalizedPath());
self::assertSame('any/path', (string) (new PathTest_Path('././any/path'))->getNormalizedPath());
self::assertSame('../any/path', (string) (new PathTest_Path('./../any/path'))->getNormalizedPath());
self::assertSame('path', (string) (new PathTest_Path('./any/../path'))->getNormalizedPath());
self::assertSame('', (string) (new PathTest_Path('./'))->getNormalizedPath());
self::assertSame('', (string) (new PathTest_Path('.'))->getNormalizedPath());
self::assertSame('..', (string) (new PathTest_Path('../'))->getNormalizedPath());
self::assertSame('..', (string) (new PathTest_Path('..'))->getNormalizedPath());
self::assertSame('path', (string) (new PathTest_Path('./any/../path/.'))->getNormalizedPath());
self::assertSame('/', (string) (new PathTest_Path('/..'))->getNormalizedPath());
self::assertSame('../any/path', (string) (new PathTest_Path('.\\..\\any\\path'))->getNormalizedPath());
self::assertSame('any/path', (string) (new PathTest_Path('any\\path'))->getNormalizedPath());
self::assertSame('/any/path', (string) (new PathTest_Path('/any/path/'))->getNormalizedPath());
self::assertSame('any/path', (string) (new PathTest_Path('any/path/'))->getNormalizedPath());
}

public function testIsNormalized(): void {
Expand All @@ -76,19 +76,19 @@ public function testIsNormalized(): void {
}

public function testGetRelativePath(): void {
self::assertEquals(
self::assertSame(
'../to/file',
(string) (new PathTest_Path('/any/path'))->getRelativePath(new PathTest_Path('/any/path/../to/file')),
);
self::assertEquals(
self::assertSame(
'',
(string) (new PathTest_Path('/any/path'))->getRelativePath(new PathTest_Path('/any/path')),
);
self::assertEquals(
self::assertSame(
'to/file',
(string) (new PathTest_Path('/absolute/path'))->getRelativePath(new PathTest_Path('to/./file')),
);
self::assertEquals(
self::assertSame(
basename(__FILE__),
(string) (new PathTest_Path(__DIR__))->getRelativePath(new PathTest_Path(__FILE__)),
);
Expand All @@ -114,20 +114,20 @@ public function testGetFilePath(): void {
$relative = (new PathTest_Path('relative/path/to'))->getFilePath('file');
$absolute = (new PathTest_Path('/path/to'))->getFilePath('/file');

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

self::assertEquals('/file', (string) $absolute);
self::assertSame('/file', (string) $absolute);
}

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

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

self::assertEquals('/directory', (string) $absolute);
self::assertEquals('/path', (string) $null);
self::assertSame('/directory', (string) $absolute);
self::assertSame('/path', (string) $null);
}

public function testIsEqual(): void {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/Provider/WithRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Illuminate\Contracts\Routing\Registrar;
use Illuminate\Support\ServiceProvider;

use function assert;

/**
* @phpstan-require-extends ServiceProvider
*/
Expand Down Expand Up @@ -36,6 +38,8 @@ protected function bootRoutes(Closure $settings): void {
$routes = require $path;
$registrar = $this->app->make(Registrar::class);

assert($routes instanceof Closure);

$registrar->group($settings['attributes'], $routes);
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Utils/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function toStringable(mixed $value): Stringable|string {
}

/**
* @return iterable<array-key, mixed>
* @return iterable<mixed, mixed>
*/
public static function toIterable(mixed $value): iterable {
assert(is_iterable($value));
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/Utils/ConfigMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ protected function setStrict(bool $strict): static {
* @see ConfigMerger::Replace
* @see ConfigMerger::Strict
*
* @param array<array-key, mixed> $target
* @param array<array-key, mixed> $configs
* @template A of array-key
* @template B of array-key
*
* @param array<A, mixed> $target
* @param array<B, mixed> $configs
*
* @return array<array-key, mixed>
* @return array<A|B, mixed>
*/
public function merge(array $target, array ...$configs): array {
// Enable strict mode (just for case)
Expand All @@ -78,7 +81,7 @@ public function merge(array $target, array ...$configs): array {
$this->cleanup($target, true);

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

/**
Expand Down
Loading

0 comments on commit 8240f83

Please sign in to comment.