Add   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 46
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __call() 0 14 2
1
<?php
2
3
namespace Clarkeash\Converter;
4
5
use Clarkeash\Converter\Contracts\Metric;
6
use Clarkeash\Converter\Exceptions\BadMethodCallException;
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
        BadMethodCallException::throw($method, $this->metric, $this);
52
    }
53
}
54