Skip to content

Commit 916ba51

Browse files
committed
Add static analysis with Psalm
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 2a4b6cb commit 916ba51

File tree

4 files changed

+183
-2
lines changed

4 files changed

+183
-2
lines changed

.github/workflows/lint-and-analyse-php.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,9 @@ jobs:
4444
with:
4545
dependency-versions: highest
4646

47-
- name: Analyse files
47+
- name: Analyse files with PHPStan
4848
run: composer run phpstan
49+
50+
- name: Analyse files with Psalm
51+
if: always()
52+
run: composer run psalm -- --shepherd

composer.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
"phpcs": "@php phpcs",
2121
"phpstan": "@php phpstan analyse",
2222
"phpunit": "@php phpunit --color=always",
23+
"psalm": "@php psalm",
2324
"test": [
2425
"@phpcs",
2526
"@phpstan",
27+
"@psalm",
2628
"@phpunit"
2729
],
2830
"update:baselines": [
@@ -41,7 +43,9 @@
4143
"phpstan/phpstan": "^1.10",
4244
"phpstan/phpstan-phpunit": "^1.3",
4345
"phpstan/phpstan-strict-rules": "^1.5",
44-
"phpunit/phpunit": "^10.3"
46+
"phpunit/phpunit": "^10.3",
47+
"psalm/plugin-phpunit": "^0.18.4",
48+
"vimeo/psalm": "^5.15"
4549
},
4650
"autoload": {
4751
"psr-4": {

psalm-baseline.xml

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
3+
<file src="src/ShapeFile.php">
4+
<InvalidPropertyAssignmentValue>
5+
<code><![CDATA[$this->shpFile]]></code>
6+
<code><![CDATA[$this->shxFile]]></code>
7+
</InvalidPropertyAssignmentValue>
8+
<MixedArgument>
9+
<code><![CDATA[$record->dbfData[$field]]]></code>
10+
<code><![CDATA[$this->boundingBox[$type] ?? 0]]></code>
11+
</MixedArgument>
12+
<MixedAssignment>
13+
<code>$shapeType</code>
14+
</MixedAssignment>
15+
<PossiblyFalseArgument>
16+
<code><![CDATA[$this->shpFile]]></code>
17+
</PossiblyFalseArgument>
18+
<PossiblyNullOperand>
19+
<code><![CDATA[$record->getContentLength()]]></code>
20+
<code><![CDATA[$record->getContentLength()]]></code>
21+
<code><![CDATA[$this->records[$index]->getContentLength()]]></code>
22+
</PossiblyNullOperand>
23+
<PossiblyUnusedReturnValue>
24+
<code>bool</code>
25+
<code>bool</code>
26+
<code>int</code>
27+
</PossiblyUnusedReturnValue>
28+
<UnusedFunctionCall>
29+
<code>dbase_close</code>
30+
<code>dbase_pack</code>
31+
</UnusedFunctionCall>
32+
</file>
33+
<file src="src/ShapeRecord.php">
34+
<MixedArgument>
35+
<code><![CDATA[$data['m']]]></code>
36+
<code><![CDATA[$data['m']]]></code>
37+
<code><![CDATA[$data['x']]]></code>
38+
<code><![CDATA[$data['x']]]></code>
39+
<code><![CDATA[$data['x']]]></code>
40+
<code><![CDATA[$data['y']]]></code>
41+
<code><![CDATA[$data['y']]]></code>
42+
<code><![CDATA[$data['y']]]></code>
43+
<code><![CDATA[$data['z']]]></code>
44+
<code>$pointData</code>
45+
<code>$pointData[$type]</code>
46+
<code><![CDATA[$this->shpData['parts']]]></code>
47+
<code><![CDATA[$this->shpData['parts']]]></code>
48+
<code><![CDATA[$this->shpData['parts']]]></code>
49+
<code><![CDATA[$this->shpData['parts']]]></code>
50+
<code><![CDATA[$this->shpData['parts']]]></code>
51+
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
52+
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
53+
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
54+
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
55+
<code><![CDATA[$this->shpData['parts'][$partIndex]['points']]]></code>
56+
<code><![CDATA[$this->shpData['parts'][$partIndex]['points']]]></code>
57+
<code><![CDATA[$this->shpData['points']]]></code>
58+
<code><![CDATA[$this->shpData['points']]]></code>
59+
<code><![CDATA[$this->shpData['points']]]></code>
60+
<code><![CDATA[$this->shpData['points']]]></code>
61+
<code><![CDATA[$this->shpData['points']]]></code>
62+
<code><![CDATA[$this->shpData['points'][$i]]]></code>
63+
<code><![CDATA[$this->shpData['points'][$i][$type]]]></code>
64+
</MixedArgument>
65+
<MixedArrayAccess>
66+
<code><![CDATA[$partData['points']]]></code>
67+
<code><![CDATA[$partData['points']]]></code>
68+
<code>$pointData[$type]</code>
69+
<code><![CDATA[$this->shpData['parts'][$i]]]></code>
70+
<code><![CDATA[$this->shpData['parts'][$i]]]></code>
71+
<code><![CDATA[$this->shpData['parts'][$i]]]></code>
72+
<code><![CDATA[$this->shpData['parts'][$i]]]></code>
73+
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
74+
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
75+
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
76+
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
77+
<code><![CDATA[$this->shpData['parts'][$part + 1]]]></code>
78+
<code><![CDATA[$this->shpData['parts'][$partIndex]['points'][$count]]]></code>
79+
<code><![CDATA[$this->shpData['parts'][$partIndex]['points'][$i + 1]]]></code>
80+
<code><![CDATA[$this->shpData['points'][$i + 1]]]></code>
81+
<code><![CDATA[$this->shpData['points'][$i]]]></code>
82+
<code><![CDATA[$this->shpData['points'][$i]]]></code>
83+
<code><![CDATA[$this->shpData['points'][$i][$type]]]></code>
84+
<code><![CDATA[$this->shpData['points'][count($this->shpData['points']) - 1]]]></code>
85+
<code>$value</code>
86+
</MixedArrayAccess>
87+
<MixedArrayAssignment>
88+
<code><![CDATA[$this->shpData['parts'][$partIndex]]]></code>
89+
<code><![CDATA[$this->shpData['parts'][$partIndex]]]></code>
90+
<code><![CDATA[$this->shpData['parts'][$partIndex]['points']]]></code>
91+
<code><![CDATA[$this->shpData['parts'][$partIndex]['points'][$i]]]></code>
92+
<code><![CDATA[$this->shpData['parts'][$part]]]></code>
93+
<code><![CDATA[$this->shpData['parts'][$part]['points']]]></code>
94+
<code><![CDATA[$this->shpData['parts'][$part]['points'][$i]]]></code>
95+
<code><![CDATA[$this->shpData['parts'][$part]['points'][$i][$type]]]></code>
96+
<code><![CDATA[$this->shpData['parts'][$part]['points'][]]]></code>
97+
<code><![CDATA[$this->shpData['points'][$i]]]></code>
98+
<code><![CDATA[$this->shpData['points'][$i]]]></code>
99+
<code><![CDATA[$this->shpData['points'][$i][$type]]]></code>
100+
<code><![CDATA[$this->shpData['points'][]]]></code>
101+
</MixedArrayAssignment>
102+
<MixedArrayOffset>
103+
<code><![CDATA[$this->dbfData[$value]]]></code>
104+
<code>$tmp[$value]</code>
105+
</MixedArrayOffset>
106+
<MixedAssignment>
107+
<code><![CDATA[$data['m']]]></code>
108+
<code><![CDATA[$data['m']]]></code>
109+
<code><![CDATA[$data['z']]]></code>
110+
<code>$numparts</code>
111+
<code>$numparts</code>
112+
<code>$numpoints</code>
113+
<code>$numpoints</code>
114+
<code>$partData</code>
115+
<code>$partData</code>
116+
<code>$point</code>
117+
<code>$pointData</code>
118+
<code>$pointData</code>
119+
<code><![CDATA[$point['m']]]></code>
120+
<code><![CDATA[$point['m']]]></code>
121+
<code><![CDATA[$point['z']]]></code>
122+
<code>$recordNumber</code>
123+
<code>$shapeType</code>
124+
<code>$size</code>
125+
<code><![CDATA[$this->size]]></code>
126+
<code>[$value]</code>
127+
</MixedAssignment>
128+
<MixedOperand>
129+
<code>$size</code>
130+
<code><![CDATA[$this->shpData['numpoints']]]></code>
131+
<code><![CDATA[$this->shpData['numpoints']]]></code>
132+
<code><![CDATA[$this->shpData['numpoints'] ?? 0]]></code>
133+
<code><![CDATA[$this->shpData['numpoints'] ?? 0]]></code>
134+
</MixedOperand>
135+
<PossiblyNullReference>
136+
<code>hasMeasure</code>
137+
<code>hasMeasure</code>
138+
<code>readSHP</code>
139+
</PossiblyNullReference>
140+
<PossiblyUndefinedArrayOffset>
141+
<code><![CDATA[$this->shpData['parts']]]></code>
142+
</PossiblyUndefinedArrayOffset>
143+
<PropertyNotSetInConstructor>
144+
<code>$shpFile</code>
145+
</PropertyNotSetInConstructor>
146+
</file>
147+
<file src="tests/ShapeFileTest.php">
148+
<MixedArgument>
149+
<code><![CDATA[$shp->records[0]->shpData['parts']]]></code>
150+
</MixedArgument>
151+
</file>
152+
</files>

psalm.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
4+
xmlns="https://getpsalm.org/schema/config"
5+
errorLevel="1"
6+
reportMixedIssues="true"
7+
resolveFromConfigFile="true"
8+
findUnusedBaselineEntry="true"
9+
findUnusedCode="true"
10+
errorBaseline="psalm-baseline.xml">
11+
<projectFiles>
12+
<directory name="src"/>
13+
<directory name="tests"/>
14+
<ignoreFiles>
15+
<directory name="vendor"/>
16+
</ignoreFiles>
17+
</projectFiles>
18+
<plugins>
19+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
20+
</plugins>
21+
</psalm>

0 commit comments

Comments
 (0)