| @@ 20-50 (lines=31) @@ | ||
| 17 | /** |
|
| 18 | * Constraint for the "maxProperties" keyword. |
|
| 19 | */ |
|
| 20 | class MaxPropertiesConstraint extends AbstractCountConstraint |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * {@inheritdoc} |
|
| 24 | */ |
|
| 25 | public function keywords() |
|
| 26 | { |
|
| 27 | return ['maxProperties']; |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * {@inheritdoc} |
|
| 32 | */ |
|
| 33 | public function supports($type) |
|
| 34 | { |
|
| 35 | return $type === Types::TYPE_OBJECT; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * {@inheritdoc} |
|
| 40 | */ |
|
| 41 | public function apply($instance, stdClass $schema, Context $context, Walker $walker) |
|
| 42 | { |
|
| 43 | if (count(get_object_vars($instance)) > $schema->maxProperties) { |
|
| 44 | $context->addViolation( |
|
| 45 | 'number of properties should be lesser than or equal to %s', |
|
| 46 | [$schema->maxProperties] |
|
| 47 | ); |
|
| 48 | } |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||
| @@ 20-50 (lines=31) @@ | ||
| 17 | /** |
|
| 18 | * Constraint for the "minProperties" keyword. |
|
| 19 | */ |
|
| 20 | class MinPropertiesConstraint extends AbstractCountConstraint |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * {@inheritdoc} |
|
| 24 | */ |
|
| 25 | public function keywords() |
|
| 26 | { |
|
| 27 | return ['minProperties']; |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * {@inheritdoc} |
|
| 32 | */ |
|
| 33 | public function supports($type) |
|
| 34 | { |
|
| 35 | return $type === Types::TYPE_OBJECT; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * {@inheritdoc} |
|
| 40 | */ |
|
| 41 | public function apply($instance, stdClass $schema, Context $context, Walker $walker) |
|
| 42 | { |
|
| 43 | if (count(get_object_vars($instance)) < $schema->minProperties) { |
|
| 44 | $context->addViolation( |
|
| 45 | 'number of properties should be greater than or equal to %s', |
|
| 46 | [$schema->minProperties] |
|
| 47 | ); |
|
| 48 | } |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||