one_of   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 12
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 5 3
1
<?php
2
3
namespace iamsaint\yml\validators;
4
5
use iamsaint\yml\BaseObject;
6
use iamsaint\yml\interfaces\Validator;
7
use function in_array;
8
9
/**
10
 * Class one_of
11
 * @package iamsaint\yml\validators
12
 */
13
class one_of implements Validator
14
{
15
    /**
16
     * @param BaseObject $BaseObject
17
     * @param array $attributes
18
     * @param array $options
19
     */
20
    public function validate(BaseObject $BaseObject, array $attributes, array $options = []): void
21
    {
22
        foreach ($attributes as $attribute) {
23
            if (!in_array($BaseObject->$attribute, $options, true)) {
24
                $BaseObject->addError($attribute, $attribute.' must be element of ['.implode(', ', $options).']');
25
            }
26
        }
27
    }
28
}
29