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

ModelCollectionPrinter::setupClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 14
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 25
ccs 0
cts 15
cp 0
crap 2
rs 9.7998
1
<?php
2
3
namespace Leonidas\Console\Library\Printer\Model;
4
5
use Leonidas\Console\Library\Printer\Model\Abstracts\AbstractCompleteModelCollectionPrinter;
6
use Leonidas\Library\System\Model\Abstracts\AbstractModelCollection;
7
use Leonidas\Library\System\Model\Abstracts\PoweredByModelCollectionKernelTrait;
8
use Nette\PhpGenerator\PhpNamespace;
9
10
class ModelCollectionPrinter extends AbstractCompleteModelCollectionPrinter
11
{
12
    protected function setupClass(PhpNamespace $namespace): object
13
    {
14
        $base = AbstractModelCollection::class;
15
        $util = PoweredByModelCollectionKernelTrait::class;
16
17
        $this->buildDefaultNamespace($namespace)
18
            ->addUse($base)
19
            ->addUse($util);
20
21
        $class = $namespace->addClass($this->class)
22
            ->setExtends($base)
23
            ->addImplement($this->type);
24
25
        $class->addTrait($util);
26
        // $class->addConstant('MODEL_IDENTIFIER', 'id')->setProtected();
27
        // $class->addConstant('COLLECTION_IS_MAP', true)->setProtected();
28
29
        $constructor = $class->addMethod('__construct')->setVariadic(true);
30
31
        $constructor->addParameter($this->plural)->setType($this->model);
32
        $constructor->setBody(
33
            sprintf('$this->initKernel($%s);', $this->plural)
34
        );
35
36
        return $class;
37
    }
38
}
39