SingleTileValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 24.32 %

Importance

Changes 0
Metric Value
dl 9
loc 37
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B validate() 9 19 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace AmaTeam\Image\Projection\Framework\Validation\Tile;
4
5
use AmaTeam\Image\Projection\API\Tile\TileInterface;
6
use AmaTeam\Image\Projection\Framework\Validation\ValidationException;
7
use AmaTeam\Image\Projection\Framework\Validation\ValidatorInterface;
8
use AmaTeam\Image\Projection\Geometry\Box;
9
10
class SingleTileValidator implements ValidatorInterface
11
{
12
    /**
13
     * @var Box|null
14
     */
15
    private $size;
16
17
    /**
18
     * @param Box $size
19
     */
20
    public function __construct(Box $size = null)
21
    {
22
        $this->size = $size;
23
    }
24
25
    /**
26
     * @inheritDoc
27
     */
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()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
44
            $template = 'Tile width is %d (%d expected)';
45
            $message = sprintf($template, $width, $this->size->getWidth());
46
            throw new ValidationException($message, $path);
47
        }
48
    }
49
}
50