Skip to content

Commit ee67aab

Browse files
authored
Merge pull request #744 from driehle/feature/static-analysis
Added static analysis with Psalm and PhpStan
2 parents bd349bf + 1fd2d1a commit ee67aab

34 files changed

+308
-85
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
/phpcs.xml.dist export-ignore
66
/phpstan.neon export-ignore
77
/phpunit.xml.dist export-ignore
8-
/psalm.xml export-ignore
8+
/psalm.xml.dist export-ignore
9+
/psalm-baseline.xml export-ignore
910
/tests/ export-ignore

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
phpunit:
12-
name: "Unit Tests"
12+
name: "PHPUnit"
1313
runs-on: "ubuntu-20.04"
1414

1515
strategy:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "Static Analysis"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*.x"
7+
push:
8+
branches:
9+
- "*.x"
10+
11+
jobs:
12+
static-analysis:
13+
name: "Static Analysis"
14+
uses: "doctrine/.github/.github/workflows/[email protected]"
15+
with:
16+
php-version: '7.4'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
/composer.lock
55
/phpcs.xml
66
/phpunit.xml
7+
/psalm.xml
78
/vendor/

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,21 @@
6262
},
6363
"require-dev": {
6464
"doctrine/coding-standard": "^9.0.0",
65-
"doctrine/orm": "^2.10.1",
65+
"doctrine/orm": "^2.10.2",
66+
"jangregor/phpstan-prophecy": "^0.8.1",
6667
"laminas/laminas-i18n": "^2.11.3",
6768
"laminas/laminas-log": "^2.13.1",
6869
"laminas/laminas-modulemanager": "^2.11.0",
6970
"laminas/laminas-mvc-console": "^1.3.0",
70-
"laminas/laminas-serializer": "^2.10.1",
71+
"laminas/laminas-serializer": "^2.11.0",
7172
"laminas/laminas-session": "^2.12.0",
7273
"laminas/laminas-test": "^3.5.1",
7374
"phpspec/prophecy-phpunit": "^2.0.1",
75+
"phpstan/phpstan": "^0.12.99",
76+
"phpstan/phpstan-phpunit": "^0.12.22",
7477
"phpunit/phpunit": "^9.5.10",
75-
"predis/predis": "^1.1.9"
78+
"predis/predis": "^1.1.9",
79+
"vimeo/psalm": "^4.11.2"
7680
},
7781
"suggest": {
7882
"doctrine/data-fixtures": "Data Fixtures if you want to generate test data or bootstrap data for your deployments",

phpstan.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src
5+
- tests
6+
excludePaths:
7+
- src/Form/Element/ObjectMultiCheckboxV2Polyfill.php
8+
- src/Form/Element/ObjectRadioV2Polyfill.php
9+
- src/Form/Element/ObjectSelectV2Polyfill.php
10+
includes:
11+
- vendor/phpstan/phpstan-phpunit/rules.neon
12+
- vendor/jangregor/phpstan-prophecy/extension.neon

psalm-baseline.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="4.11.2@6fba5eb554f9507b72932f9c75533d8af593688d">
3+
<file src="src/Form/Element/ObjectMultiCheckboxV3Polyfill.php">
4+
<LessSpecificImplementedReturnType occurrences="2">
5+
<code>self</code>
6+
<code>self</code>
7+
</LessSpecificImplementedReturnType>
8+
</file>
9+
<file src="src/Form/Element/ObjectRadioV3Polyfill.php">
10+
<LessSpecificImplementedReturnType occurrences="2">
11+
<code>self</code>
12+
<code>self</code>
13+
</LessSpecificImplementedReturnType>
14+
<MoreSpecificImplementedParamType occurrences="1">
15+
<code>$options</code>
16+
</MoreSpecificImplementedParamType>
17+
</file>
18+
<file src="src/Form/Element/ObjectSelectV3Polyfill.php">
19+
<LessSpecificImplementedReturnType occurrences="2">
20+
<code>self</code>
21+
<code>self</code>
22+
</LessSpecificImplementedReturnType>
23+
<MoreSpecificImplementedParamType occurrences="1">
24+
<code>$options</code>
25+
</MoreSpecificImplementedParamType>
26+
</file>
27+
<file src="src/Module.php">
28+
<ParseError occurrences="1"/>
29+
</file>
30+
<file src="src/Service/DriverFactory.php">
31+
<UndefinedClass occurrences="1">
32+
<code>'Doctrine\Persistence\Mapping\Driver\AnnotationDriver'</code>
33+
</UndefinedClass>
34+
</file>
35+
<file src="vendor/laminas/laminas-servicemanager/src/Exception/CyclicAliasException.php">
36+
<ParseError occurrences="7">
37+
<code>)</code>
38+
<code>,</code>
39+
<code>,</code>
40+
<code>:</code>
41+
<code>=&gt;</code>
42+
<code>fn</code>
43+
<code>fn</code>
44+
</ParseError>
45+
</file>
46+
<file src="vendor/laminas/laminas-servicemanager/src/ServiceManager.php">
47+
<ParseError occurrences="2">
48+
<code>=&gt;</code>
49+
<code>fn</code>
50+
</ParseError>
51+
</file>
52+
</files>

psalm.xml.dist

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="5"
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+
errorBaseline="psalm-baseline.xml"
9+
>
10+
<projectFiles>
11+
<directory name="src" />
12+
<ignoreFiles>
13+
<file name="src/Form/Element/ObjectMultiCheckboxV2Polyfill.php" />
14+
<file name="src/Form/Element/ObjectRadioV2Polyfill.php" />
15+
<file name="src/Form/Element/ObjectSelectV2Polyfill.php" />
16+
<directory name="vendor" />
17+
</ignoreFiles>
18+
</projectFiles>
19+
<issueHandlers>
20+
<DuplicateClass>
21+
<errorLevel type="suppress">
22+
<!-- These files contain a php 7 and a php 8 version of the same trait -->
23+
<file name="src/GetConsoleUsage.php"/>
24+
</errorLevel>
25+
</DuplicateClass>
26+
</issueHandlers>
27+
</psalm>

src/Authentication/Storage/ObjectRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public function readKeyOnly()
7272
}
7373

7474
/**
75-
* @param mixed $identity
75+
* @param mixed $contents
7676
*/
77-
public function write($identity): void
77+
public function write($contents): void
7878
{
7979
$metadataInfo = $this->options->getClassMetadata();
80-
$identifierValues = $metadataInfo->getIdentifierValues($identity);
80+
$identifierValues = $metadataInfo->getIdentifierValues($contents);
8181

8282
$this->options->getStorage()->write($identifierValues);
8383
}

src/Cache/DoctrineCacheStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function internalGetItem(&$normalizedKey, &$success = null, &$casToken
5353
protected function internalSetItem(&$normalizedKey, &$value)
5454
{
5555
$key = $this->getOptions()->getNamespace() . $normalizedKey;
56-
$ttl = $this->getOptions()->getTtl();
56+
$ttl = (int) $this->getOptions()->getTtl();
5757

5858
return $this->cache->save($key, $value, $ttl);
5959
}

0 commit comments

Comments
 (0)