|
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) |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
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
|
|
|
|
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.