From   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 41
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 17 3
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