Completed
Push — master ( 1fdfb3...bdbfd8 )
by Ashley
01:31
created

Add::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

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