Passed
Push — master ( 3491f1...e1ceb1 )
by Chris
40:32
created

ModelCollectionAsChildPrinter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 56
ccs 0
cts 21
cp 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setupClass() 0 24 1
A __construct() 0 16 1
1
<?php
2
3
namespace Leonidas\Console\Library\Printer\Model;
4
5
use Leonidas\Console\Library\Printer\Model\Abstracts\AbstractClassPrinter;
6
use Leonidas\Library\System\Model\Abstracts\PoweredByModelCollectionKernelTrait;
7
use Nette\PhpGenerator\PhpNamespace;
8
9
class ModelCollectionAsChildPrinter extends AbstractClassPrinter
10
{
11
    public const CORE = 'kernel';
12
13
    protected string $model;
14
15
    protected string $single;
16
17
    protected string $plural;
18
19
    protected string $type;
20
21
    protected string $extends;
22
23
    public function __construct(
24
        string $extends,
25
        string $model,
26
        string $single,
27
        string $plural,
28
        string $namespace,
29
        string $class,
30
        string $type
31
    ) {
32
        parent::__construct($namespace, $class);
33
34
        $this->extends = $extends;
35
        $this->model = $model;
36
        $this->single = $single;
37
        $this->plural = $plural;
38
        $this->type = $type;
39
    }
40
41
    protected function setupClass(PhpNamespace $namespace): object
42
    {
43
        $util = PoweredByModelCollectionKernelTrait::class;
44
45
        $namespace
46
            ->addUse($this->type)
47
            ->addUse($this->extends)
48
            ->addUse($this->model)
49
            ->addUse($util);
50
51
        $class = $namespace->addClass($this->class)
52
            ->setExtends($this->extends)
53
            ->addImplement($this->type);
54
55
        $class->addTrait($util);
56
        // $class->addConstant('MODEL_IDENTIFIER', 'id')->setProtected();
57
        // $class->addConstant('COLLECTION_IS_MAP', true)->setProtected();
58
59
        $constructor = $class->addMethod('__construct')->setVariadic(true);
60
61
        $constructor->addParameter($this->plural)->setType($this->model);
62
        $constructor->setBody(sprintf('$this->initKernel($%s);', $this->plural));
63
64
        return $class;
65
    }
66
}
67