From::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Clarkeash\Converter;
4
5
use Clarkeash\Converter\Contracts\Metric;
6
use Clarkeash\Converter\Exceptions\BadMethodCallException;
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 8
    public function __construct(Convert $convert, Metric $metric)
26
    {
27 8
        $this->convert = $convert;
28 8
        $this->metric = $metric;
29 8
    }
30
31 7
    public function __call($method, $args)
32
    {
33 7
        if (in_array($method, ['from', 'of'])) {
34 7
            $this->value = $args[0];
35 7
            return $this;
36
        }
37
38 7
        if (method_exists($this->metric, $method)) {
39 6
            $rate = call_user_func([$this->metric, $method]);
40
41 6
            $this->convert->setValue($rate * $this->value);
42
43 6
            return new To($this->convert, $this->metric);
44
        }
45
46 1
        BadMethodCallException::throw($method, $this->metric, $this);
47
    }
48
}
49