Skip to content

Commit 2927c7a

Browse files
xaloppmmoll
authored andcommitted
add phpstan for static analysis of the project
1 parent f17ae06 commit 2927c7a

11 files changed

+48
-20
lines changed

.phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
autoload_files:
3+
- %rootDir%/../../../tests/bootstrap.php

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ before_script:
1515
script:
1616
- vendor/bin/phpunit
1717
- vendor/bin/phpcs
18+
- |
19+
if [ `php -r "echo (int) version_compare(PHP_VERSION, '7.0', '>=');"` = "1" ]; then
20+
composer require phpstan/phpstan --dev
21+
vendor/bin/phpstan analyse --level=5 --no-progress -c .phpstan.neon MO4
22+
fi
1823
- php -d zend_extension=xdebug.so vendor/bin/phpunit --coverage-clover=coverage.xml
1924

2025
after_success:

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ So give `phpcbf` a try and let it fix the issues for you:
3636
To run the unit tests, execute in the repository root:
3737

3838
./vendor/bin/phpunit
39+
40+
## Static analysis
41+
42+
We do recommend to use [PHPStan](https://github.com/phpstan/phpstan) for static analysis, with level 5.
43+
Please refer to the [PHPStan](https://github.com/phpstan/phpstan#installation) documentation for
44+
installation instructions.
45+
46+
phpstan analyse --level=5 -c .phpstan.neon MO4/
3947

4048
## Code Coverage
4149

MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private function getUseStatementAsString(
223223
) {
224224
$tokens = $phpcsFile->getTokens();
225225

226-
$useEndPtr = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 2));
226+
$useEndPtr = $phpcsFile->findNext(array(T_SEMICOLON), ($stackPtr + 2));
227227
$useLength = ($useEndPtr - $stackPtr + 1);
228228
if ($tokens[($useEndPtr + 1)]['code'] === T_WHITESPACE) {
229229
$useLength++;

MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function process(File $phpcsFile, $stackPtr)
136136
);
137137

138138
$docCommentStringPtr = $phpcsFile->findNext(
139-
T_DOC_COMMENT_STRING,
139+
array(T_DOC_COMMENT_STRING),
140140
$next,
141141
$lineEnd
142142
);

MO4/Tests/Commenting/PropertyCommentUnitTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
namespace MO4\Tests\Commenting;
3030

31+
use PHP_CodeSniffer\Exceptions\RuntimeException;
3132
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
3233

3334
class PropertyCommentUnitTest extends AbstractSniffUnitTest
@@ -42,7 +43,8 @@ class PropertyCommentUnitTest extends AbstractSniffUnitTest
4243
*
4344
* @param string $testFile test file
4445
*
45-
* @return array(int => int)
46+
* @return array<int, int>
47+
* @throws RuntimeException
4648
*/
4749
protected function getErrorList($testFile='')
4850
{
@@ -62,7 +64,7 @@ protected function getErrorList($testFile='')
6264
);
6365
}
6466

65-
return null;
67+
throw new RuntimeException("Testfile {$testFile} in ".__DIR__." is not handled by ".__CLASS__);
6668

6769
}//end getErrorList()
6870

@@ -73,7 +75,7 @@ protected function getErrorList($testFile='')
7375
* The key of the array should represent the line number and the value
7476
* should represent the number of warnings that should occur on that line.
7577
*
76-
* @return array(int => int)
78+
* @return array<int, int>
7779
*/
7880
protected function getWarningList()
7981
{

MO4/Tests/Formatting/AlphabeticalUseStatementsUnitTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
namespace MO4\Tests\Formatting;
3131

32+
use PHP_CodeSniffer\Exceptions\RuntimeException;
3233
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
3334

3435
class AlphabeticalUseStatementsUnitTest extends AbstractSniffUnitTest
@@ -43,7 +44,8 @@ class AlphabeticalUseStatementsUnitTest extends AbstractSniffUnitTest
4344
*
4445
* @param string $testFile test file
4546
*
46-
* @return array(int => int)
47+
* @return array<int, int>
48+
* @throws RuntimeException
4749
*/
4850
protected function getErrorList($testFile='')
4951
{
@@ -82,7 +84,7 @@ protected function getErrorList($testFile='')
8284
);
8385
}//end switch
8486

85-
return null;
87+
throw new RuntimeException("Testfile {$testFile} in ".__DIR__." is not handled by ".__CLASS__);
8688

8789
}//end getErrorList()
8890

@@ -93,7 +95,7 @@ protected function getErrorList($testFile='')
9395
* The key of the array should represent the line number and the value
9496
* should represent the number of warnings that should occur on that line.
9597
*
96-
* @return array(int => int)
98+
* @return array<int, int>
9799
*/
98100
protected function getWarningList()
99101
{

MO4/Tests/Formatting/ArrayAlignmentUnitTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
namespace MO4\Tests\Formatting;
3030

31+
use PHP_CodeSniffer\Exceptions\RuntimeException;
3132
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
3233

3334
class ArrayAlignmentUnitTest extends AbstractSniffUnitTest
@@ -42,7 +43,8 @@ class ArrayAlignmentUnitTest extends AbstractSniffUnitTest
4243
*
4344
* @param string $testFile test file
4445
*
45-
* @return array(int => int)
46+
* @return array<int, int>
47+
* @throws RuntimeException
4648
*/
4749
protected function getErrorList($testFile='')
4850
{
@@ -86,7 +88,7 @@ protected function getErrorList($testFile='')
8688
);
8789
}//end switch
8890

89-
return null;
91+
throw new RuntimeException("Testfile {$testFile} in ".__DIR__." is not handled by ".__CLASS__);
9092

9193
}//end getErrorList()
9294

@@ -97,7 +99,7 @@ protected function getErrorList($testFile='')
9799
* The key of the array should represent the line number and the value
98100
* should represent the number of warnings that should occur on that line.
99101
*
100-
* @return array(int => int)
102+
* @return array<int, int>
101103
*/
102104
protected function getWarningList()
103105
{

MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
namespace MO4\Tests\Formatting;
3232

33+
use PHP_CodeSniffer\Exceptions\RuntimeException;
3334
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
3435

3536
class UnnecessaryNamespaceUsageUnitTest extends AbstractSniffUnitTest
@@ -44,7 +45,7 @@ class UnnecessaryNamespaceUsageUnitTest extends AbstractSniffUnitTest
4445
*
4546
* @param string $testFile test file
4647
*
47-
* @return array(int => int)
48+
* @return array<int, int>
4849
*/
4950
protected function getErrorList($testFile='')
5051
{
@@ -61,7 +62,8 @@ protected function getErrorList($testFile='')
6162
*
6263
* @param string $testFile test file
6364
*
64-
* @return array(int => int)
65+
* @return array<int, int>
66+
* @throws RuntimeException
6567
*/
6668
protected function getWarningList($testFile='')
6769
{
@@ -106,7 +108,7 @@ protected function getWarningList($testFile='')
106108
);
107109
}//end switch
108110

109-
return null;
111+
throw new RuntimeException("Testfile {$testFile} in ".__DIR__." is not handled by ".__CLASS__);
110112

111113
}//end getWarningList()
112114

MO4/Tests/Formatting/UseArrayShortTagUnitTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
namespace MO4\Tests\Formatting;
3131

32+
use PHP_CodeSniffer\Exceptions\RuntimeException;
3233
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
3334

3435
class UseArrayShortTagUnitTest extends AbstractSniffUnitTest
@@ -43,7 +44,8 @@ class UseArrayShortTagUnitTest extends AbstractSniffUnitTest
4344
*
4445
* @param string $testFile test file
4546
*
46-
* @return array(int => int)
47+
* @return array<int, int>
48+
* @throws RuntimeException
4749
*/
4850
protected function getErrorList($testFile='')
4951
{
@@ -62,7 +64,7 @@ protected function getErrorList($testFile='')
6264
);
6365
}
6466

65-
return null;
67+
throw new RuntimeException("Testfile {$testFile} in ".__DIR__." is not handled by ".__CLASS__);
6668

6769
}//end getErrorList()
6870

@@ -73,7 +75,7 @@ protected function getErrorList($testFile='')
7375
* The key of the array should represent the line number and the value
7476
* should represent the number of warnings that should occur on that line.
7577
*
76-
* @return array(int => int)
78+
* @return array<int, int>
7779
*/
7880
protected function getWarningList()
7981
{

0 commit comments

Comments
 (0)