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

MissingBody   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 20 3
A getRegister() 0 17 1
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