AsReturn   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 11 2
A getDescription() 0 4 1
A createFailMessage() 0 4 2
1
<?php
2
/**
3
 * ShouldPHP
4
 *
5
 * @author  Gabriel Jacinto <[email protected]>
6
 * @status  dev
7
 * @link    https://github.com/GabrielJMJ/ShouldPHP
8
 * @license MIT
9
 */
10
 
11
namespace Gabrieljmj\Should\Assert\TheMethod\Have;
12
13
use Gabrieljmj\Should\Assert\TheMethod\AbstractMethodAssert;
14
15
class AsReturn extends AbstractMethodAssert
16
{
17
    private $expectedReturn;
18
19
    private $args;
20
21
    private $returned;
22
23
    public function __construct($class, $method, $expectedReturn, array $args)
24
    {
25
        parent::__construct($class, $method);
26
        $this->expectedReturn = $expectedReturn;
27
        $this->args = $args;
28
    }
29
30
    /**
31
     * Executes the assert
32
     *
33
     * @return boolean
34
     */
35
    public function execute()
36
    {
37
        if (is_object($this->class)) {
38
            $ref = new \ReflectionMethod($this->class, $this->method);
39
            $this->returned = $ref->invokeArgs($this->class, $this->args);
40
        } else {
41
            $this->returned = call_user_func_array([$this->class, $this->method], $this->args);
42
        }
43
44
        return $this->returned == $this->expectedReturn;
45
    }
46
47
    /**
48
     * Returns the assert description
49
     *
50
     * @return string
51
     */
52
    public function getDescription()
53
    {
54
        return 'Tests if the return of a method is equal expected.';
55
    }
56
57
    /**
58
     * Creates the fail message
59
     *
60
     * @return string
61
     */
62
    protected function createFailMessage()
63
    {
64
        return 'The return of the method ' . $this->getTestedElement() . ' ' . count($this->args) > 0 ? 'with the arguments ' . print_r($this->args, true) : null . ' is not equal the expected: ' . print_r($this->expectedReturn, true);
65
    }
66
}