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

MissingBody   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

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\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