1 | <?php |
||
23 | class Parameter |
||
24 | { |
||
25 | private static $parameterCounter; |
||
26 | |||
27 | private $rfp; |
||
28 | |||
29 | 49 | public function __construct(\ReflectionParameter $rfp) |
|
33 | |||
34 | 48 | public function __call($method, array $args) |
|
38 | |||
39 | public function getClass() |
||
43 | |||
44 | 49 | public function getTypeHintAsString() |
|
45 | { |
||
46 | 49 | if (method_exists($this->rfp, 'getTypehintText')) { |
|
47 | // Available in HHVM |
||
48 | $typehint = $this->rfp->getTypehintText(); |
||
49 | |||
50 | // not exhaustive, but will do for now |
||
51 | if (in_array($typehint, array('int', 'integer', 'float', 'string', 'bool', 'boolean'))) { |
||
52 | return ''; |
||
53 | } |
||
54 | |||
55 | return $typehint; |
||
56 | } |
||
57 | |||
58 | 49 | if ($this->rfp->isArray()) { |
|
59 | 3 | return 'array'; |
|
60 | } |
||
61 | |||
62 | /* |
||
63 | * PHP < 5.4.1 has some strange behaviour with a typehint of self and |
||
64 | * subclass signatures, so we risk the regexp instead |
||
65 | */ |
||
66 | 49 | if ((version_compare(PHP_VERSION, '5.4.1') >= 0)) { |
|
67 | try { |
||
68 | 49 | if ($this->rfp->getClass()) { |
|
69 | 6 | return $this->rfp->getClass()->getName(); |
|
|
|||
70 | } |
||
71 | 46 | } catch (\ReflectionException $re) { |
|
72 | // noop |
||
73 | } |
||
74 | 46 | } |
|
75 | |||
76 | 46 | if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0 && $this->rfp->hasType()) { |
|
77 | return (string) $this->rfp->getType(); |
||
78 | } |
||
79 | |||
80 | 46 | if (preg_match('/^Parameter #[0-9]+ \[ \<(required|optional)\> (?<typehint>\S+ )?.*\$' . $this->rfp->getName() . ' .*\]$/', $this->rfp->__toString(), $typehintMatch)) { |
|
81 | 46 | if (!empty($typehintMatch['typehint'])) { |
|
82 | 3 | return $typehintMatch['typehint']; |
|
83 | } |
||
84 | 44 | } |
|
85 | |||
86 | 44 | return ''; |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * Some internal classes have funny looking definitions... |
||
91 | */ |
||
92 | 41 | public function getName() |
|
101 | |||
102 | |||
103 | /** |
||
104 | * Variadics only introduced in 5.6 |
||
105 | */ |
||
106 | 41 | public function isVariadic() |
|
110 | } |
||
111 |