Completed
Pull Request — master (#139)
by Kévin
03:44
created

MethodCannotReturn::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 2
rs 9.6666
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\Statement;
7
8
use PhpParser\Node\Stmt\ClassMethod;
9
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
10
use PHPSA\Analyzer\Helper\ResolveExpressionTrait;
11
use PHPSA\Analyzer\Pass;
12
use PHPSA\Context;
13
14
class MethodCannotReturn implements Pass\AnalyzerPassInterface
15
{
16
    use DefaultMetadataPassTrait;
17
    use ResolveExpressionTrait;
18
19
    /**
20
     * @param ClassMethod $methodStmt
21
     * @param Context $context
22
     * @return bool
23
     */
24 23
    public function pass(ClassMethod $methodStmt, Context $context)
25
    {
26 23
        if (count($methodStmt->stmts) == 0) {
27 1
            return false;
28
        }
29
30 23
        $result = false;
31
32 23
        if ($methodStmt->name == '__construct' || $methodStmt->name == '__destruct') {
33 2
            foreach ($this->findReturnStatement($methodStmt->stmts) as $returnStmt) {
34 1
                if (!$returnStmt->expr) {
35
                    continue;
36
                }
37
38 1
                $context->notice(
39 1
                    'return.construct',
40 1
                    sprintf('Method %s cannot return a value.', $methodStmt->name),
41
                    $returnStmt
42 1
                );
43
44 1
                $result = true;
45 2
            }
46 2
        }
47
48 23
        return $result;
49
    }
50
51
    /**
52
     * @return array
53
     */
54 1
    public function getRegister()
55
    {
56
        return [
57
            ClassMethod::class
58 1
        ];
59
    }
60
}
61