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

From::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 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
    public function __construct(Convert $convert, Metric $metric)
26
    {
27
        $this->convert = $convert;
28
        $this->metric = $metric;
29
    }
30
31
    /**
32
     * @param $value
33
     *
34
     * @return $this
35
     */
36
    public function from($value)
37
    {
38
        $this->value = $value;
39
40
        return $this;
41
    }
42
43
    public function __call($method, $args)
44
    {
45
        if (method_exists($this->metric, $method)) {
46
            $rate = call_user_func([$this->metric, $method]);
47
48
            $this->convert->setValue($rate * $this->value);
49
50
            return new To($this->convert, $this->metric);
51
        }
52
53
        throw new BadMethodCallException(sprintf('Method: %s does not exist on class: %s', $method, get_class($this->metric)));
54
    }
55
}
56