Completed
Push — master ( 89d65b...2465be )
by Ashley
68:37 queued 67:00
created

To   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A to() 0 4 1
A __call() 0 10 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
    public function __construct(Convert $convert, Metric $metric)
21
    {
22
        $this->convert = $convert;
23
        $this->metric = $metric;
24
    }
25
26
    /**
27
     * @return $this
28
     */
29
    public function to()
30
    {
31
        return $this;
32
    }
33
34
    public function __call($method, $args)
35
    {
36
        if (method_exists($this->metric, $method)) {
37
            $rate = call_user_func([$this->metric, $method]);
38
39
            return $this->convert->getValue() / $rate;
40
        }
41
42
        throw new BadMethodCallException(sprintf('Method: %s does not exist on class: %s', $method, get_class($this->metric)));
43
    }
44
}
45