Conditions | 3 |
Paths | 3 |
Total Lines | 19 |
Code Lines | 9 |
Lines | 19 |
Ratio | 100 % |
Changes | 0 |
1 | <?php |
||
34 | public function __construct($stringData) |
||
35 | { |
||
36 | if (!is_string($stringData)) { |
||
37 | throw new InvalidArgumentException('Given data is not a string'); |
||
38 | } |
||
39 | |||
40 | if (!preg_match('#^([0-9]+)/([0-9]+)s?$#', $stringData, $matches)) { |
||
41 | throw new RuntimeException('Given exposure time is not in a valid format. |
||
42 | Need: "1/<number>" or "1/<number>s"'); |
||
43 | } |
||
44 | |||
45 | $numerator = (int) $matches[1]; |
||
46 | $denominator = (int) $matches[2]; |
||
47 | |||
48 | // normalize: |
||
49 | $denominator /= $numerator; |
||
50 | |||
51 | $this->setStringData("1/{$denominator}"); |
||
52 | } |
||
53 | |||
68 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.