Skip to content

Commit 35a235f

Browse files
author
Heiko Jerichen
committed
Add psalm for static code analysis.
1 parent 0405ad7 commit 35a235f

17 files changed

+107
-17
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,37 @@ jobs:
5555
- name: Run Tests
5656
run: vendor/bin/phpunit
5757

58+
psalm:
59+
name: Psalm
60+
runs-on: ubuntu-latest
61+
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v4
65+
66+
- name: Install PHP
67+
uses: shivammathur/[email protected]
68+
with:
69+
php-version: 8.2
70+
coverage: none
71+
72+
- name: Get Composer Cache Directory
73+
id: composer-cache
74+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
75+
76+
- name: Cache dependencies
77+
uses: actions/cache@v3
78+
with:
79+
path: ${{ steps.composer-cache.outputs.dir }}
80+
key: ${{ runner.os }}-psalm-composer-${{ hashFiles('**/composer.json') }}
81+
restore-keys: ${{ runner.os }}-psalm-composer-
82+
83+
- name: Install Dependencies
84+
run: composer update
85+
86+
- name: Run psalm
87+
run: vendor/bin/psalm --output-format=github
88+
5889
coverage:
5990
runs-on: ubuntu-latest
6091
name: Code Coverage

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"require-dev": {
2424
"roave/security-advisories": "dev-latest",
2525
"phpunit/phpunit": "^9.6.21 | ^10.0 | ^11.0",
26-
"phpspec/prophecy-phpunit": "^2.0"
26+
"phpspec/prophecy-phpunit": "^2.0",
27+
"vimeo/psalm": "^6.1",
28+
"psalm/plugin-phpunit": "^0.19.2"
2729
}
2830
}

psalm.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<!--suppress XmlDefaultAttributeValue -->
3+
<psalm
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns="https://getpsalm.org/schema/config"
6+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
errorLevel="1"
8+
findUnusedBaselineEntry="true"
9+
findUnusedCode="true"
10+
>
11+
<projectFiles>
12+
<directory name="src"/>
13+
<directory name="tests"/>
14+
<ignoreFiles>
15+
<directory name="vendor/phpunit"/>
16+
</ignoreFiles>
17+
</projectFiles>
18+
<issueHandlers>
19+
<RedundantPropertyInitializationCheck errorLevel="suppress"/>
20+
<PropertyNotSetInConstructor errorLevel="suppress"/>
21+
<MissingConstructor errorLevel="suppress"/>
22+
<InvalidDocblock errorLevel="suppress"/>
23+
</issueHandlers>
24+
<plugins>
25+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
26+
</plugins>
27+
</psalm>

src/FunctionDelegation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class FunctionDelegation
1212
/**
1313
* @return mixed
1414
* @noinspection PhpReturnDocTypeMismatchInspection
15+
* @psalm-suppress InvalidReturnType, PossiblyUnusedParam
1516
*/
1617
public function delegate(string $functionName, array $arguments)
1718
{

src/FunctionProphecy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function getFunctionName(): string
3535

3636
public function scoreArguments(array $arguments): int
3737
{
38-
return $this->argumentEvaluator->scoreArguments($arguments) ?: 0;
38+
$score = $this->argumentEvaluator->scoreArguments($arguments);
39+
return $score === false ? 0 : $score;
3940
}
4041

4142
public function makeCall(): mixed

src/FunctionProphecyStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FunctionProphecyStorage
1111
{
1212
private static self $instance;
1313

14-
/** @var FunctionProphecy[][][] */
14+
/** @var array<string,array<string,array<string,FunctionProphecy>>> */
1515
private array $functionProphecies = [];
1616

1717
public static function getInstance(): FunctionProphecyStorage

src/FunctionRevealer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct(
1515
) {
1616
}
1717

18+
/** @psalm-suppress PossiblyUnusedParam */
1819
public function revealFunction(string $namespace, string $functionName): void
1920
{
2021
if ($this->isFunctionAlreadyRevealed($namespace, $functionName)) {

src/NamespaceProphecy.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/**
1010
* @author Heiko Jerichen <[email protected]>
11+
* @template-implements ProphecyInterface<self>
1112
*/
1213
readonly class NamespaceProphecy implements ProphecyInterface
1314
{
@@ -47,12 +48,13 @@ public function prepare(string ...$functionNames): void
4748
/**
4849
* Reveals prophecy object (double) .
4950
*/
50-
public function reveal(): void
51+
public function reveal(): self
5152
{
5253
$functionNames = $this->functionProphecyStorage->getFunctionNamesOfSetProphecies($this->namespace);
5354
foreach ($functionNames as $functionName) {
5455
$this->functionRevealer->revealFunction($this->namespace, $functionName);
5556
}
57+
return $this;
5658
}
5759

5860
public function unReveal(): void

src/PHPBuiltInFunctions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ public function getmypid(): MethodProphecy
400400
* </p>
401401
* @return MethodProphecy
402402
* @noinspection PhpUnusedParameterInspection
403+
* @psalm-suppress PossiblyUnusedParam
403404
*/
404405
public function exit($status = null): MethodProphecy
405406
{
@@ -422,6 +423,7 @@ public function exit($status = null): MethodProphecy
422423
* </p>
423424
* @return MethodProphecy
424425
* @noinspection PhpUnusedParameterInspection
426+
* @psalm-suppress PossiblyUnusedParam
425427
*/
426428
public function die($status = "") : MethodProphecy
427429
{

0 commit comments

Comments
 (0)