Completed
Push — master ( 6fc490...f62e5f )
by Ashley
39:42 queued 38:33
created

To::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Clarkeash\Converter;
4
5
use BadMethodCallException;
6
use Clarkeash\Converter\Contracts\Metric;
7
8
class To
9
{
10
    /**
11
     * @var \Clarkeash\Converter\Convert
12
     */
13
    private $convert;
14
15
    /**
16
     * @var \Clarkeash\Converter\Contracts\Metric
17
     */
18
    private $metric;
19
20 3
    public function __construct(Convert $convert, Metric $metric)
21
    {
22 3
        $this->convert = $convert;
23 3
        $this->metric = $metric;
24 3
    }
25
26
    /**
27
     * @return $this
28
     */
29 2
    public function to()
30
    {
31 2
        return $this;
32
    }
33
34 2
    public function __call($method, $args)
35
    {
36 2
        if (method_exists($this->metric, $method)) {
37 1
            $rate = call_user_func([$this->metric, $method]);
38
39 1
            return $this->convert->getValue() / $rate;
40
        }
41
42 1
        throw new BadMethodCallException(sprintf('Method: %s does not exist on class: %s', $method, get_class($this->metric)));
43
    }
44
}
45