CropTypeMachineNameValidationConstraintValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 9 2
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 CropTypeMachineNameValidationConstraintValidator 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
    // '0' is invalid, since elsewhere we check it using empty().
25
    /** @var \Drupal\crop\Entity\CropType $value */
26
    if (trim($value->id()) == '0') {
27
      $this->context->buildViolation($constraint->message)
28
        ->atPath('id')
29
        ->addViolation();
30
    }
31
  }
32
33
}
34