Completed
Pull Request — master (#80)
by
unknown
03:32 queued 01:07
created

FunctionData   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 85
Duplicated Lines 23.53 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 17
lcom 2
cbo 3
dl 20
loc 85
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSignature() 0 8 1
A addParam() 10 10 3
A addArgument() 0 4 1
A getParamsStr() 0 18 4
A getReturnStr() 0 7 2
A getReturn() 0 4 1
A setReturn() 0 4 1
A addTypeHint() 10 10 3

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 Padawan\Domain\Project\Node;
4
5
use Padawan\Domain\Project\FQCN;
6
7
class FunctionData
8
{
9
    public $name = "";
10
    public $arguments = [];
11
    public $return;
12
    public $doc = "";
13
    public $startLine = 0;
14
    public $endLine = 0;
15
16
    /**
17
     * @property TypeHint[] $inlineTypeHint
18
     */
19
    public $inlineTypeHint = [];
20
21
    public function __construct($name)
22
    {
23
        $this->name = $name;
24
    }
25
    public function getSignature()
26
    {
27
        return sprintf(
28
            "(%s) : %s",
29
            $this->getParamsStr(),
30
            $this->getReturnStr()
31
        );
32
    }
33 View Code Duplication
    public function addParam(MethodParam $param)
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...
34
    {
35
        if (array_key_exists($param->getName(), $this->arguments)) {
36
            $var = $this->arguments[$param->getName()];
37
            if (empty($param->getType())) {
38
                $param->setType($var->getType());
39
            }
40
        }
41
        $this->arguments[$param->getName()] = $param;
42
    }
43
    public function addArgument(MethodParam $arg)
44
    {
45
        $this->addParam($arg);
46
    }
47
    public function getParamsStr()
48
    {
49
        $paramsStr = [];
50
        foreach ($this->arguments as $argument) {
51
            /** @var MethodParam $argument */
52
            $curParam = [];
53
            if ($argument->getType()) {
54
                if ($argument->getType() instanceof FQCN) {
55
                    $curParam[] = $argument->getType()->getClassName();
56
                } else {
57
                    $curParam[] = $argument->getType();
58
                }
59
            }
60
            $curParam[] = sprintf("$%s", $argument->getName());
61
            $paramsStr[] = implode(" ", $curParam);
62
        }
63
        return implode(", ", $paramsStr);
64
    }
65
    public function getReturnStr()
66
    {
67
        if ($this->return instanceof FQCN) {
68
            return $this->return->getClassName();
69
        }
70
        return "mixed";
71
    }
72
    public function getReturn()
73
    {
74
        return $this->return;
75
    }
76
    public function setReturn(FQCN $fqcn = null)
77
    {
78
        $this->return = $fqcn;
79
    }
80
81 View Code Duplication
    public function addTypeHint(TypeHint $var)
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...
82
    {
83
        if (array_key_exists($var->getName(), $this->inlineTypeHint)) {
84
            $var = $this->inlineTypeHint[$var->getName()];
85
            if (empty($var->getType())) {
86
                $var->setType($var->getType());
87
            }
88
        }
89
        $this->inlineTypeHint[$var->getName()] = $var;
90
    }
91
}
92