Interface_   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 25 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 7
c 3
b 0
f 1
lcom 0
cbo 2
dl 11
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubNodeNames() 0 3 1
B __construct() 11 19 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace PhpParser\Node\Stmt;
4
5
use PhpParser\Node;
6
use PhpParser\Error;
7
8
class Interface_ extends ClassLike
9
{
10
    /** @var Node\Name[] Extended interfaces */
11
    public $extends;
12
13
    protected static $specialNames = array(
14
        'self'   => true,
15
        'parent' => true,
16
        'static' => true,
17
    );
18
19
    /**
20
     * Constructs a class node.
21
     *
22
     * @param string $name       Name
23
     * @param array  $subNodes   Array of the following optional subnodes:
24
     *                           'extends' => array(): Name of extended interfaces
25
     *                           'stmts'   => array(): Statements
26
     * @param array  $attributes Additional attributes
27
     */
28
    public function __construct($name, array $subNodes = array(), array $attributes = array()) {
29
        parent::__construct($attributes);
30
        $this->name = $name;
31
        $this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : array();
32
        $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
33
34 View Code Duplication
        if (isset(self::$specialNames[strtolower($this->name)])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name));
36
        }
37
38 View Code Duplication
        foreach ($this->extends as $interface) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
            if (isset(self::$specialNames[strtolower($interface)])) {
40
                throw new Error(
41
                    sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
42
                    $interface->getAttributes()
43
                );
44
            }
45
        }
46
    }
47
48
    public function getSubNodeNames() {
49
        return array('name', 'extends', 'stmts');
50
    }
51
}
52