Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise PHPStan to level 4 #93

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
phpstan.neon
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'ordered_imports' => true,
'php_unit_strict' => false,
'phpdoc_order' => true,
'phpdoc_to_param_type' => true,
// 'psr4' => true,
'strict_comparison' => true,
'strict_param' => true,
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
"psr-4": { "Readability\\": "src/" }
},
"autoload-dev": {
"psr-4": { "Tests\\Readability\\": "tests/" }
"psr-4": {
"Tests\\Readability\\": "tests/",
"Readability\\Maintenance\\": "maintenance/"
}
},
"scripts": {
"fix": "php-cs-fixer fix --verbose --diff",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

Check warning on line 1 in maintenance/PHPStan/DOMDocumentGetElementDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: indentation_type

Check warning on line 1 in maintenance/PHPStan/DOMDocumentGetElementDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: native_function_invocation

Check warning on line 1 in maintenance/PHPStan/DOMDocumentGetElementDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: braces_position

Check warning on line 1 in maintenance/PHPStan/DOMDocumentGetElementDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: no_unused_imports

namespace Readability\Maintenance\PHPStan;

use Readability\JSLikeHTMLElement;
use PHPStan\Type\Generic\GenericObjectType;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\ArrayType;
use PHPStan\Type\ObjectType;

class DOMDocumentGetElementDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
public function getClass(): string
{
return \DOMDocument::class;
}

public function isMethodSupported(MethodReflection $methodReflection): bool
{
return in_array($methodReflection->getName(),
[
'createElement',
], true);
}

public function getTypeFromMethodCall(
MethodReflection $methodReflection,
MethodCall $methodCall,
Scope $scope
): ?Type
{
return new ObjectType(JSLikeHTMLElement::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Readability\Maintenance\PHPStan;

use Readability\JSLikeHTMLElement;
use PHPStan\Type\Generic\GenericObjectType;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\ArrayType;
use PHPStan\Type\ObjectType;

class DOMDocumentGetElementsDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
public function getClass(): string
{
return \DOMDocument::class;
}

public function isMethodSupported(MethodReflection $methodReflection): bool
{
return in_array($methodReflection->getName(),
[
'getElementsByTagName',
], true);
}

public function getTypeFromMethodCall(
MethodReflection $methodReflection,
MethodCall $methodCall,
Scope $scope
): ?Type
{
$elementType = new ObjectType(JSLikeHTMLElement::class);
return new GenericObjectType(\DOMNodeList::class, [$elementType]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

Check warning on line 1 in maintenance/PHPStan/DOMElementGetElementsDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: indentation_type

Check warning on line 1 in maintenance/PHPStan/DOMElementGetElementsDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: native_function_invocation

Check warning on line 1 in maintenance/PHPStan/DOMElementGetElementsDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: braces_position

Check warning on line 1 in maintenance/PHPStan/DOMElementGetElementsDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: no_unused_imports

Check warning on line 1 in maintenance/PHPStan/DOMElementGetElementsDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: blank_line_before_statement

Check warning on line 1 in maintenance/PHPStan/DOMElementGetElementsDynamicReturnTypeExtension.php

View workflow job for this annotation

GitHub Actions / CS Fixer & PHPStan (7.4)

Found violation(s) of type: ordered_imports

namespace Readability\Maintenance\PHPStan;

use Readability\JSLikeHTMLElement;
use PHPStan\Type\Generic\GenericObjectType;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Type;
use PHPStan\Type\ArrayType;
use PHPStan\Type\ObjectType;

class DOMElementGetElementsDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
public function getClass(): string
{
return \DOMElement::class;
}

public function isMethodSupported(MethodReflection $methodReflection): bool
{
return in_array($methodReflection->getName(),
[
'getElementsByTagName',
], true);
}

public function getTypeFromMethodCall(
MethodReflection $methodReflection,
MethodCall $methodCall,
Scope $scope
): ?Type
{
$elementType = new ObjectType(JSLikeHTMLElement::class);
return new GenericObjectType(\DOMNodeList::class, [$elementType]);
}
}
30 changes: 30 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
parameters:
level: 4
paths:
- src
- tests

# https://github.com/phpstan/phpstan/issues/694#issuecomment-350724288
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- phar://phpstan.phar/conf/bleedingEdge.neon

services:
-
class: Readability\Maintenance\PHPStan\DOMDocumentGetElementDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

-
class: Readability\Maintenance\PHPStan\DOMDocumentGetElementsDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

-
class: Readability\Maintenance\PHPStan\DOMElementGetElementsDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
15 changes: 0 additions & 15 deletions phpstan.neon

This file was deleted.

Loading
Loading