Completed
Push — master ( 8de424...30de07 )
by Дмитрий
03:11
created

ReturnVoid::pass()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 25
ccs 14
cts 14
cp 1
crap 5
rs 8.439
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\CompiledExpression;
9
use PHPSA\Context;
10
11
class ReturnVoid implements Pass\AnalyzerPassInterface
12
{
13
    use DefaultMetadataPassTrait;
14
15
    const DESCRIPTION = 'Checks for return void statements.';
16
17
    /**
18
     * @param $stmt
19
     * @param Context $context
20
     * @return bool
21
     */
22 5
    public function pass(Return_ $stmt, Context $context)
23
    {
24
        // this is not the value null but "no value"
25 5
        if ($stmt->expr === null) {
26 1
            $scopePointer = $context->scopePointer;
27 1
            if ($scopePointer && $scopePointer->isClassMethod()) {
28
                /** @var \PHPSA\Definition\ClassMethod $method */
29 1
                $method = $scopePointer->getObject();
30 1
                if ($method->getReturnType() == CompiledExpression::VOID) {
31 1
                    return false;
32
                }
33 1
            }
34
35
36 1
            $context->notice(
37 1
                'return.void',
38 1
                'You are trying to return void',
39
                $stmt
40 1
            );
41
42 1
            return true;
43
        }
44
45 5
        return false;
46
    }
47
48
    /**
49
     * @return array
50
     */
51 2
    public function getRegister()
52
    {
53
        return [
54 2
            Return_::class,
55 2
        ];
56
    }
57
}
58