| Conditions | 12 |
| Paths | 21 |
| Total Lines | 44 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 27 | public function validate($attribute, Constraint $constraint): void |
||
| 28 | { |
||
| 29 | /** @var AttributeInterface $attribute */ |
||
| 30 | Assert::isInstanceOf($attribute, AttributeInterface::class); |
||
| 31 | Assert::isInstanceOf($constraint, ValidSelectAttributeConfiguration::class); |
||
| 32 | |||
| 33 | if (SelectAttributeType::TYPE !== $attribute->getType()) { |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | |||
| 37 | $configuration = $attribute->getConfiguration(); |
||
| 38 | |||
| 39 | $min = null; |
||
| 40 | if (!empty($configuration['min'])) { |
||
| 41 | $min = $configuration['min']; |
||
| 42 | } |
||
| 43 | |||
| 44 | $max = null; |
||
| 45 | if (!empty($configuration['max'])) { |
||
| 46 | $max = $configuration['max']; |
||
| 47 | } |
||
| 48 | |||
| 49 | if (null === $min && null === $max) { |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | |||
| 53 | $multiple = $attribute->getConfiguration()['multiple']; |
||
| 54 | if (!$multiple) { |
||
| 55 | $this->context->addViolation($constraint->messageMultiple); |
||
| 56 | |||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | if (null !== $min && null !== $max && $min > $max) { |
||
| 61 | $this->context->addViolation($constraint->messageMaxEntries); |
||
| 62 | |||
| 63 | return; |
||
| 64 | } |
||
| 65 | |||
| 66 | $numberOfChoices = count($attribute->getConfiguration()['choices']); |
||
| 67 | if (null !== $min && $min > $numberOfChoices) { |
||
| 68 | $this->context->addViolation($constraint->messageMinEntries); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 |