OldConstructor::pass()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 20
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Statement;
4
5
use PhpParser\Node\Stmt;
6
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
7
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
8
use PHPSA\Context;
9
10
class OldConstructor implements AnalyzerPassInterface
11
{
12
    use DefaultMetadataPassTrait;
13
14
    const DESCRIPTION = 'Checks for use of PHP 4 constructors and discourages it.';
15
16
    /**
17
     * @param Stmt\Class_ $classStmt
18
     * @param Context $context
19
     * @return bool
20
     */
21
    public function pass(Stmt\Class_ $classStmt, Context $context)
22
    {
23
        foreach ($classStmt->stmts as $statement) {
24
            if (!($statement instanceof Stmt\ClassMethod) || $statement->name !== $classStmt->name) {
25
                continue;
26
            }
27
28
            $context->notice(
29
                'deprecated.constructor',
30
                sprintf('Class %s uses a PHP4 constructor.', $classStmt->name),
31
                $classStmt
32
            );
33
            return true;
34
        }
35
36
        return false;
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function getRegister()
43
    {
44
        return [
45
            Stmt\Class_::class
46
        ];
47
    }
48
}
49