Skip to content

Commit 3eaa085

Browse files
committed
Static analysis with PHPStan
1 parent 10726ed commit 3eaa085

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ php:
55
before_script:
66
- composer self-update
77
script:
8-
- composer install
8+
- composer install --ignore-platform-reqs
99
- vendor/bin/phing
1010
after_script:
1111
- php vendor/bin/coveralls -v

SlevomatCodingStandard/Sniffs/Namespaces/AlphabeticallySortedUsesSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ private function fixAlphabeticalOrder(
9999
*/
100100
private function compareStrings($a, $b)
101101
{
102-
for ($i = 0; $i < min(strlen($a), strlen($b)); $i++) {
102+
$i = 0;
103+
for (; $i < min(strlen($a), strlen($b)); $i++) {
103104
if ($this->isSpecialCharacter($a[$i]) && !$this->isSpecialCharacter($b[$i])) {
104105
return -1;
105106
} elseif (!$this->isSpecialCharacter($a[$i]) && $this->isSpecialCharacter($b[$i])) {

build.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
composer,
66
lint,
77
cs,
8-
tests
8+
tests,
9+
phpstan
910
"/>
1011

1112
<target name="composer">
@@ -16,6 +17,7 @@
1617
checkreturn="true"
1718
>
1819
<arg value="install"/>
20+
<arg value="--ignore-platform-reqs"/>
1921
</exec>
2022
</target>
2123

@@ -81,4 +83,28 @@
8183
</exec>
8284
</target>
8385

86+
<target name="phpstan">
87+
<php expression="PHP_VERSION_ID >= 70000 ?'true':'false'" returnProperty="isPHP7" level="verbose" />
88+
<if>
89+
<equals arg1="${isPHP7}" arg2="true" />
90+
<then>
91+
<exec
92+
executable="vendor/bin/phpstan"
93+
logoutput="true"
94+
passthru="true"
95+
checkreturn="true"
96+
>
97+
<arg value="analyse"/>
98+
<arg value="-c"/>
99+
<arg path="phpstan.neon"/>
100+
<arg path="SlevomatCodingStandard"/>
101+
<arg path="tests"/>
102+
</exec>
103+
</then>
104+
<else>
105+
<echo message="PHPStan requires PHP 7." />
106+
</else>
107+
</if>
108+
</target>
109+
84110
</project>

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"require-dev": {
1313
"consistence/coding-standard": "^0.10",
1414
"phing/phing": "^2.9",
15+
"phpstan/phpstan": "dev-dev#1cb3904e17",
1516
"phpunit/phpunit": "^5.0",
1617
"satooshi/php-coveralls": "dev-master"
1718
},

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
excludes_analyse:
3+
- */tests/*/data/*

0 commit comments

Comments
 (0)