ConstraintBuilder::getPathTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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 6
 */
10
namespace FlexPHP\Generator\Domain\Builders\Constraint;
11 6
12
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13
use FlexPHP\Schema\SchemaAttributeInterface;
14 6
use FlexPHP\Schema\SchemaInterface;
15
16 6
final class ConstraintBuilder extends AbstractBuilder
17
{
18
    public function __construct(SchemaInterface $schema)
19
    {
20
        $entity = $this->getInflector()->entity($schema->name());
21
        $rules = \array_reduce(
22
            $schema->attributes(),
23
            function (array $result, SchemaAttributeInterface $schemaAttribute) {
24
                $result[$schemaAttribute->name()] = (new RuleBuilder($schemaAttribute))->build();
25
26
                return $result;
27
            },
28
            []
29
        );
30
31
        parent::__construct(\compact('entity', 'rules'));
32
    }
33
34
    protected function getFileTemplate(): string
35
    {
36
        return 'Constraint.php.twig';
37
    }
38
39
    protected function getPathTemplate(): string
40
    {
41
        return \sprintf('%1$s/FlexPHP/Constraint', parent::getPathTemplate());
42
    }
43
}
44