Completed
Push — master ( 038cb8...f2d1b9 )
by FX
13:23
created

MineFactor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 85
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A isValid() 0 4 1
A getFactor() 0 4 1
A getR1Factor() 0 4 1
A getR2Factor() 0 4 1
A getR3Factor() 0 4 1
1
<?php
2
3
/**
4
 * Copyright (c) 2016 Francois-Xavier Soubirou.
5
 *
6
 * This file is part of eco4.
7
 *
8
 * eco4 is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * eco4 is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with eco4. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace AppBundle\Entity;
24
25
use InvalidArgumentException;
26
27
/**
28
 * Mine factor class.
29
 *
30
 * @category  Eco4 App
31
 *
32
 * @author    Francois-Xavier Soubirou <[email protected]>
33
 * @copyright 2016 Francois-Xavier Soubirou
34
 * @license   http://www.gnu.org/licenses/   GPLv3
35
 *
36
 * @link      https://www.eco4.io
37
 */
38
class MineFactor
39
{
40
    const FACTORS = array(
41
        '100000000',
42
        '000100000',
43
        '000000100',
44
        '050020005',
45
        '005050020',
46
        '020005050',
47
        '022022022',
48
        '000000000',
49
    );
50
51
    /**
52
     * @var string
53
     */
54
    private $factor;
55
56
    /**
57
     * Constructor.
58
     *
59
     * @param string $factor Factor
60
     *
61
     * @throws InvalidArgumentException
62
     */
63
    public function __construct(string $factor)
64
    {
65
        if (!$this->isValid($factor)) {
66
            throw new InvalidArgumentException('Invalid factor: '.$factor);
67
        }
68
        $this->factor = $factor;
69
    }
70
71
    /**
72
     * Is it a valid factor.
73
     *
74
     * @param string $factor Factor
75
     *
76
     * @return bool
77
     */
78
    public function isValid(string $factor)
79
    {
80
        return in_array($factor, self::FACTORS);
81
    }
82
83
    /**
84
     * Get factor.
85
     *
86
     * @return string
87
     */
88
    public function getFactor(): string
89
    {
90
        return $this->factor;
91
    }
92
93
    /**
94
     * Get r1Factor.
95
     *
96
     * @return int
97
     */
98
    public function getR1Factor(): int
99
    {
100
        return (int) substr($this->factor, 0, 3);
101
    }
102
103
    /**
104
     * Get r2Factor.
105
     *
106
     * @return int
107
     */
108
    public function getR2Factor(): int
109
    {
110
        return (int) substr($this->factor, 3, 3);
111
    }
112
113
    /**
114
     * Get r3Factor.
115
     *
116
     * @return int
117
     */
118
    public function getR3Factor(): int
119
    {
120
        return (int) substr($this->factor, 6, 3);
121
    }
122
}
123