Skip to content

Commit a711afe

Browse files
committed
Add Psalm
1 parent 5bdaff8 commit a711afe

5 files changed

Lines changed: 45 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
pull_request:
66

77
env:
8+
PSALM_PHP_VERSION: "8.3"
89
COVERAGE_PHP_VERSION: "8.3"
910

1011
jobs:
@@ -56,3 +57,22 @@ jobs:
5657
env:
5758
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5859
if: ${{ matrix.php-version == env.COVERAGE_PHP_VERSION }}
60+
61+
psalm:
62+
name: Psalm
63+
runs-on: ubuntu-latest
64+
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v2
68+
69+
- name: Setup PHP
70+
uses: shivammathur/setup-php@v2
71+
with:
72+
php-version: ${{ env.PSALM_PHP_VERSION }}
73+
74+
- name: Install composer dependencies
75+
uses: "ramsey/composer-install@v1"
76+
77+
- name: Run Psalm
78+
run: vendor/bin/psalm --no-progress

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
},
1313
"require-dev": {
1414
"phpunit/phpunit": "^9.0",
15-
"php-coveralls/php-coveralls": "^2.0"
15+
"php-coveralls/php-coveralls": "^2.0",
16+
"vimeo/psalm": "5.17.0"
1617
},
1718
"autoload": {
1819
"psr-4": {

psalm.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
findUnusedBaselineEntry="true"
9+
findUnusedPsalmSuppress="true"
10+
findUnusedCode="false"
11+
>
12+
<projectFiles>
13+
<directory name="src" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
</psalm>

src/Formatter/GBFormatter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class GBFormatter implements CountryPostcodeFormatter
4747
/**
4848
* The regular expression patterns, or null if not built yet.
4949
*
50+
* @psalm-var non-empty-string[]|null
51+
*
5052
* @var string[]|null
5153
*/
5254
private $patterns = null;
@@ -86,6 +88,8 @@ public function format(string $postcode) : ?string
8688
* - The area code (ex: WC) for additional checks
8789
* - The inward code (e.g. 9RZ) for formatting
8890
*
91+
* @psalm-return non-empty-string[]
92+
*
8993
* @return string[]
9094
*/
9195
private function getPatterns() : array

src/PostcodeFormatter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ private function doGetFormatter(string $country): ?CountryPostcodeFormatter
8686
return null;
8787
}
8888

89+
/** @var class-string<CountryPostcodeFormatter> $class */
8990
$class = __NAMESPACE__ . '\\Formatter\\' . $country . 'Formatter';
9091

9192
return class_exists($class) ? new $class() : null;

0 commit comments

Comments
 (0)