ArgumentsEqual   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 14 1
A getDescription() 0 4 1
A createFailMessage() 0 5 1
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 ArgumentsEqual extends AbstractMethodAssert
16
{
17
    private $expectedArgs;
18
19
    private $returned;
20
21
    public function __construct($class, $method, array $expectedArgs)
22
    {
23
        parent::__construct($class, $method);
24
        $this->expectedArgs = $expectedArgs;
25
    }
26
27
    /**
28
     * Executes the assert
29
     *
30
     * @return boolean
31
     */
32
    public function execute()
33
    {
34
        $ref = new \ReflectionMethod($this->class, $this->method);
35
        $params = $ref->getParameters();
36
37
        $params = array_map(function ($param)
38
        {
39
            return $param->getName();
40
        }, $params);
41
42
        $this->returned = $params;
43
44
        return $this->expectedArgs === $params;
45
    }
46
47
    /**
48
     * Returns the assert description
49
     *
50
     * @return string
51
     */
52
    public function getDescription()
53
    {
54
        return 'Tests if the arguments of the method are equal expected.';
55
    }
56
57
    /**
58
     * Creates the fail message
59
     *
60
     * @return string
61
     */
62
    protected function createFailMessage()
63
    {
64
        $class = $this->classToStr($this->class);
65
        return 'The arguments of the method ' . $class . '::' . $this->method . ' are incorrect. Expcted: ' . print_r($this->expectedArgs, true) . ' - Returned: ' . print_r($this->returned, true);
66
    }
67
}