Completed
Pull Request — master (#687)
by Dave
02:47
created

Method   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 4 1
A getParameters() 0 6 1
B getReturnType() 0 17 6
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 166
    public function __construct(\ReflectionMethod $method)
28
    {
29 166
        $this->method = $method;
30 166
    }
31
32 166
    public function __call($method, $args)
33
    {
34 166
        return call_user_func_array(array($this->method, $method), $args);
35
    }
36
37
    public function getParameters()
38
    {
39 152
        return array_map(function ($parameter) {
40 80
            return new Parameter($parameter);
41 152
        }, $this->method->getParameters());
42
    }
43
44 152
    public function getReturnType()
45
    {
46 152
        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();
0 ignored issues
show
introduced by
Consider using $this->method->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
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 142
        return '';
60
    }
61
}
62