validate()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\crop\Plugin\Validation\Constraint;
4
5
use Symfony\Component\Validator\Constraint;
6
use Symfony\Component\Validator\ConstraintValidator;
7
8
/**
9
 * Checks if the crop type is valid.
10
 */
11
class CropTypeAspectRatioValidationConstraintValidator extends ConstraintValidator {
12
13
  /**
14
   * Validator 2.5 and upwards compatible execution context.
15
   *
16
   * @var \Symfony\Component\Validator\Context\ExecutionContextInterface
17
   */
18
  protected $context;
19
20
  /**
21
   * {@inheritdoc}
22
   */
23
  public function validate($value, Constraint $constraint) {
24
    /** @var \Drupal\crop\Entity\CropType $value */
25
    $aspect_ratio = $value->getAspectRatio();
26
    if (!empty($aspect_ratio) && !preg_match($value::VALIDATION_REGEXP, $aspect_ratio)) {
27
      $this->context->buildViolation($constraint->message)
28
        ->atPath('aspect_ratio')
29
        ->addViolation();
30
    }
31
  }
32
33
}
34