Conditions | 5 |
Paths | 2 |
Total Lines | 19 |
Code Lines | 14 |
Lines | 9 |
Ratio | 47.37 % |
Changes | 0 |
1 | <?php |
||
28 | public function validate($value, array $path = []) |
||
29 | { |
||
30 | if (!($value instanceof TileInterface)) { |
||
31 | throw new ValidationException('Value is not a Tile', $path); |
||
32 | } |
||
33 | if (!$this->size) { |
||
34 | return; |
||
35 | } |
||
36 | $height = $value->getImage()->getHeight(); |
||
37 | $width = $value->getImage()->getWidth(); |
||
38 | View Code Duplication | if ($height !== $this->size->getHeight()) { |
|
|
|||
39 | $template = 'Tile height is %d (%d expected)'; |
||
40 | $message = sprintf($template, $height, $this->size->getHeight()); |
||
41 | throw new ValidationException($message, $path); |
||
42 | } |
||
43 | View Code Duplication | if ($width !== $this->size->getWidth()) { |
|
44 | $template = 'Tile width is %d (%d expected)'; |
||
45 | $message = sprintf($template, $width, $this->size->getWidth()); |
||
46 | throw new ValidationException($message, $path); |
||
47 | } |
||
50 |
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.