diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..88be9bf --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,10 @@ +name: PHPStan + +on: + push + +jobs: + phpstan: + uses: stefanzweifel/reusable-workflows/.github/workflows/phpstan.yml@main + with: + php_version: '8.3' diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml deleted file mode 100644 index b18170b..0000000 --- a/.github/workflows/psalm.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Psalm - -on: - push: - paths: - - '**.php' - - 'psalm.xml' - -jobs: - psalm: - name: psalm - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - - - name: Run composer install - run: composer install -n --prefer-dist - - - name: Run psalm - run: ./vendor/bin/psalm diff --git a/composer.json b/composer.json index e231e29..669c604 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,10 @@ "require-dev": { "phpunit/phpunit": "^10.1", "friendsofphp/php-cs-fixer": "^3", - "vimeo/psalm": "^5.0", "league/csv": "^9.7", "symfony/console": "^6.0", - "rector/rector": "^0.15.24" + "rector/rector": "^0.15.24", + "phpstan/phpstan": "^1.10" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..46b0f47 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 5 + paths: + - src + - tests diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 30258a7..0000000 --- a/psalm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - diff --git a/src/Exceptions/CantonException.php b/src/Exceptions/CantonException.php index 7b49ef4..e390ac4 100644 --- a/src/Exceptions/CantonException.php +++ b/src/Exceptions/CantonException.php @@ -8,16 +8,19 @@ class CantonException extends Exception { public static function notFoundForAbbreviation(string $abbreviation): self { + /** @phpstan-ignore-next-line */ return new static("Couldn't find Canton for given abbreviation: {$abbreviation}"); } public static function notFoundForName(string $name): self { + /** @phpstan-ignore-next-line */ return new static("Couldn't find Canton for given name: {$name}"); } public static function notFoundForZipcode(int $zipcode): self { + /** @phpstan-ignore-next-line */ return new static("Couldn't find Canton for given zipcode: {$zipcode}"); } } diff --git a/tests/CantonManagerTest.php b/tests/CantonManagerTest.php index a7bb825..c71532a 100644 --- a/tests/CantonManagerTest.php +++ b/tests/CantonManagerTest.php @@ -10,7 +10,7 @@ class CantonManagerTest extends TestCase { #[Test] - public function it_returns_correct_canton_instance_for_abbreviation() + public function it_returns_correct_canton_instance_for_abbreviation(): void { $canton = new CantonManager(); $canton = $canton->getByAbbreviation('ZH'); @@ -22,7 +22,7 @@ public function it_returns_correct_canton_instance_for_abbreviation() } #[Test] - public function it_returns_correct_canton_if_abbreviation_is_lowercase() + public function it_returns_correct_canton_if_abbreviation_is_lowercase(): void { $cantonManager = new CantonManager(); @@ -46,7 +46,7 @@ public function it_returns_correct_canton_if_abbreviation_is_lowercase() } #[Test] - public function it_throws_exception_if_no_canton_for_abbreviation_is_found() + public function it_throws_exception_if_no_canton_for_abbreviation_is_found(): void { $this->expectException(CantonException::class); @@ -55,7 +55,7 @@ public function it_throws_exception_if_no_canton_for_abbreviation_is_found() } #[Test] - public function it_returns_correct_canton_instance_for_name() + public function it_returns_correct_canton_instance_for_name(): void { $canton = new CantonManager(); $result = $canton->getByName('Zürich'); @@ -64,7 +64,7 @@ public function it_returns_correct_canton_instance_for_name() } #[Test] - public function it_throws_exception_if_not_canton_for_name_is_found() + public function it_throws_exception_if_not_canton_for_name_is_found(): void { $this->expectException(CantonException::class); @@ -73,7 +73,7 @@ public function it_throws_exception_if_not_canton_for_name_is_found() } #[Test] - public function it_returns_canton_for_zipcode() + public function it_returns_canton_for_zipcode(): void { $canton = new CantonManager(); $result = $canton->getByZipcode(3005); @@ -84,7 +84,7 @@ public function it_returns_canton_for_zipcode() } #[Test] - public function it_throws_exception_if_no_canton_for_zipcode_could_be_found() + public function it_throws_exception_if_no_canton_for_zipcode_could_be_found(): void { $this->expectException(CantonException::class); @@ -93,7 +93,7 @@ public function it_throws_exception_if_no_canton_for_zipcode_could_be_found() } #[Test] - public function it_throws_exception_if_lichtenstein_zipcode_is_searched_for() + public function it_throws_exception_if_lichtenstein_zipcode_is_searched_for(): void { $this->expectException(CantonException::class); diff --git a/tests/CantonSearchTest.php b/tests/CantonSearchTest.php index b09476d..9b09bde 100644 --- a/tests/CantonSearchTest.php +++ b/tests/CantonSearchTest.php @@ -10,7 +10,7 @@ class CantonSearchTest extends TestCase { #[Test] - public function it_finds_canton_by_abbreviation() + public function it_finds_canton_by_abbreviation(): void { $cantonSearch = new CantonSearch(); $canton = $cantonSearch->findByAbbreviation('SH'); @@ -20,7 +20,7 @@ public function it_finds_canton_by_abbreviation() } #[Test] - public function it_returns_null_if_no_canton_for_abbreviation_was_found() + public function it_returns_null_if_no_canton_for_abbreviation_was_found(): void { $cantonSearch = new CantonSearch(); $canton = $cantonSearch->findByAbbreviation('foo'); @@ -29,7 +29,7 @@ public function it_returns_null_if_no_canton_for_abbreviation_was_found() } #[Test] - public function it_finds_canton_by_name() + public function it_finds_canton_by_name(): void { $cantonSearch = new CantonSearch(); $canton = $cantonSearch->findByName('Zürich'); @@ -40,7 +40,7 @@ public function it_finds_canton_by_name() } #[Test] - public function it_returns_null_if_no_canton_for_name_was_found() + public function it_returns_null_if_no_canton_for_name_was_found(): void { $cantonSearch = new CantonSearch(); $canton = $cantonSearch->findByName('foo'); diff --git a/tests/CantonTest.php b/tests/CantonTest.php index c68d167..8c5d9d1 100644 --- a/tests/CantonTest.php +++ b/tests/CantonTest.php @@ -24,7 +24,7 @@ protected function getExampleCanton(): array } #[Test] - public function it_sets_language() + public function it_sets_language(): void { $canton = new Canton($this->getExampleCanton()); $canton->setLanguage('fr'); @@ -33,7 +33,7 @@ public function it_sets_language() } #[Test] - public function it_transformers_uppercase_language_string_to_lowercase() + public function it_transformers_uppercase_language_string_to_lowercase(): void { $canton = new Canton($this->getExampleCanton()); $canton->setLanguage('DE'); @@ -42,7 +42,7 @@ public function it_transformers_uppercase_language_string_to_lowercase() } #[Test] - public function it_only_allows_national_languages() + public function it_only_allows_national_languages(): void { $this->expectException(InvalidLanguageException::class); @@ -51,7 +51,7 @@ public function it_only_allows_national_languages() } #[Test] - public function it_sets_and_returns_abbreviation() + public function it_sets_and_returns_abbreviation(): void { $canton = new Canton($this->getExampleCanton()); @@ -59,7 +59,7 @@ public function it_sets_and_returns_abbreviation() } #[Test] - public function it_sets_names_array() + public function it_sets_names_array(): void { $canton = new Canton($this->getExampleCanton()); @@ -70,7 +70,7 @@ public function it_sets_names_array() } #[Test] - public function it_returns_correct_name_for_given_language() + public function it_returns_correct_name_for_given_language(): void { $canton = new Canton($this->getExampleCanton()); diff --git a/tests/CantonsTest.php b/tests/CantonsTest.php index 96016e5..3d44289 100644 --- a/tests/CantonsTest.php +++ b/tests/CantonsTest.php @@ -10,7 +10,7 @@ class CantonsTest extends TestCase { #[Test] - public function it_returns_json_source_as_array() + public function it_returns_json_source_as_array(): void { $cantons = new Cantons(); @@ -18,7 +18,7 @@ public function it_returns_json_source_as_array() } #[Test] - public function it_contains_abbreviation_and_name() + public function it_contains_abbreviation_and_name(): void { $cantons = (new Cantons())->getAll(); @@ -31,7 +31,7 @@ public function it_contains_abbreviation_and_name() } #[Test] - public function it_returns_an_array_with_abbreviation_as_key_and_name_as_value() + public function it_returns_an_array_with_abbreviation_as_key_and_name_as_value(): void { $cantons = (new Cantons())->getAllAsArray(); @@ -43,7 +43,7 @@ public function it_returns_an_array_with_abbreviation_as_key_and_name_as_value() } #[Test] - public function it_returns_an_array_with_abbreviation_and_name_but_in_a_different_language() + public function it_returns_an_array_with_abbreviation_and_name_but_in_a_different_language(): void { $cantons = (new Cantons())->getAllAsArray('de'); @@ -55,7 +55,7 @@ public function it_returns_an_array_with_abbreviation_and_name_but_in_a_differen } #[Test] - public function it_throws_an_exception_if_passed_langauge_is_not_available() + public function it_throws_an_exception_if_passed_langauge_is_not_available(): void { $this->expectException(Exception::class); diff --git a/tests/ZipcodeSearchTest.php b/tests/ZipcodeSearchTest.php index 0413e6d..f15a5a3 100644 --- a/tests/ZipcodeSearchTest.php +++ b/tests/ZipcodeSearchTest.php @@ -9,7 +9,7 @@ class ZipcodeSearchTest extends TestCase { #[Test] - public function it_returns_dataset_as_array() + public function it_returns_dataset_as_array(): void { $cantonSearch = new ZipcodeSearch(); @@ -17,7 +17,7 @@ public function it_returns_dataset_as_array() } #[Test] - public function it_finds_canton_by_zipcode() + public function it_finds_canton_by_zipcode(): void { $zipcodeSearch = new ZipcodeSearch(); @@ -29,7 +29,7 @@ public function it_finds_canton_by_zipcode() } #[Test] - public function it_does_not_find_result_for_not_available_zipcode() + public function it_does_not_find_result_for_not_available_zipcode(): void { $zipcodeSearch = new ZipcodeSearch(); @@ -39,7 +39,7 @@ public function it_does_not_find_result_for_not_available_zipcode() } #[Test] - public function it_does_not_find_liechtenstein_zipcodes() + public function it_does_not_find_liechtenstein_zipcodes(): void { $zipcodeSearch = new ZipcodeSearch();