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
|
|
|
public function __construct($name) |
16
|
|
|
{ |
17
|
|
|
$this->name = $name; |
18
|
|
|
} |
19
|
|
|
public function getSignature() |
20
|
|
|
{ |
21
|
|
|
return sprintf( |
22
|
|
|
"(%s) : %s", |
23
|
|
|
$this->getParamsStr(), |
24
|
|
|
$this->getReturnStr() |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
public function addParam(MethodParam $param) |
28
|
|
|
{ |
29
|
|
|
if (array_key_exists($param->getName(), $this->arguments)) { |
30
|
|
|
$var = $this->arguments[$param->getName()]; |
31
|
|
|
if (empty($param->getType())) { |
32
|
|
|
$param->setType($var->getType()); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
$this->arguments[$param->getName()] = $param; |
36
|
|
|
} |
37
|
|
|
public function addArgument(MethodParam $arg) |
38
|
|
|
{ |
39
|
|
|
$this->addParam($arg); |
40
|
|
|
} |
41
|
|
|
public function getParamsStr() |
42
|
|
|
{ |
43
|
|
|
$paramsStr = []; |
44
|
|
|
foreach ($this->arguments as $argument) { |
45
|
|
|
/** @var MethodParam $argument */ |
46
|
|
|
$curParam = []; |
47
|
|
|
if ($argument->getType()) { |
48
|
|
|
if ($argument->getType() instanceof FQCN) { |
49
|
|
|
$curParam[] = $argument->getType()->getClassName(); |
50
|
|
|
} else { |
51
|
|
|
$curParam[] = $argument->getType(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
$curParam[] = sprintf("$%s", $argument->getName()); |
55
|
|
|
$paramsStr[] = implode(" ", $curParam); |
56
|
|
|
} |
57
|
|
|
return implode(", ", $paramsStr); |
58
|
|
|
} |
59
|
|
|
public function getReturnStr() |
60
|
|
|
{ |
61
|
|
|
if ($this->return instanceof FQCN) { |
62
|
|
|
return $this->return->getClassName(); |
63
|
|
|
} |
64
|
|
|
return "mixed"; |
65
|
|
|
} |
66
|
|
|
public function getReturn() |
67
|
|
|
{ |
68
|
|
|
return $this->return; |
69
|
|
|
} |
70
|
|
|
public function setReturn(FQCN $fqcn = null) |
71
|
|
|
{ |
72
|
|
|
$this->return = $fqcn; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|