Completed
Push — master ( cc5436...181e05 )
by Дмитрий
03:10 queued 36s
created

MethodCannotReturn::pass()   C

Complexity

Conditions 7
Paths 3

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 7
eloc 15
c 1
b 0
f 1
nc 3
nop 2
dl 0
loc 28
ccs 0
cts 18
cp 0
crap 56
rs 6.7272
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\Statement;
7
8
use PhpParser\Node\Stmt\ClassMethod;
9
use PhpParser\Node\Stmt\Return_;
10
use PHPSA\Context;
11
12
class MethodCannotReturn
13
{
14
    /**
15
     * @param ClassMethod $st
16
     * @param Context $context
17
     * @return bool
18
     */
19
    public function pass(ClassMethod $st, Context $context)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $st. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
20
    {
21
        if (count($st->stmts) == 0) {
22
            return false;
23
        }
24
25
        $result = false;
26
27
        if ($st->name == '__construct' || $st->name == '__destruct') {
28
            foreach ($st->stmts as $stmt) {
29
                if ($stmt instanceof Return_) {
30
                    if (!$stmt->expr) {
31
                        continue;
32
                    }
33
34
                    $context->notice(
35
                        'return.construct',
36
                        sprintf('Method %s cannot return a value.', $st->name),
37
                        $stmt
38
                    );
39
40
                    $result = true;
41
                }
42
            }
43
        }
44
45
        return $result;
46
    }
47
}
48