SingleTileValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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