GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NewExpression   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 76
Duplicated Lines 13.16 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 3
dl 10
loc 76
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getArguments() 0 4 1
A traverse() 0 4 1
A update() 10 10 3
A updateClassValue() 0 4 1
A compileCode() 0 10 1
A dataToSerialize() 0 4 1
A unserializeData() 0 4 1
A __clone() 0 5 1

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 Pinq\Expressions;
4
5
/**
6
 * <code>
7
 * new \stdClass()
8
 * </code>
9
 *
10
 * @author Elliot Levin <[email protected]>
11
 */
12
class NewExpression extends StaticClassExpression
13
{
14
    /**
15
     * @var ArgumentExpression[]
16
     */
17
    private $arguments;
18
19
    public function __construct(Expression $class, array $arguments = [])
20
    {
21
        parent::__construct($class);
22
23
        $this->arguments = self::verifyAll($arguments, ArgumentExpression::getType());
24
    }
25
26
    /**
27
     * @return Expression[]
28
     */
29
    public function getArguments()
30
    {
31
        return $this->arguments;
32
    }
33
34
    public function traverse(ExpressionWalker $walker)
35
    {
36
        return $walker->walkNew($this);
37
    }
38
39
    /**
40
     * @param Expression           $class
41
     * @param ArgumentExpression[] $arguments
42
     *
43
     * @return NewExpression
44
     */
45 View Code Duplication
    public function update(Expression $class, array $arguments = [])
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...
46
    {
47
        if ($this->class === $class
48
                && $this->arguments === $arguments
49
        ) {
50
            return $this;
51
        }
52
53
        return new self($class, $arguments);
54
    }
55
56
    protected function updateClassValue(Expression $class)
57
    {
58
        return new self($class, $this->arguments);
59
    }
60
61
    protected function compileCode(&$code)
62
    {
63
        $code .= '(new ';
64
65
        $this->compileType($code, $this->class);
66
67
        $code .= '(';
68
        $code .= implode(',', self::compileAll($this->arguments));
69
        $code .= '))';
70
    }
71
72
    protected function dataToSerialize()
73
    {
74
        return [$this->arguments];
75
    }
76
77
    protected function unserializeData($data)
78
    {
79
        list($this->arguments) = $data;
80
    }
81
82
    public function __clone()
83
    {
84
        $this->class     = clone $this->class;
85
        $this->arguments = self::cloneAll($this->arguments);
86
    }
87
}
88