Completed
Pull Request — master (#229)
by Enrico
04:42
created

MissingBody::pass()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 4
nop 2
dl 0
loc 20
ccs 12
cts 12
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Statement;
4
5
use PhpParser\Node\Stmt;
6
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
7
use PHPSA\Context;
8
9
class MissingBody implements AnalyzerPassInterface
10
{
11
    /**
12
     * @param Stmt $stmt
13
     * @param Context $context
14
     * @return bool
15
     */
16 49
    public function pass(Stmt $stmt, Context $context)
17
    {
18 49
        if ($stmt instanceof Stmt\Switch_) {
19 2
            $counting = $stmt->cases;
20 2
        } else {
21 49
            $counting = $stmt->stmts;
0 ignored issues
show
Bug introduced by
The property stmts does not seem to exist in PhpParser\Node\Stmt.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
22
        }
23
24 49
        if (count($counting) === 0) {
25 11
            $context->notice(
26 11
                'missing_body',
27 11
                'Missing Body',
28
                $stmt
29 11
            );
30
31 11
            return true;
32
        }
33
        
34 42
        return false;
35
    }
36
37
    /**
38
     * @return array
39
     */
40 1
    public function getRegister()
41
    {
42
        return [
43 1
            Stmt\Function_::class,
44 1
            Stmt\ClassMethod::class,
45 1
            Stmt\For_::class,
46 1
            Stmt\Foreach_::class,
47 1
            Stmt\While_::class,
48 1
            Stmt\Do_::class,
49 1
            Stmt\If_::class,
50 1
            Stmt\ElseIf_::class,
51 1
            Stmt\Else_::class,
52 1
            Stmt\Switch_::class,
53 1
            Stmt\TryCatch::class,
54 1
            Stmt\Catch_::class,
55 1
        ];
56
    }
57
}
58