RequestBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 24 1
A getFileTemplate() 0 3 1
A getPathTemplate() 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 1
 */
10
namespace FlexPHP\Generator\Domain\Builders\Message;
11 1
12
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13
use FlexPHP\Schema\Constants\Action;
14 1
use FlexPHP\Schema\SchemaAttributeInterface;
15
use FlexPHP\Schema\SchemaInterface;
16 1
17
final class RequestBuilder extends AbstractBuilder
18
{
19
    public function __construct(SchemaInterface $schema, string $action)
20
    {
21
        $login = 'email';
22
        $entity = $this->getInflector()->entity($schema->name());
23
        $action = $this->getInflector()->pascalAction($action);
24
        $pkName = $this->getInflector()->camelProperty($schema->pkName());
25
        $pkTypeHint = $schema->pkTypeHint();
26
        $properties = \array_reduce($schema->attributes(), function ($result, SchemaAttributeInterface $property) {
27
            $result[$this->getInflector()->camelProperty($property->name())] = $property;
28
29
            return $result;
30
        }, []);
31
        $header = self::getHeaderFile();
32
        $usePatch = $schema->hasAction(Action::PATCH);
33
34
        parent::__construct(\compact(
35
            'entity',
36
            'header',
37
            'action',
38
            'pkName',
39
            'pkTypeHint',
40
            'login',
41
            'properties',
42
            'usePatch'
43
        ));
44
    }
45
46
    protected function getFileTemplate(): string
47
    {
48
        return 'Request.php.twig';
49
    }
50
51
    protected function getPathTemplate(): string
52
    {
53
        return \sprintf('%1$s/FlexPHP/Message', parent::getPathTemplate());
54
    }
55
}
56