1 | <?php |
||
33 | class ElseExpression extends AbstractRule implements MethodAware, FunctionAware |
||
34 | { |
||
35 | /** |
||
36 | * This method checks if a method/function uses an else expression and add a violation for each one found. |
||
37 | * |
||
38 | * @param \PHPMD\AbstractNode $node |
||
39 | * @return void |
||
40 | */ |
||
41 | 4 | public function apply(AbstractNode $node) |
|
61 | |||
62 | /** |
||
63 | * Whether the given scope is an else clause |
||
64 | * |
||
65 | * @param $scope |
||
66 | * @param ASTNode $parent |
||
67 | * @return bool |
||
68 | */ |
||
69 | 4 | private function isElseScope($scope, ASTNode $parent) |
|
76 | |||
77 | /** |
||
78 | * Whether the parent node is an if or an elseif clause |
||
79 | * |
||
80 | * @param ASTNode $parent |
||
81 | * @return bool |
||
82 | */ |
||
83 | 4 | private function isIfOrElseIfStatement(ASTNode $parent) |
|
87 | |||
88 | /** |
||
89 | * Whether the given scope has a yield or yield from clause |
||
90 | * |
||
91 | * @param $scope |
||
92 | * @return bool |
||
93 | */ |
||
94 | 3 | private function hasYieldOrYieldFrom($scope) |
|
98 | } |
||
99 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: