MinSizeSliderImageValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 2
A isValid() 0 8 4
1
<?php
2
3
namespace App\Validator;
4
5
use App\Entity\Performance;
6
use Symfony\Component\Validator\ConstraintValidator;
7
use Symfony\Component\Validator\Constraint;
8
9
/**
10
 * Class MinSizeSliderImageValidator
11
 * @package App\Validator
12
 */
13
class MinSizeSliderImageValidator extends ConstraintValidator
14
{
15
    const MIN_HEIGHT = 500;
16
    const MIN_WIDTH = 1000;
17
18
    /**
19
     * @param Performance $object
20
     * @param Constraint                    $constraint
21
     */
22 7
    public function validate($object, Constraint $constraint)
23
    {
24 7
        if (!$this->isValid($object)) {
25 5
            $this->context->buildViolation($constraint->message)
26 5
                    ->atPath('sliderImage')
27 5
                    ->setParameter('{{width}}', self::MIN_HEIGHT)
28 5
                    ->setParameter('{{height}}', self::MIN_WIDTH)
29 5
                    ->addViolation()
30
            ;
31
        }
32 7
    }
33
34 15
    public function isValid(Performance $performance)
35
    {
36 15
        if ($performance->getSliderImage() === null) return false;
37 14
        if ($performance->getSliderImage()->getWidth() < self::MIN_WIDTH) return false;
38 8
        if ($performance->getSliderImage()->getHeight() < self::MIN_HEIGHT) return false;
39
40 4
        return true;
41
    }
42
}
43