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

getMethodGiveReplacements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Leonidas\Console\Library\Printer\Model\Abstracts;
4
5
abstract class AbstractModelCollectionPrinter extends AbstractClassPrinter
6
{
7
    public const CORE = 'kernel';
8
9
    public const SIGNATURES = [
10
        'collect' => [
11
            'take' => '@model ...@plural',
12
            'pass' => '$@plural',
13
        ],
14
        'add' => [
15
            'take' => '@model @single',
16
            'call' => 'insert',
17
            'pass' => '$@single',
18
        ],
19
        'hasWithId' => [
20
            'take' => 'int ...$id',
21
            'give' => 'bool',
22
            'call' => 'hasWhere',
23
            'pass' => '\'id\', \'in\', $id',
24
        ],
25
        'hasWith' => [
26
            'take' => 'string $property, ...$values',
27
            'give' => 'bool',
28
            'call' => 'hasWhere',
29
            'pass' => '$property, \'in\', $values',
30
        ],
31
        'hasWhere' => [
32
            'take' => 'string $property, string $operator, $value',
33
            'give' => 'bool',
34
            'pass' => '$property, $operator, $value',
35
        ],
36
        'matches' => [
37
            'take' => '@type @plural',
38
            'give' => 'bool',
39
            'pass' => '$@plural->toArray()',
40
        ],
41
        'getById' => [
42
            'take' => 'int $id',
43
            'give' => '?@model',
44
            'call' => 'firstWhere',
45
            'pass' => '\'id\', \'=\', $id',
46
        ],
47
        'getBy' => [
48
            'take' => 'string $property, $value',
49
            'give' => '?@model',
50
            'call' => 'firstWhere',
51
            'pass' => '$property, \'=\', $value',
52
        ],
53
        'firstWhere' => [
54
            'take' => 'string $property, string $operator, $value',
55
            'give' => '?@model',
56
            'pass' => '$property, $operator, $value',
57
        ],
58
        'first' => [
59
            'give' => '?@model',
60
        ],
61
        'last' => [
62
            'give' => '?@model',
63
        ],
64
        'withId' => [
65
            'take' => 'int ...$id',
66
            'give' => '@self',
67
            'call' => 'where',
68
            'pass' => '\'id\', \'in\', $id',
69
        ],
70
        'withoutId' => [
71
            'take' => 'int ...$id',
72
            'give' => '@self',
73
            'call' => 'where',
74
            'pass' => '\'id\', \'not in\', $id',
75
        ],
76
        'with' => [
77
            'take' => 'string $property, ...$values',
78
            'give' => '@self',
79
            'call' => 'where',
80
            'pass' => '$property, \'in\', $values',
81
        ],
82
        'without' => [
83
            'take' => 'string $property, ...$values',
84
            'give' => '@self',
85
            'call' => 'where',
86
            'pass' => '$property, \'not in\', $values',
87
        ],
88
        'where' => [
89
            'take' => 'string $property, string $operator, $value',
90
            'give' => '@self',
91
            'pass' => '$property, $operator, $value',
92
        ],
93
        'filter' => [
94
            'take' => 'callable $callback',
95
            'give' => '@self',
96
            'pass' => '$callback',
97
        ],
98
        'diff' => [
99
            'take' => '@type ...@plural',
100
            'give' => '@self',
101
            'pass' => '...$this->expose(...$@plural)',
102
        ],
103
        'contrast' => [
104
            'take' => '@type ...@plural',
105
            'give' => '@self',
106
            'pass' => '...$this->expose(...$@plural)',
107
        ],
108
        'intersect' => [
109
            'take' => '@type ...@plural',
110
            'give' => '@self',
111
            'pass' => '...$this->expose(...$@plural)',
112
        ],
113
        'merge' => [
114
            'take' => '@type ...@plural',
115
            'give' => '@self',
116
            'pass' => '...$this->expose(...$@plural)',
117
        ],
118
        'sortBy' => [
119
            'take' => 'string $property, string $order = \'asc\'',
120
            'give' => '@self',
121
            'pass' => '$property, $order',
122
        ],
123
        'sortMapped' => [
124
            'take' => 'array $map, string $property, string $order = \'asc\'',
125
            'give' => '@self',
126
            'pass' => '$map, $property, $order',
127
        ],
128
        'sortCustom' => [
129
            'take' => 'callable $callback, string $order = \'asc\'',
130
            'give' => '@self',
131
            'pass' => '$callback, $order',
132
        ],
133
    ];
134
135
    protected string $model;
136
137
    protected string $single;
138
139
    protected string $plural;
140
141
    public function __construct(
142
        string $model,
143
        string $single,
144
        string $plural,
145
        string $namespace,
146
        string $class
147
    ) {
148
        parent::__construct($namespace, $class);
149
150
        $this->model = $model;
151
        $this->single = $single;
152
        $this->plural = $plural;
153
    }
154
155
    protected function getMethodPassReplacements(): array
156
    {
157
        return [
158
            ['@single', '@plural'],
159
            [$this->single, $this->plural],
160
        ];
161
    }
162
163
    protected function getMethodGiveReplacements(): array
164
    {
165
        return [
166
            ['@model', '@self'],
167
            [$this->model, $this->getClassFqn()],
168
        ];
169
    }
170
171
    protected function getParameterTypeReplacements(): array
172
    {
173
        return [
174
            ['@model', '@type'],
175
            [$this->model, $this->getClassFqn()],
176
        ];
177
    }
178
179
    protected function getParameterNameReplacements(): array
180
    {
181
        return [
182
            ['@single', '@plural'],
183
            [$this->single, $this->plural],
184
        ];
185
    }
186
}
187