Completed
Pull Request — master (#229)
by Enrico
06:28
created

MissingBody::getRegister()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 17
ccs 14
cts 14
cp 1
crap 1
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\Analyzer\Helper\DefaultMetadataPassTrait;
8
use PHPSA\Context;
9
10
class MissingBody implements AnalyzerPassInterface
11
{
12
    use DefaultMetadataPassTrait;
13
    
14
    /**
15
     * @param Stmt $stmt
16
     * @param Context $context
17
     * @return bool
18
     */
19 50
    public function pass(Stmt $stmt, Context $context)
20
    {
21 50
        if ($stmt instanceof Stmt\Switch_) {
22 3
            $counting = $stmt->cases;
23 3
        } else {
24 50
            $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...
25
        }
26
27 50
        if (count($counting) === 0) {
28 11
            $context->notice(
29 11
                'missing_body',
30 11
                'Missing Body',
31
                $stmt
32 11
            );
33
34 11
            return true;
35
        }
36
        
37 43
        return false;
38
    }
39
40
    /**
41
     * @return array
42
     */
43 1
    public function getRegister()
44
    {
45
        return [
46 1
            Stmt\Function_::class,
47 1
            Stmt\ClassMethod::class,
48 1
            Stmt\For_::class,
49 1
            Stmt\Foreach_::class,
50 1
            Stmt\While_::class,
51 1
            Stmt\Do_::class,
52 1
            Stmt\If_::class,
53 1
            Stmt\ElseIf_::class,
54 1
            Stmt\Else_::class,
55 1
            Stmt\Switch_::class,
56 1
            Stmt\TryCatch::class,
57 1
            Stmt\Catch_::class,
58 1
        ];
59
    }
60
}
61