Completed
Push — master ( 88ff74...459ac7 )
by Enrico
13:32
created

MissingBody   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 57
ccs 28
cts 28
cp 1
rs 10
wmc 6
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegister() 0 17 1
B pass() 0 24 5
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
    const DESCRIPTION = 'Checks that statements that define a block of statements are not empty.';
15
    
16
    /**
17
     * @param Stmt $stmt
18
     * @param Context $context
19
     * @return bool
20
     */
21 22
    public function pass(Stmt $stmt, Context $context)
22
    {
23 22
        if ($stmt instanceof Stmt\ClassMethod && $stmt->isAbstract()) { // abstract classes are ok
24 1
            return false;
25
        }
26
27 22
        if ($stmt instanceof Stmt\Switch_) {
28 2
            $counting = $stmt->cases;
29 2
        } else {
30 22
            $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...
31
        }
32
33 22
        if (count($counting) === 0) {
34 10
            $context->notice(
35 10
                'missing_body',
36 10
                'Missing Body',
37
                $stmt
38 10
            );
39
40 10
            return true;
41
        }
42
        
43 15
        return false;
44
    }
45
46
    /**
47
     * @return array
48
     */
49 1
    public function getRegister()
50
    {
51
        return [
52 1
            Stmt\Function_::class,
53 1
            Stmt\ClassMethod::class,
54 1
            Stmt\For_::class,
55 1
            Stmt\Foreach_::class,
56 1
            Stmt\While_::class,
57 1
            Stmt\Do_::class,
58 1
            Stmt\If_::class,
59 1
            Stmt\ElseIf_::class,
60 1
            Stmt\Else_::class,
61 1
            Stmt\Switch_::class,
62 1
            Stmt\TryCatch::class,
63 1
            Stmt\Catch_::class,
64 1
        ];
65
    }
66
}
67