To   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 37
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 18 4
1
<?php
2
3
namespace Clarkeash\Converter;
4
5
use Clarkeash\Converter\Contracts\Metric;
6
use Clarkeash\Converter\Exceptions\BadMethodCallException;
7
8
class To
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 7
    public function __construct(Convert $convert, Metric $metric)
21
    {
22 7
        $this->convert = $convert;
23 7
        $this->metric = $metric;
24 7
    }
25
26 6
    public function __call($method, $args)
27
    {
28 6
        if (in_array($method, ['to', 'in', 'into', 'as'])) {
29 6
            return $this;
30
        }
31
32 6
        if ($method == 'and') {
33 1
            return new Add($this->convert, $this->metric, $args[0]);
34
        }
35
36 6
        if (method_exists($this->metric, $method)) {
37 5
            $rate = call_user_func([$this->metric, $method]);
38
39 5
            return $this->convert->getValue() / $rate;
40
        }
41
42 1
        BadMethodCallException::throw($method, $this->metric, $this);
43
    }
44
}
45