Use_   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 14.89 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
c 2
b 1
f 1
lcom 1
cbo 4
dl 7
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A as_() 0 4 1
A __call() 7 7 2
A getNode() 0 6 2

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\Builder;
4
5
use PhpParser\BuilderAbstract;
6
use PhpParser\Node;
7
use PhpParser\Node\Stmt;
8
9
/**
10
 * @method $this as(string $alias) Sets alias for used name.
11
 */
12
class Use_ extends BuilderAbstract {
13
    protected $name;
14
    protected $type;
15
    protected $alias = null;
16
17
    /**
18
     * Creates a name use (alias) builder.
19
     *
20
     * @param Node\Name|string $name Name of the entity (namespace, class, function, constant) to alias
21
     * @param int              $type One of the Stmt\Use_::TYPE_* constants
22
     */
23
    public function __construct($name, $type) {
24
        $this->name = $this->normalizeName($name);
25
        $this->type = $type;
26
    }
27
28
    /**
29
     * Sets alias for used name.
30
     *
31
     * @param string $alias Alias to use (last component of full name by default)
32
     *
33
     * @return $this The builder instance (for fluid interface)
34
     */
35
    protected function as_($alias) {
36
        $this->alias = $alias;
37
        return $this;
38
    }
39 View Code Duplication
    public function __call($name, $args) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
40
        if (method_exists($this, $name . '_')) {
41
            return call_user_func_array(array($this, $name . '_'), $args);
42
        }
43
44
        throw new \LogicException(sprintf('Method "%s" does not exist', $name));
45
    }
46
47
    /**
48
     * Returns the built node.
49
     *
50
     * @return Node The built node
51
     */
52
    public function getNode() {
53
        $alias = null !== $this->alias ? $this->alias : $this->name->getLast();
54
        return new Stmt\Use_(array(
55
            new Stmt\UseUse($this->name, $alias)
56
        ), $this->type);
57
    }
58
}
59