Convert::setValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Clarkeash\Converter;
4
5
use Clarkeash\Converter\Exceptions\BadMethodCallException;
6
use Clarkeash\Converter\Metrics\Size;
7
use Clarkeash\Converter\Metrics\Time;
8
9
class Convert
10
{
11
    /**
12
     * @var array
13
     */
14
    protected static $metrics = [
15
        'size' => Size::class,
16
        'time' => Time::class,
17
    ];
18
19
    /**
20
     * @var int
21
     */
22
    protected $value = 0;
23
24
    /**
25
     * @return int
26
     */
27 6
    public function getValue()
28
    {
29 6
        return $this->value;
30
    }
31
32
    /**
33
     * @param int $value
34
     */
35 7
    public function setValue($value)
36
    {
37 7
        $this->value = $value;
38 7
    }
39
40
    /**
41
     * @param $method
42
     * @param $args
43
     *
44
     * @return mixed
45
     */
46 4
    public function __call($method, $args)
47
    {
48 4
        if (array_key_exists($method, static::$metrics)) {
49
50 3
            $metric = new static::$metrics[$method];
51
52 3
            return new From($this, $metric);
53
        }
54
55 1
        BadMethodCallException::throw($method, $this);
56
    }
57
58
    /**
59
     * Proxy to __call
60
     *
61
     * @param $method
62
     * @param $args
63
     *
64
     * @return \Clarkeash\Converter\From
65
     */
66 4
    public static function __callStatic($method, $args)
67
    {
68 4
        $convert = new static;
69
70 4
        return call_user_func([$convert, $method]);
71
    }
72
}
73