Skip to content

Commit c60e6bf

Browse files
authored
Merge pull request #40 from ConvertKit/phpstan
Added PHPStan for Static Analysis
2 parents 9521ed2 + 2535220 commit c60e6bf

File tree

4 files changed

+118
-53
lines changed

4 files changed

+118
-53
lines changed

TESTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ If your work fixes existing functionality, check if a test exists. Either update
2222

2323
Tests are written in PHP using [PHPUnit](https://phpunit.de/), and the existing `tests/ConvertKitAPITest.php` is a good place to start as a guide.
2424

25+
## Run PHPStan
26+
27+
[PHPStan](https://phpstan.org) performs static analysis on the Plugin's PHP code. This ensures:
28+
29+
- DocBlocks declarations are valid and uniform
30+
- DocBlocks declarations for WordPress `do_action()` and `apply_filters()` calls are valid
31+
- Typehinting variables and return types declared in DocBlocks are correctly cast
32+
- Any unused functions are detected
33+
- Unnecessary checks / code is highlighted for possible removal
34+
- Conditions that do not evaluate can be fixed/removed as necessary
35+
36+
In the Plugin's directory, run the following command to run PHPStan:
37+
38+
```bash
39+
vendor/bin/phpstan --memory-limit=1G
40+
```
41+
42+
Any errors should be corrected by making applicable code changes.
43+
44+
False positives [can be excluded by configuring](https://phpstan.org/user-guide/ignoring-errors) the `phpstan.neon` file.
45+
2546
## Run PHPUnit
2647

2748
Once you have written your code and tests, run the tests to make sure there are no errors.

phpstan.neon.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Parameters
2+
parameters:
3+
# Paths to scan
4+
paths:
5+
- src/
6+
7+
# Should not need to edit anything below here
8+
# Rule Level: https://phpstan.org/user-guide/rule-levels
9+
level: 8
10+
11+
# Ignore the following errors, as PHPStan either does not have registered symbols for them yet,
12+
# or the symbols are inaccurate.
13+
ignoreErrors:
14+
- '#\$headers of class GuzzleHttp\\Psr7\\Request constructor expects#'

phpstan.neon.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Parameters
2+
parameters:
3+
# Paths to scan
4+
paths:
5+
- src/
6+
7+
# Should not need to edit anything below here
8+
# Rule Level: https://phpstan.org/user-guide/rule-levels
9+
level: 8
10+
11+
# Ignore the following errors, as PHPStan either does not have registered symbols for them yet,
12+
# or the symbols are inaccurate.
13+
ignoreErrors:
14+
- '#\$headers of class GuzzleHttp\\Psr7\\Request constructor expects#'

0 commit comments

Comments
 (0)