RepositoryBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 23
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 29
ccs 5
cts 5
cp 1
crap 1
rs 9.552
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\Repository;
11 1
12 1
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13 1
use FlexPHP\Schema\Constants\Action;
14
use FlexPHP\Schema\SchemaInterface;
15
16
final class RepositoryBuilder extends AbstractBuilder
17 1
{
18 1
    public function __construct(SchemaInterface $schema, array $actions)
19
    {
20 1
        $login = 'email';
21
        $item = $this->getInflector()->item($schema->name());
22 1
        $entity = $this->getInflector()->entity($schema->name());
23
        $fkFns = $this->getFkFunctions($schema->fkRelations());
24
        $pkName = $this->getInflector()->pascalProperty($schema->pkName());
25 1
26
        $requests = [];
27 1
        $actions = \array_reduce($actions, function (array $result, string $action) use (&$requests) {
28
            $result[] = $this->getInflector()->camelAction($action);
29
            $requests[] = $this->getInflector()->pascalAction($action);
30
31
            return $result;
32
        }, []);
33
        $header = self::getHeaderFile();
34
        $usePatch = $schema->hasAction(Action::PATCH);
35
36
        parent::__construct(
37
            \compact(
38
                'header',
39
                'entity',
40
                'item',
41
                'actions',
42
                'requests',
43
                'login',
44
                'fkFns',
45
                'pkName',
46
                'usePatch'
47
            )
48
        );
49
    }
50
51
    protected function getFileTemplate(): string
52
    {
53
        return 'Repository.php.twig';
54
    }
55
56
    protected function getPathTemplate(): string
57
    {
58
        return \sprintf('%1$s/FlexPHP/Repository', parent::getPathTemplate());
59
    }
60
}
61