Interface_::__construct()   B
last analyzed

Complexity

Conditions 6
Paths 16

Size

Total Lines 19
Code Lines 12

Duplication

Lines 11
Ratio 57.89 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 11
loc 19
rs 8.8571
cc 6
eloc 12
nc 16
nop 3
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