Completed
Push — master ( e0270b...8de424 )
by Дмитрий
03:07
created

ReturnVoid   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 15 2
A getRegister() 0 6 1
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Statement;
4
5
use PhpParser\Node\Stmt\Return_;
6
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
7
use PHPSA\Analyzer\Pass;
8
use PHPSA\Context;
9
10
class ReturnVoid implements Pass\AnalyzerPassInterface
11
{
12
    use DefaultMetadataPassTrait;
13
14
    const DESCRIPTION = 'Checks for return void statements.';
15
16
    /**
17
     * @param $stmt
18
     * @param Context $context
19
     * @return bool
20
     */
21 5
    public function pass(Return_ $stmt, Context $context)
22
    {
23
        // this is not the value null but "no value"
24 5
        if ($stmt->expr === null) {
25 1
            $context->notice(
26 1
                'return.void',
27 1
                'You are trying to return void',
28
                $stmt
29 1
            );
30
31 1
            return true;
32
        }
33
34 5
        return false;
35
    }
36
37
    /**
38
     * @return array
39
     */
40 2
    public function getRegister()
41
    {
42
        return [
43 2
            Return_::class,
44 2
        ];
45
    }
46
}
47