From 5aa260ca2450d323bd45c3ef9bd30fb232e0dc6f Mon Sep 17 00:00:00 2001 From: Maarten Nusteling Date: Wed, 17 Jan 2024 22:20:33 +0100 Subject: [PATCH] Fixed workflow deprecation and updated PHPStan --- .github/workflows/build.yml | 4 ++-- composer.json | 2 +- src/Command/SearchCommand.php | 2 ++ src/Composer/PackageDefinition.php | 21 +++++++++++++++++---- tests/Author/AuthorCollectionTest.php | 2 +- tests/Composer/PackageDefinitionTest.php | 2 +- tests/Replace/ReplaceCollectionTest.php | 2 +- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f733be..d5ce722 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,10 +8,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: [ '7.2', '7.3', '7.4', '8.0' ] + php-versions: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] steps: - name: Setup PHP, with composer and extensions - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} diff --git a/composer.json b/composer.json index 5ee91b4..c4103ac 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ }, "require-dev": { "phpunit/phpunit": "^8.5", - "phpstan/phpstan": "^0.12.3" + "phpstan/phpstan": "^1.0" }, "autoload": { "psr-4": { diff --git a/src/Command/SearchCommand.php b/src/Command/SearchCommand.php index 8e727ce..4c4a890 100644 --- a/src/Command/SearchCommand.php +++ b/src/Command/SearchCommand.php @@ -38,6 +38,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in private function searchForPackage(): PackageInterface { $searchedPackage = $this->io->ask('What package do you want to lookup ? (TIP: you could also enter a part of a package name)'); + assert(is_string($searchedPackage)); $suggestedPackages = $this->suggestPackages((string)$searchedPackage); if ($suggestedPackages->isEmpty()) { @@ -59,6 +60,7 @@ private function searchForPackage(): PackageInterface )); $choice = $this->io->choice('What package would you like to view ?', $options); + assert(is_string($choice)); if (null !== $choice && 'Search again' !== $choice) { return $this->graph->getPackage($choice); diff --git a/src/Composer/PackageDefinition.php b/src/Composer/PackageDefinition.php index 752c862..6180043 100644 --- a/src/Composer/PackageDefinition.php +++ b/src/Composer/PackageDefinition.php @@ -31,6 +31,7 @@ public function __construct(array $definition, string $source) public static function createFromFile(SplFileInfo $file): self { $definition = json_decode($file->getContents(), true); + assert(is_array($definition)); return new PackageDefinition($definition, $file->getPath()); } @@ -56,7 +57,10 @@ public function getPackageDirectory(): string */ public function getAuthors(): array { - return $this->definition['authors'] ?? []; + $authors = $this->definition['authors'] ?? []; + assert(is_array($authors)); + + return $authors; } /** @@ -64,7 +68,10 @@ public function getAuthors(): array */ public function getDependencies(): array { - return $this->definition['require'] ?? []; + $dependencies = $this->definition['require'] ?? []; + assert(is_array($dependencies)); + + return $dependencies; } /** @@ -72,7 +79,10 @@ public function getDependencies(): array */ public function getDevDependencies(): array { - return $this->definition['require-dev'] ?? []; + $dependencies = $this->definition['require-dev'] ?? []; + assert(is_array($dependencies)); + + return $dependencies; } /** @@ -80,6 +90,9 @@ public function getDevDependencies(): array */ public function getReplaces(): array { - return $this->definition['replace'] ?? []; + $replace = $this->definition['replace'] ?? []; + assert(is_array($replace)); + + return $replace; } } diff --git a/tests/Author/AuthorCollectionTest.php b/tests/Author/AuthorCollectionTest.php index 8ae24fd..cbc2e63 100644 --- a/tests/Author/AuthorCollectionTest.php +++ b/tests/Author/AuthorCollectionTest.php @@ -7,7 +7,7 @@ use Nusje2000\DependencyGraph\Author\Author; use Nusje2000\DependencyGraph\Author\AuthorCollection; use Nusje2000\DependencyGraph\Exception\AuthorException; -use PHPStan\Testing\TestCase; +use PHPUnit\Framework\TestCase; final class AuthorCollectionTest extends TestCase { diff --git a/tests/Composer/PackageDefinitionTest.php b/tests/Composer/PackageDefinitionTest.php index e83fa87..cad299d 100644 --- a/tests/Composer/PackageDefinitionTest.php +++ b/tests/Composer/PackageDefinitionTest.php @@ -6,7 +6,7 @@ use Nusje2000\DependencyGraph\Composer\PackageDefinition; use Nusje2000\DependencyGraph\Exception\DefinitionException; -use PHPStan\Testing\TestCase; +use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\SplFileInfo; final class PackageDefinitionTest extends TestCase diff --git a/tests/Replace/ReplaceCollectionTest.php b/tests/Replace/ReplaceCollectionTest.php index f506f38..4343274 100644 --- a/tests/Replace/ReplaceCollectionTest.php +++ b/tests/Replace/ReplaceCollectionTest.php @@ -7,7 +7,7 @@ use Nusje2000\DependencyGraph\Exception\ReplaceException; use Nusje2000\DependencyGraph\Replace\Replace; use Nusje2000\DependencyGraph\Replace\ReplaceCollection; -use PHPStan\Testing\TestCase; +use PHPUnit\Framework\TestCase; final class ReplaceCollectionTest extends TestCase {