1: <?php
2:
3: namespace Mockery\Generator;
4:
5: class Parameter
6: {
7: private static $parameterCounter;
8:
9: private $rfp;
10:
11: public function __construct(\ReflectionParameter $rfp)
12: {
13: $this->rfp = $rfp;
14: }
15:
16: public function __call($method, array $args)
17: {
18: return call_user_func_array(array($this->rfp, $method), $args);
19: }
20:
21: public function getClass()
22: {
23: return new DefinedTargetClass($this->rfp->getClass());
24: }
25:
26: public function getTypeHintAsString()
27: {
28: if (method_exists($this->rfp, 'getTypehintText')) {
29:
30: $typehint = $this->rfp->getTypehintText();
31:
32:
33: if (in_array($typehint, array('int', 'integer', 'float', 'string', 'bool', 'boolean'))) {
34: return '';
35: }
36:
37: return $typehint;
38: }
39:
40: if ($this->rfp->isArray()) {
41: return 'array';
42: }
43:
44: 45: 46: 47:
48: if ((version_compare(PHP_VERSION, '5.4.1') >= 0)) {
49: try {
50: if ($this->rfp->getClass()) {
51: return $this->rfp->getClass()->getName();
52: }
53: } catch (\ReflectionException $re) {
54:
55: }
56: }
57:
58: if (preg_match('/^Parameter #[0-9]+ \[ \<(required|optional)\> (?<typehint>\S+ )?.*\$' . $this->rfp->getName() . ' .*\]$/', $this->rfp->__toString(), $typehintMatch)) {
59: if (!empty($typehintMatch['typehint'])) {
60: return $typehintMatch['typehint'];
61: }
62: }
63:
64: return '';
65: }
66:
67: 68: 69:
70: public function getName()
71: {
72: $name = $this->rfp->getName();
73: if (!$name || $name == '...') {
74: $name = 'arg' . static::$parameterCounter++;
75: }
76:
77: return $name;
78: }
79: }
80: