Skip to content

Commit

Permalink
Replace Psalm with Phpstan (#45)
Browse files Browse the repository at this point in the history
* Remove Psalm

* Add phpstan

* Add Return Type to Tests

* Add Phpstan Workflow

* Ignore static calls in Exception
  • Loading branch information
stefanzweifel authored Apr 1, 2024
1 parent b771695 commit f895d8e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 70 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: PHPStan

on:
push

jobs:
phpstan:
uses: stefanzweifel/reusable-workflows/.github/workflows/phpstan.yml@main
with:
php_version: '8.3'
26 changes: 0 additions & 26 deletions .github/workflows/psalm.yml

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 5
paths:
- src
- tests
15 changes: 0 additions & 15 deletions psalm.xml

This file was deleted.

3 changes: 3 additions & 0 deletions src/Exceptions/CantonException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
16 changes: 8 additions & 8 deletions tests/CantonManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();

Expand All @@ -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);

Expand All @@ -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');
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions tests/CantonSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down
12 changes: 6 additions & 6 deletions tests/CantonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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);

Expand All @@ -51,15 +51,15 @@ 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());

$this->assertEquals('ZH', $canton->getAbbreviation());
}

#[Test]
public function it_sets_names_array()
public function it_sets_names_array(): void
{
$canton = new Canton($this->getExampleCanton());

Expand All @@ -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());

Expand Down
10 changes: 5 additions & 5 deletions tests/CantonsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
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();

$this->assertTrue(is_array($cantons->getAll()));
}

#[Test]
public function it_contains_abbreviation_and_name()
public function it_contains_abbreviation_and_name(): void
{
$cantons = (new Cantons())->getAll();

Expand All @@ -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();

Expand All @@ -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');

Expand All @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions tests/ZipcodeSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
class ZipcodeSearchTest extends TestCase
{
#[Test]
public function it_returns_dataset_as_array()
public function it_returns_dataset_as_array(): void
{
$cantonSearch = new ZipcodeSearch();

$this->assertIsArray($cantonSearch->getDataSet());
}

#[Test]
public function it_finds_canton_by_zipcode()
public function it_finds_canton_by_zipcode(): void
{
$zipcodeSearch = new ZipcodeSearch();

Expand All @@ -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();

Expand All @@ -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();

Expand Down

0 comments on commit f895d8e

Please sign in to comment.