Skip to content

Commit 6ae1cc6

Browse files
authored
Merge pull request #30 from shochdoerfer/feature/phpstan
Add phpstan to test the project
2 parents a49a5c0 + 55e4f44 commit 6ae1cc6

File tree

12 files changed

+149
-16
lines changed

12 files changed

+149
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ script:
1919
- composer validate
2020
- ./vendor/bin/phing security:check
2121
- ./vendor/bin/phing sniff
22+
- ./vendor/bin/phing static-analysis
2223
- if [[ $TEST_COVERAGE == 'true' ]]; then ./vendor/bin/phing unit-with-coverage ; fi
2324
- if [[ $TEST_COVERAGE != 'true' ]]; then ./vendor/bin/phing unit ; fi
2425

2526
after_script:
2627
- if [[ $TEST_COVERAGE == 'true' ]]; then ./vendor/bin/coveralls -v ; fi
27-

build.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@
3939
<arg value="clover.xml"/>
4040
</exec>
4141
</target>
42+
43+
<target name="static-analysis">
44+
<exec executable="./vendor/bin/phpstan"
45+
passthru="true"
46+
checkreturn="true">
47+
<arg value="analyse"/>
48+
</exec>
49+
</target>
4250
</project>

captainhook.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"pre-push": {
1515
"enabled": false,
1616
"actions": [
17+
{
18+
"action": "./vendor/bin/phing static-analysis",
19+
"options": []
20+
},
1721
{
1822
"action": "./vendor/bin/phing security:check",
1923
"options": []

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"mikey179/vfsstream": "^1.6",
2828
"nikic/php-parser": "^4.3",
2929
"phing/phing": "^2.16",
30+
"phpstan/extension-installer": "^1.0",
31+
"phpstan/phpstan-phpunit": "^0.12.8",
3032
"phpunit/phpunit": "^8.5.3",
3133
"squizlabs/php_codesniffer": "^3.4"
3234
},

composer.lock

Lines changed: 102 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
parameters:
2+
level: 7
3+
inferPrivatePropertyTypeFromConstructor: true
4+
fileExtensions:
5+
- php
6+
paths:
7+
- src/bitExpert
8+
- tests/bitExpert
9+
ignoreErrors:
10+
-
11+
message: '~Call to an undefined method ReflectionType::getName~'
12+
path: src/bitExpert/PHPStan/Magento/Autoload/ProxyAutoloader.php
13+
-
14+
message: '~Parameter #1 \$argument of class ReflectionClass constructor expects~'
15+
path: src/bitExpert/PHPStan/Magento/Autoload/ProxyAutoloader.php
16+
-
17+
message: '~Class Magento\\Framework\\DataObject not found~'
18+
path: src/bitExpert/PHPStan/Magento/Reflection/Framework/DataObjectMagicMethodReflectionExtension.php

src/bitExpert/PHPStan/Magento/Autoload/FactoryAutoloader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public function autoload(string $class): void
4949
/**
5050
* Generate the factory file content as Magento would.
5151
*
52-
* @param $class
52+
* @param string $class
5353
* @return string
5454
*/
55-
protected function getFileContents($class): string
55+
protected function getFileContents(string $class): string
5656
{
5757
$namespace = explode('\\', ltrim($class, '\\'));
5858
$factoryClassname = array_pop($namespace);

src/bitExpert/PHPStan/Magento/Reflection/MagicMethodReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MagicMethodReflection implements MethodReflection
2828
*/
2929
private $declaringClass;
3030
/**
31-
* @var array
31+
* @var ParametersAcceptor[]
3232
*/
3333
private $variants;
3434

tests/bitExpert/PHPStan/Magento/Autoload/Cache/FileCacheStorageUnitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function setUp(): void
3737
/**
3838
* @test
3939
*/
40-
public function nullReturnedWhenLookingUpNonExistentFileInCache()
40+
public function nullReturnedWhenLookingUpNonExistentFileInCache(): void
4141
{
4242
$absFilename = $this->storage->load('test.txt', '');
4343

@@ -47,7 +47,7 @@ public function nullReturnedWhenLookingUpNonExistentFileInCache()
4747
/**
4848
* @test
4949
*/
50-
public function absoluteFilenameReturnedWhenLookingUpExistentFileInCache()
50+
public function absoluteFilenameReturnedWhenLookingUpExistentFileInCache(): void
5151
{
5252
vfsStream::create(
5353
['4b' => ['6f' => ['4b6fcb2d521ef0fd442a5301e7932d16cc9f375a.php' => 'Lorem ipsum']]],
@@ -62,7 +62,7 @@ public function absoluteFilenameReturnedWhenLookingUpExistentFileInCache()
6262
/**
6363
* @test
6464
*/
65-
public function addingFileToCacheSucceeds()
65+
public function addingFileToCacheSucceeds(): void
6666
{
6767
$this->storage->save('test.txt', '', 'Lorem ipsum');
6868
$absFilename = $this->storage->load('test.txt', '');
@@ -73,7 +73,7 @@ public function addingFileToCacheSucceeds()
7373
/**
7474
* @test
7575
*/
76-
public function addingFileToCacheFails()
76+
public function addingFileToCacheFails(): void
7777
{
7878
$this->expectException(InvalidArgumentException::class);
7979

tests/bitExpert/PHPStan/Magento/Autoload/FactoryAutoloaderUnitTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function setUp(): void
3636
/**
3737
* @test
3838
*/
39-
public function autoloaderIgnoresClassesWithoutFactoryPostfix()
39+
public function autoloaderIgnoresClassesWithoutFactoryPostfix(): void
4040
{
4141
$this->storage->expects($this->never())
4242
->method('load');
@@ -47,7 +47,7 @@ public function autoloaderIgnoresClassesWithoutFactoryPostfix()
4747
/**
4848
* @test
4949
*/
50-
public function autoloaderUsesCachedFileWhenFound()
50+
public function autoloaderUsesCachedFileWhenFound(): void
5151
{
5252
$this->storage->expects($this->once())
5353
->method('load')
@@ -61,7 +61,7 @@ public function autoloaderUsesCachedFileWhenFound()
6161
/**
6262
* @test
6363
*/
64-
public function autoloaderGeneratesCacheFileWhenNotFoundInCache()
64+
public function autoloaderGeneratesCacheFileWhenNotFoundInCache(): void
6565
{
6666
$this->storage->expects($this->atMost(2))
6767
->method('load')

0 commit comments

Comments
 (0)