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

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 6
dl 0
loc 11
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Leonidas\Console\Library\Printer\Model\Abstracts;
4
5
use Nette\PhpGenerator\PhpNamespace;
6
7
abstract class AbstractCompleteModelCollectionPrinter extends AbstractModelCollectionPrinter
8
{
9
    use TypedClassPrinterTrait;
10
11
    protected const TEMPLATES = [
12
        'getBy*' => [
13
            'give' => '?@model',
14
            'call' => 'firstWhere',
15
            'pass' => '#*, \'=\', $*',
16
        ],
17
        'hasWhere*Not' => [
18
            'give' => 'bool',
19
            'call' => 'hasWhere',
20
            'pass' => '#*, \'!=\', $*',
21
        ],
22
        'hasWhere*' => [
23
            'give' => 'bool',
24
            'call' => 'hasWhere',
25
            'pass' => '#*, \'=\', $*',
26
        ],
27
        'where*Not' => [
28
            'give' => '@self',
29
            'call' => 'where',
30
            'pass' => '#*, \'!=\', $*',
31
        ],
32
        'where*' => [
33
            'give' => '@self',
34
            'call' => 'where',
35
            'pass' => '#*, \'=\', $*',
36
        ],
37
        'hasWithout*' => [
38
            'give' => 'bool',
39
            'call' => 'hasWhere',
40
            'pass' => '#*, \'not in\', $*',
41
        ],
42
        'hasWith*' => [
43
            'give' => 'bool',
44
            'call' => 'hasWhere',
45
            'pass' => '#*, \'in\', $*',
46
        ],
47
        'without*' => [
48
            'give' => '@self',
49
            'call' => 'where',
50
            'pass' => '#*, \'not in\', $*',
51
        ],
52
        'with*' => [
53
            'give' => '@self',
54
            'call' => 'where',
55
            'pass' => '#*, \'in\', $*',
56
        ],
57
    ];
58
59
    public function __construct(
60
        string $model,
61
        string $single,
62
        string $plural,
63
        string $namespace,
64
        string $class,
65
        string $type
66
    ) {
67
        parent::__construct($model, $single, $plural, $namespace, $class);
68
69
        $this->type = $type;
70
    }
71
72
    protected function buildDefaultNamespace(PhpNamespace $namespace): PhpNamespace
73
    {
74
        return $namespace->addUse($this->type)->addUse($this->model);
75
    }
76
77
    protected function getMethodTemplates(): array
78
    {
79
        return static::TEMPLATES;
80
    }
81
82
    protected function getParameterTypeReplacements(): array
83
    {
84
        return [
85
            ['@model', '@type'],
86
            [$this->model, $this->type],
87
        ];
88
    }
89
}
90