FieldSyntaxValidation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 12
c 3
b 0
f 0
dl 0
loc 34
ccs 5
cts 5
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 2
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\Generator\Domain\Validations;
11
12
use FlexPHP\Generator\Domain\Exceptions\FieldSyntaxValidationException;
13
use FlexPHP\Schema\Constants\Keyword;
14
15
final class FieldSyntaxValidation implements ValidationInterface
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $properties;
21
22
    /**
23
     * @var array
24
     */
25
    private $allowedProperties = [
26
        Keyword::NAME,
27
        Keyword::DATATYPE,
28
        Keyword::CONSTRAINTS,
29
        Keyword::TYPE,
30
    ];
31
32
    public function __construct(array $properties)
33
    {
34
        $this->properties = $properties;
35
    }
36
37
    public function validate(): void
38
    {
39
        // foreach ($this->properties as $property) {
40
        //     if (!\in_array($property, $this->allowedProperties)) {
41 102
        //         throw new FieldSyntaxValidationException('Property unknow: ' . $property);
42
        //     }
43 102
        // }
44 102
        \array_map(function ($property): void {
45
            if (!\in_array($property, $this->allowedProperties)) {
46 102
                throw new FieldSyntaxValidationException('Property unknow: ' . $property);
47
            }
48 102
        }, \array_keys($this->properties));
49 102
    }
50
}
51