Mock   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 1
dl 0
loc 49
ccs 15
cts 21
cp 0.7143
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A withParams() 0 5 1
A willDo() 0 4 1
A willReturn() 0 4 1
A handler() 0 14 3
1
<?php
2
3
namespace Basis\Test;
4
5
use Basis\Converter;
6
use Basis\Test;
7
use Exception;
8
9
class Mock
10
{
11
    private $converter;
12
    private $test;
13
14
    public $params;
15
    public $result;
16
    public $calls = 0;
17
18 5
    public function __construct(Converter $converter, Test $test, array $params = [])
19
    {
20 5
        $this->converter = $converter;
21 5
        $this->test = $test;
22 5
        if (count($params)) {
23
            $this->params = $params;
24
        }
25 5
    }
26
27
    public function withParams($params)
28
    {
29
        $this->params = $params;
30
        return $this;
31
    }
32
33 5
    public function handler($result)
34
    {
35 5
        $this->result = $result;
36 5
        if (is_string($result)) {
37
            if (!method_exists($this->test, $result)) {
38
                throw new Exception("Invalid method ".get_class($this->test)."::$result");
39
            }
40
            $this->result = function($params) use ($result) {
41 3
                $params = $this->converter->toObject($params);
42 3
                return $this->test->$result($params);
43
            };
44
        }
45 5
        return $this;
46
    }
47
48 1
    public function willDo($result)
49
    {
50 1
        return $this->handler($result);
51
    }
52
53 5
    public function willReturn($result)
54
    {
55 5
        return $this->handler($result);
56
    }
57
}
58