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

From   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 48
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A from() 0 6 1
A __call() 0 12 2
1
<?php
2
3
namespace Clarkeash\Converter;
4
5
use BadMethodCallException;
6
use Clarkeash\Converter\Contracts\Metric;
7
8
class From
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
    /**
21
     * @var int
22
     */
23
    private $value = 0;
24
25 5
    public function __construct(Convert $convert, Metric $metric)
26
    {
27 5
        $this->convert = $convert;
28 5
        $this->metric = $metric;
29 5
    }
30
31
    /**
32
     * @param $value
33
     *
34
     * @return $this
35
     */
36 4
    public function from($value)
37
    {
38 4
        $this->value = $value;
39
40 4
        return $this;
41
    }
42
43 4
    public function __call($method, $args)
44
    {
45 4
        if (method_exists($this->metric, $method)) {
46 3
            $rate = call_user_func([$this->metric, $method]);
47
48 3
            $this->convert->setValue($rate * $this->value);
49
50 3
            return new To($this->convert, $this->metric);
51
        }
52
53 1
        throw new BadMethodCallException(sprintf('Method: %s does not exist on class: %s', $method, get_class($this->metric)));
54
    }
55
}
56