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

MethodCannotReturn   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 36
ccs 0
cts 18
cp 0
rs 10
wmc 7
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
C pass() 0 28 7
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