1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mockery |
4
|
|
|
* |
5
|
|
|
* LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the new BSD license that is bundled |
8
|
|
|
* with this package in the file LICENSE.txt. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://github.com/padraic/mockery/blob/master/LICENSE |
11
|
|
|
* If you did not receive a copy of the license and are unable to |
12
|
|
|
* obtain it through the world-wide-web, please send an email |
13
|
|
|
* to [email protected] so we can send you a copy immediately. |
14
|
|
|
* |
15
|
|
|
* @category Mockery |
16
|
|
|
* @package Mockery |
17
|
|
|
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com) |
18
|
|
|
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Mockery\Generator; |
22
|
|
|
|
23
|
|
|
class Method |
24
|
|
|
{ |
25
|
|
|
private $method; |
26
|
|
|
|
27
|
152 |
|
public function __construct(\ReflectionMethod $method) |
28
|
|
|
{ |
29
|
152 |
|
$this->method = $method; |
30
|
152 |
|
} |
31
|
|
|
|
32
|
152 |
|
public function __call($method, $args) |
33
|
|
|
{ |
34
|
152 |
|
return call_user_func_array(array($this->method, $method), $args); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getParameters() |
38
|
|
|
{ |
39
|
137 |
|
return array_map(function ($parameter) { |
40
|
65 |
|
return new Parameter($parameter); |
41
|
137 |
|
}, $this->method->getParameters()); |
42
|
|
|
} |
43
|
|
|
|
44
|
137 |
|
public function getReturnType() |
45
|
|
|
{ |
46
|
137 |
|
if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0 && $this->method->hasReturnType()) { |
47
|
18 |
|
$returnType = (string) $this->method->getReturnType(); |
48
|
|
|
|
49
|
18 |
|
if ('self' === $returnType) { |
50
|
10 |
|
$returnType = "\\".$this->method->getDeclaringClass()->getName(); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
18 |
|
if (version_compare(PHP_VERSION, '7.1.0-dev') >= 0 && $this->method->getReturnType()->allowsNull()) { |
54
|
|
|
$returnType = '?'.$returnType; |
55
|
|
|
} |
56
|
|
|
|
57
|
18 |
|
return $returnType; |
58
|
|
|
} |
59
|
130 |
|
return ''; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|