|
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
|
169 |
|
public function __construct(\ReflectionMethod $method) |
|
28
|
|
|
{ |
|
29
|
169 |
|
$this->method = $method; |
|
30
|
169 |
|
} |
|
31
|
|
|
|
|
32
|
169 |
|
public function __call($method, $args) |
|
33
|
|
|
{ |
|
34
|
169 |
|
return call_user_func_array(array($this->method, $method), $args); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getParameters() |
|
38
|
|
|
{ |
|
39
|
154 |
|
return array_map(function ($parameter) { |
|
40
|
80 |
|
return new Parameter($parameter); |
|
41
|
154 |
|
}, $this->method->getParameters()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
154 |
|
public function getReturnType() |
|
45
|
|
|
{ |
|
46
|
154 |
|
if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0 && $this->method->hasReturnType()) { |
|
47
|
34 |
|
$returnType = (string) $this->method->getReturnType(); |
|
48
|
|
|
|
|
49
|
34 |
|
if ('self' === $returnType) { |
|
50
|
23 |
|
$returnType = "\\".$this->method->getDeclaringClass()->getName(); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
34 |
|
if (version_compare(PHP_VERSION, '7.1.0-dev') >= 0 && $this->method->getReturnType()->allowsNull()) { |
|
54
|
13 |
|
$returnType = '?'.$returnType; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
34 |
|
return $returnType; |
|
58
|
|
|
} |
|
59
|
144 |
|
return ''; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|