Passed
Push — master ( 1208d6...08925d )
by Steffen
08:15
created

LengthConverter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 86.96%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 105
ccs 20
cts 23
cp 0.8696
rs 10
c 2
b 0
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A getName() 0 4 1
A getBaseUnit() 0 4 1
A setUnits() 0 4 1
A addUnit() 0 4 1
1
<?php
2
/*
3
 * This file is part of the unicorn project
4
 *
5
 * (c) Philipp Braeutigam <[email protected]>, Steffen Brand <[email protected]> and contributors
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Xynnn\Unicorn\Converter;
12
13
use Xynnn\Unicorn\Model\Unit;
14
15
class LengthConverter extends AbstractMathematicalConverter
16
{
17
    /**
18
     * @var Unit $nanometer Static instance for conversions
19
     */
20
    public static $nanometer;
21
22
    /**
23
     * @var Unit $micrometer Static instance for conversions
24
     */
25
    public static $micrometer;
26
27
    /**
28
     * @var Unit $millimeter Static instance for conversions
29
     */
30
    public static $millimeter;
31
32
    /**
33
     * @var Unit $centimeter Static instance for conversions
34
     */
35
    public static $centimeter;
36
37
    /**
38
     * @var Unit $decimeter Static instance for conversions
39
     */
40
    public static $decimeter;
41
42
    /**
43
     * @var Unit $meter Static instance for conversions
44
     */
45
    public static $meter;
46
47
    /**
48
     * @var Unit $kilometer Static instance for conversions
49
     */
50
    public static $kilometer;
51
52
    /**
53
     * @var Unit $inch Static instance for conversions
54
     */
55
    public static $inch;
56
57
    /**
58
     * @var Unit $feet Static instance for conversions
59
     */
60
    public static $feet;
61
62
    /**
63
     * @var Unit $yard Static instance for conversions
64
     */
65
    public static $yard;
66
67
    /**
68
     * @var Unit $mile Static instance for conversions
69
     */
70
    public static $mile;
71
72
    /**
73
     * LengthConverter constructor.
74
     */
75 18
    public function __construct()
76
    {
77 18
        $this->units[] = self::$nanometer = new Unit('nanometer', 'nm', '1000000000');
78 18
        $this->units[] = self::$micrometer = new Unit('micrometer', 'µm', '1000000');
79 18
        $this->units[] = self::$millimeter = new Unit('millimeter', 'mm', '1000');
80 18
        $this->units[] = self::$centimeter = new Unit('centimeter', 'cm', '100');
81 18
        $this->units[] = self::$decimeter = new Unit('decimeter', 'dm', '10');
82 18
        $this->units[] = self::$meter = new Unit('meter', 'm', '1');
83 18
        $this->units[] = self::$kilometer = new Unit('kilometer', 'km', '0.001');
84 18
        $this->units[] = self::$inch = new Unit('inch', 'in', bcdiv('1', '0.0254', self::MAX_DECIMALS));
85 18
        $this->units[] = self::$feet = new Unit('feet', 'ft', bcdiv('1', '0.3048', self::MAX_DECIMALS));
86 18
        $this->units[] = self::$yard = new Unit('yard', 'yd', bcdiv('1', '0.9144', self::MAX_DECIMALS));
87 18
        $this->units[] = self::$mile = new Unit('mile', 'm', bcdiv('1', '1609.344', self::MAX_DECIMALS));
88 18
    }
89
90
    /**
91
     * @return string Name of the converter
92
     */
93 4
    public function getName(): string
94
    {
95 4
        return 'unicorn.converter.length';
96
    }
97
98 34
    public function getBaseUnit(): Unit
99
    {
100 34
        return self::$meter;
101
    }
102
103
    /**
104
     * @param array $units
105
     */
106
    public function setUnits(array $units)
107
    {
108
        $this->units = $units;
109
    }
110
111
    /**
112
     * @param Unit $unit
113
     */
114 1
    public function addUnit(Unit $unit)
115
    {
116 1
        $this->units[] = $unit;
117 1
    }
118
119
}
120