Skip to content

Commit

Permalink
Merge pull request #27 from MauricioFauth/psalm
Browse files Browse the repository at this point in the history
Add static analysis with Psalm
  • Loading branch information
MauricioFauth committed Sep 14, 2023
2 parents 2f63b77 + 916ba51 commit ab4a803
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/lint-and-analyse-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ jobs:
with:
dependency-versions: highest

- name: Analyse files
- name: Analyse files with PHPStan
run: composer run phpstan

- name: Analyse files with Psalm
if: always()
run: composer run psalm -- --shepherd
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
"phpcs": "@php phpcs",
"phpstan": "@php phpstan analyse",
"phpunit": "@php phpunit --color=always",
"psalm": "@php psalm",
"test": [
"@phpcs",
"@phpstan",
"@psalm",
"@phpunit"
],
"update:baselines": [
Expand All @@ -41,7 +43,9 @@
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^10.3"
"phpunit/phpunit": "^10.3",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.15"
},
"autoload": {
"psr-4": {
Expand Down
152 changes: 152 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/ShapeFile.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[$this->shpFile]]></code>
<code><![CDATA[$this->shxFile]]></code>
</InvalidPropertyAssignmentValue>
<MixedArgument>
<code><![CDATA[$record->dbfData[$field]]]></code>
<code><![CDATA[$this->boundingBox[$type] ?? 0]]></code>
</MixedArgument>
<MixedAssignment>
<code>$shapeType</code>
</MixedAssignment>
<PossiblyFalseArgument>
<code><![CDATA[$this->shpFile]]></code>
</PossiblyFalseArgument>
<PossiblyNullOperand>
<code><![CDATA[$record->getContentLength()]]></code>
<code><![CDATA[$record->getContentLength()]]></code>
<code><![CDATA[$this->records[$index]->getContentLength()]]></code>
</PossiblyNullOperand>
<PossiblyUnusedReturnValue>
<code>bool</code>
<code>bool</code>
<code>int</code>
</PossiblyUnusedReturnValue>
<UnusedFunctionCall>
<code>dbase_close</code>
<code>dbase_pack</code>
</UnusedFunctionCall>
</file>
<file src="src/ShapeRecord.php">
<MixedArgument>
<code><![CDATA[$data['m']]]></code>
<code><![CDATA[$data['m']]]></code>
<code><![CDATA[$data['x']]]></code>
<code><![CDATA[$data['x']]]></code>
<code><![CDATA[$data['x']]]></code>
<code><![CDATA[$data['y']]]></code>
<code><![CDATA[$data['y']]]></code>
<code><![CDATA[$data['y']]]></code>
<code><![CDATA[$data['z']]]></code>
<code>$pointData</code>
<code>$pointData[$type]</code>
<code><![CDATA[$this->shpData['parts']]]></code>
<code><![CDATA[$this->shpData['parts']]]></code>
<code><![CDATA[$this->shpData['parts']]]></code>
<code><![CDATA[$this->shpData['parts']]]></code>
<code><![CDATA[$this->shpData['parts']]]></code>
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$partIndex]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$partIndex]['points']]]></code>
<code><![CDATA[$this->shpData['points']]]></code>
<code><![CDATA[$this->shpData['points']]]></code>
<code><![CDATA[$this->shpData['points']]]></code>
<code><![CDATA[$this->shpData['points']]]></code>
<code><![CDATA[$this->shpData['points']]]></code>
<code><![CDATA[$this->shpData['points'][$i]]]></code>
<code><![CDATA[$this->shpData['points'][$i][$type]]]></code>
</MixedArgument>
<MixedArrayAccess>
<code><![CDATA[$partData['points']]]></code>
<code><![CDATA[$partData['points']]]></code>
<code>$pointData[$type]</code>
<code><![CDATA[$this->shpData['parts'][$i]]]></code>
<code><![CDATA[$this->shpData['parts'][$i]]]></code>
<code><![CDATA[$this->shpData['parts'][$i]]]></code>
<code><![CDATA[$this->shpData['parts'][$i]]]></code>
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$i]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$part + 1]]]></code>
<code><![CDATA[$this->shpData['parts'][$partIndex]['points'][$count]]]></code>
<code><![CDATA[$this->shpData['parts'][$partIndex]['points'][$i + 1]]]></code>
<code><![CDATA[$this->shpData['points'][$i + 1]]]></code>
<code><![CDATA[$this->shpData['points'][$i]]]></code>
<code><![CDATA[$this->shpData['points'][$i]]]></code>
<code><![CDATA[$this->shpData['points'][$i][$type]]]></code>
<code><![CDATA[$this->shpData['points'][count($this->shpData['points']) - 1]]]></code>
<code>$value</code>
</MixedArrayAccess>
<MixedArrayAssignment>
<code><![CDATA[$this->shpData['parts'][$partIndex]]]></code>
<code><![CDATA[$this->shpData['parts'][$partIndex]]]></code>
<code><![CDATA[$this->shpData['parts'][$partIndex]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$partIndex]['points'][$i]]]></code>
<code><![CDATA[$this->shpData['parts'][$part]]]></code>
<code><![CDATA[$this->shpData['parts'][$part]['points']]]></code>
<code><![CDATA[$this->shpData['parts'][$part]['points'][$i]]]></code>
<code><![CDATA[$this->shpData['parts'][$part]['points'][$i][$type]]]></code>
<code><![CDATA[$this->shpData['parts'][$part]['points'][]]]></code>
<code><![CDATA[$this->shpData['points'][$i]]]></code>
<code><![CDATA[$this->shpData['points'][$i]]]></code>
<code><![CDATA[$this->shpData['points'][$i][$type]]]></code>
<code><![CDATA[$this->shpData['points'][]]]></code>
</MixedArrayAssignment>
<MixedArrayOffset>
<code><![CDATA[$this->dbfData[$value]]]></code>
<code>$tmp[$value]</code>
</MixedArrayOffset>
<MixedAssignment>
<code><![CDATA[$data['m']]]></code>
<code><![CDATA[$data['m']]]></code>
<code><![CDATA[$data['z']]]></code>
<code>$numparts</code>
<code>$numparts</code>
<code>$numpoints</code>
<code>$numpoints</code>
<code>$partData</code>
<code>$partData</code>
<code>$point</code>
<code>$pointData</code>
<code>$pointData</code>
<code><![CDATA[$point['m']]]></code>
<code><![CDATA[$point['m']]]></code>
<code><![CDATA[$point['z']]]></code>
<code>$recordNumber</code>
<code>$shapeType</code>
<code>$size</code>
<code><![CDATA[$this->size]]></code>
<code>[$value]</code>
</MixedAssignment>
<MixedOperand>
<code>$size</code>
<code><![CDATA[$this->shpData['numpoints']]]></code>
<code><![CDATA[$this->shpData['numpoints']]]></code>
<code><![CDATA[$this->shpData['numpoints'] ?? 0]]></code>
<code><![CDATA[$this->shpData['numpoints'] ?? 0]]></code>
</MixedOperand>
<PossiblyNullReference>
<code>hasMeasure</code>
<code>hasMeasure</code>
<code>readSHP</code>
</PossiblyNullReference>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$this->shpData['parts']]]></code>
</PossiblyUndefinedArrayOffset>
<PropertyNotSetInConstructor>
<code>$shpFile</code>
</PropertyNotSetInConstructor>
</file>
<file src="tests/ShapeFileTest.php">
<MixedArgument>
<code><![CDATA[$shp->records[0]->shpData['parts']]]></code>
</MixedArgument>
</file>
</files>
21 changes: 21 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
xmlns="https://getpsalm.org/schema/config"
errorLevel="1"
reportMixedIssues="true"
resolveFromConfigFile="true"
findUnusedBaselineEntry="true"
findUnusedCode="true"
errorBaseline="psalm-baseline.xml">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>

0 comments on commit ab4a803

Please sign in to comment.