Skip to content

Commit 8c58cc8

Browse files
authored
Merge pull request #51 from moufmouf/phpstan0.12
Upgrading to PHPStan 0.12
2 parents a2aa2fc + 5050cad commit 8c58cc8

24 files changed

+29
-1155
lines changed

README.md

-10
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ They are more "strict" than the default PHPStan rules and some may be controvers
2424
- When throwing an exception inside a catch block, [you should pass the catched exception as the "previous" exception](http://bestpractices.thecodingmachine.com/php/error_handling.html#wrapping-an-exception-do-not-lose-the-previous-exception)
2525
- If you catch a `Throwable`, an `Exception` or a `RuntimeException`, you must rethrow the exception.
2626

27-
### Type-hinting related rules
28-
29-
This is a PHP 7.1+ rule:
30-
31-
- You should use type-hinting when possible
32-
- If not possible, you should use a Docblock to specify the type
33-
- If type-hinting against an array, you should use a Docblock to further explain the content of the array
34-
35-
[More about type-hinting related rules...](doc/typehinting_rules.md)
36-
3727
### Superglobal related rules
3828

3929
- The use of [`$_GET`, `$_POST`, `$_FILES`, `$_COOKIE`, `$_SESSION`, `$_REQUEST` is forbidden](http://bestpractices.thecodingmachine.com/php/organize_your_code.html#stop-using-superglobals-).

composer.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": "^7.1",
14-
"phpstan/phpstan": "^0.11.7"
14+
"phpstan/phpstan": "^0.12"
1515
},
1616
"require-dev": {
1717
"phpunit/phpunit": "^7.1",
@@ -24,19 +24,18 @@
2424
},
2525
"autoload-dev": {
2626
"classmap": [
27-
"tests/Rules/Exceptions/data/",
28-
"tests/Rules/TypeHints/data/"
27+
"tests/Rules/Exceptions/data/"
2928
],
3029
"psr-4": {
3130
"TheCodingMachine\\PHPStan\\": "tests/"
3231
}
3332
},
3433
"scripts": {
35-
"phpstan": "phpstan analyse src -c phpstan.neon --level=5 --no-progress -vvv"
34+
"phpstan": "phpstan analyse src -c phpstan.neon --level=6 --no-progress -vvv"
3635
},
3736
"extra": {
3837
"branch-alias": {
39-
"dev-master": "0.10-dev"
38+
"dev-master": "0.12-dev"
4039
},
4140
"phpstan": {
4241
"includes": [

doc/typehinting_rules.md

-140
This file was deleted.

phpstan-strict-rules.neon

-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ services:
1515
class: TheCodingMachine\PHPStan\Rules\Exceptions\MustRethrowRule
1616
tags:
1717
- phpstan.rules.rule
18-
-
19-
class: TheCodingMachine\PHPStan\Rules\TypeHints\MissingTypeHintInFunctionRule
20-
tags:
21-
- phpstan.rules.rule
22-
-
23-
class: TheCodingMachine\PHPStan\Rules\TypeHints\MissingTypeHintInMethodRule
24-
tags:
25-
- phpstan.rules.rule
2618
-
2719
class: TheCodingMachine\PHPStan\Rules\Superglobals\NoSuperglobalsRule
2820
tags:

phpstan.neon

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
parameters:
2-
ignoreErrors:
3-
- '#Access to an undefined property PhpParser\\Node\\FunctionLike::\$name.#'
41
includes:
52
- phpstan-strict-rules.neon

src/Rules/Conditionals/SwitchMustContainDefaultRule.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* A switch statement must always contain a "default" statement.
16+
*
17+
* @implements Rule<Switch_>
1618
*/
1719
class SwitchMustContainDefaultRule implements Rule
1820
{

src/Rules/Exceptions/DoNotThrowExceptionBaseClassRule.php

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
/**
1212
* This rule checks that the base \Exception class is never thrown. Instead, developers should subclass the \Exception
1313
* base class and throw the sub-type.
14+
*
15+
* @implements Rule<Node\Stmt\Throw_>
1416
*/
1517
class DoNotThrowExceptionBaseClassRule implements Rule
1618
{

src/Rules/Exceptions/EmptyExceptionRule.php

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use PHPStan\Rules\Rule;
1111
use function strpos;
1212

13+
/**
14+
* @implements Rule<Catch_>
15+
*/
1316
class EmptyExceptionRule implements Rule
1417
{
1518
public function getNodeType(): string

src/Rules/Exceptions/MustRethrowRule.php

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
/**
2020
* When catching \Exception, \RuntimeException or \Throwable, the exception MUST be thrown again
2121
* (unless you are developing an exception handler...)
22+
*
23+
* @implements Rule<Catch_>
2224
*/
2325
class MustRethrowRule implements Rule
2426
{
@@ -49,13 +51,17 @@ public function processNode(Node $node, Scope $scope): array
4951

5052
// Let's visit and find a throw.
5153
$visitor = new class() extends NodeVisitorAbstract {
54+
/**
55+
* @var bool
56+
*/
5257
private $throwFound = false;
5358

5459
public function leaveNode(Node $node)
5560
{
5661
if ($node instanceof Node\Stmt\Throw_) {
5762
$this->throwFound = true;
5863
}
64+
return null;
5965
}
6066

6167
/**

src/Rules/Exceptions/ThrowMustBundlePreviousExceptionRule.php

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
/**
1515
* When throwing into a catch block, checks that the previous exception is passed to the new "throw" clause
1616
* (the initial stack trace must not be lost).
17+
*
18+
* @implements Rule<Catch_>
1719
*/
1820
class ThrowMustBundlePreviousExceptionRule implements Rule
1921
{
@@ -34,7 +36,13 @@ public function processNode(Node $node, Scope $scope): array
3436
* @var string
3537
*/
3638
private $catchedVariableName;
39+
/**
40+
* @var int
41+
*/
3742
private $exceptionUsedCount = 0;
43+
/**
44+
* @var Node\Stmt\Throw_[]
45+
*/
3846
private $unusedThrows = [];
3947

4048
public function __construct(string $catchedVariableName)
@@ -48,6 +56,7 @@ public function leaveNode(Node $node)
4856
if ($node->name === $this->catchedVariableName) {
4957
$this->exceptionUsedCount++;
5058
}
59+
return null;
5160
}
5261

5362
// If the variable is used in the context of a method call (like $e->getMessage()), the exception is not passed as a "previous exception".
@@ -60,6 +69,7 @@ public function leaveNode(Node $node)
6069
if ($node instanceof Node\Stmt\Throw_ && $this->exceptionUsedCount === 0) {
6170
$this->unusedThrows[] = $node;
6271
}
72+
return null;
6373
}
6474

6575
/**

src/Rules/Superglobals/NoSuperglobalsRule.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* This rule checks that no superglobals are used in code.
16+
*
17+
* @implements Rule<Node\Expr\Variable>
1618
*/
1719
class NoSuperglobalsRule implements Rule
1820
{

0 commit comments

Comments
 (0)