TestTableOneRepository   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 332
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 99
dl 0
loc 332
rs 10
c 0
b 0
f 0
wmc 14

14 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteEntity() 0 3 1
A readCount() 0 3 1
A read() 0 3 1
A readCountWithAllQueryParts() 0 3 1
A readWithAllQueryParts() 0 3 1
A createPaginator() 0 3 1
A create() 0 29 1
A createReplace() 0 29 1
A createOnDuplicateKeyUpdate() 0 30 1
A createIgnore() 0 29 1
A getEntityClass() 0 3 1
A deleteRow() 0 14 1
A readWithAllQueryPartsQuery() 0 32 1
A updateRow() 0 24 1
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Tests\Behat\Bootstrap\Generated\LightOrmMysql\Repository;
4
5
use Janisbiz\LightOrm\Dms\MySQL\Enum\KeywordEnum;
6
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\QueryBuilderInterface;
7
use Janisbiz\LightOrm\Dms\MySQL\Repository\AbstractRepository;
8
use Janisbiz\LightOrm\Tests\Behat\Bootstrap\Generated\LightOrmMysql\Entity\TestTableOneEntity;
9
use Janisbiz\LightOrm\Tests\Behat\Bootstrap\Generated\LightOrmMysql\Entity\TestTableOneTwoEntity;
10
use Janisbiz\LightOrm\Tests\Behat\Bootstrap\Generated\LightOrmMysql\Entity\TestTableTwoEntity;
11
12
class TestTableOneRepository extends AbstractRepository
13
{
14
    /**
15
     * @param null|int $id
16
     * @param int $intColNotNull
17
     * @param string $varcharColNotNull
18
     * @param float $floatColNotNull
19
     * @param null|int $intColNull
20
     * @param null|string $varcharColNull
21
     * @param null|float $floatColNull
22
     * @param null|string $createdAt
23
     * @param null|string $updatedAt
24
     *
25
     * @return TestTableOneEntity
26
     */
27
    public function create(
28
        ?int $id,
29
        int $intColNotNull,
30
        string $varcharColNotNull,
31
        float $floatColNotNull,
32
        ?int $intColNull = null,
33
        ?string $varcharColNull = null,
34
        ?float $floatColNull = null,
35
        ?string $createdAt = null,
36
        ?string $updatedAt = null
37
    ) {
38
        $testTableOneEntity = (new TestTableOneEntity())
39
            ->setId($id)
40
            ->setIntColNotNull($intColNotNull)
41
            ->setVarcharColNotNull($varcharColNotNull)
42
            ->setFloatColNotNull($floatColNotNull)
43
            ->setIntColNull($intColNull)
44
            ->setVarcharColNull($varcharColNull)
45
            ->setFloatColNull($floatColNull)
46
            ->setCreatedAt($createdAt)
47
            ->setUpdatedAt($updatedAt)
48
        ;
49
50
        $this
51
            ->createQueryBuilder($testTableOneEntity)
52
            ->insert()
53
        ;
54
55
        return $testTableOneEntity;
56
    }
57
58
    /**
59
     * @param null|int $id
60
     * @param int $intColNotNull
61
     * @param string $varcharColNotNull
62
     * @param float $floatColNotNull
63
     * @param null|int $intColNull
64
     * @param null|string $varcharColNull
65
     * @param null|float $floatColNull
66
     * @param null|string $createdAt
67
     * @param null|string $updatedAt
68
     *
69
     * @return TestTableOneEntity
70
     */
71
    public function createOnDuplicateKeyUpdate(
72
        ?int $id,
73
        int $intColNotNull,
74
        string $varcharColNotNull,
75
        float $floatColNotNull,
76
        ?int $intColNull = null,
77
        ?string $varcharColNull = null,
78
        ?float $floatColNull = null,
79
        ?string $createdAt = null,
80
        ?string $updatedAt = null
81
    ) {
82
        $testTableOneEntity = (new TestTableOneEntity())
83
            ->setId($id)
84
            ->setIntColNotNull($intColNotNull)
85
            ->setVarcharColNotNull($varcharColNotNull)
86
            ->setFloatColNotNull($floatColNotNull)
87
            ->setIntColNull($intColNull)
88
            ->setVarcharColNull($varcharColNull)
89
            ->setFloatColNull($floatColNull)
90
            ->setCreatedAt($createdAt)
91
            ->setUpdatedAt($updatedAt)
92
        ;
93
94
        $this
95
            ->createQueryBuilder($testTableOneEntity)
96
            ->onDuplicateKeyUpdate(TestTableOneEntity::COLUMN_UPDATED_AT, $updatedAt)
97
            ->insert()
98
        ;
99
100
        return $testTableOneEntity;
101
    }
102
103
    /**
104
     * @param null|int $id
105
     * @param int $intColNotNull
106
     * @param string $varcharColNotNull
107
     * @param float $floatColNotNull
108
     * @param null|int $intColNull
109
     * @param null|string $varcharColNull
110
     * @param null|float $floatColNull
111
     * @param null|string $createdAt
112
     * @param null|string $updatedAt
113
     *
114
     * @return TestTableOneEntity
115
     */
116
    public function createIgnore(
117
        ?int $id,
118
        int $intColNotNull,
119
        string $varcharColNotNull,
120
        float $floatColNotNull,
121
        ?int $intColNull = null,
122
        ?string $varcharColNull = null,
123
        ?float $floatColNull = null,
124
        ?string $createdAt = null,
125
        ?string $updatedAt = null
126
    ) {
127
        $testTableOneEntity = (new TestTableOneEntity())
128
            ->setId($id)
129
            ->setIntColNotNull($intColNotNull)
130
            ->setVarcharColNotNull($varcharColNotNull)
131
            ->setFloatColNotNull($floatColNotNull)
132
            ->setIntColNull($intColNull)
133
            ->setVarcharColNull($varcharColNull)
134
            ->setFloatColNull($floatColNull)
135
            ->setCreatedAt($createdAt)
136
            ->setUpdatedAt($updatedAt)
137
        ;
138
139
        $this
140
            ->createQueryBuilder($testTableOneEntity)
141
            ->insertIgnore()
142
        ;
143
144
        return $testTableOneEntity;
145
    }
146
147
    /**
148
     * @param null|int $id
149
     * @param int $intColNotNull
150
     * @param string $varcharColNotNull
151
     * @param float $floatColNotNull
152
     * @param null|int $intColNull
153
     * @param null|string $varcharColNull
154
     * @param null|float $floatColNull
155
     * @param null|string $createdAt
156
     * @param null|string $updatedAt
157
     *
158
     * @return TestTableOneEntity
159
     */
160
    public function createReplace(
161
        ?int $id,
162
        int $intColNotNull,
163
        string $varcharColNotNull,
164
        float $floatColNotNull,
165
        ?int $intColNull = null,
166
        ?string $varcharColNull = null,
167
        ?float $floatColNull = null,
168
        ?string $createdAt = null,
169
        ?string $updatedAt = null
170
    ) {
171
        $testTableOneEntity = (new TestTableOneEntity())
172
            ->setId($id)
173
            ->setIntColNotNull($intColNotNull)
174
            ->setVarcharColNotNull($varcharColNotNull)
175
            ->setFloatColNotNull($floatColNotNull)
176
            ->setIntColNull($intColNull)
177
            ->setVarcharColNull($varcharColNull)
178
            ->setFloatColNull($floatColNull)
179
            ->setCreatedAt($createdAt)
180
            ->setUpdatedAt($updatedAt)
181
        ;
182
183
        $this
184
            ->createQueryBuilder($testTableOneEntity)
185
            ->replace()
186
        ;
187
188
        return $testTableOneEntity;
189
    }
190
191
    /**
192
     * @return TestTableOneEntity[]
193
     */
194
    public function read()
195
    {
196
        return $this->createQueryBuilder()->find();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQueryBuilder()->find() returns the type Janisbiz\LightOrm\Entity\EntityInterface[]|string which is incompatible with the documented return type Janisbiz\LightOrm\Tests\...ty\TestTableOneEntity[].
Loading history...
197
    }
198
199
    /**
200
     * @return TestTableOneEntity[]
201
     */
202
    public function readWithAllQueryParts()
203
    {
204
        return $this->readWithAllQueryPartsQuery()->find();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->readWithAl...eryPartsQuery()->find() returns the type Janisbiz\LightOrm\Entity\EntityInterface[]|string which is incompatible with the documented return type Janisbiz\LightOrm\Tests\...ty\TestTableOneEntity[].
Loading history...
205
    }
206
207
    /**
208
     * @return int
209
     */
210
    public function readCount()
211
    {
212
        return $this->createQueryBuilder()->count();
213
    }
214
215
    /**
216
     * @return int
217
     */
218
    public function readCountWithAllQueryParts()
219
    {
220
        return $this->readWithAllQueryPartsQuery()->count();
221
    }
222
223
    /**
224
     * @param int $pageSize
225
     * @param int $currentPage
226
     *
227
     * @return TestTableOneEntity[]
228
     */
229
    public function createPaginator($pageSize, $currentPage)
230
    {
231
        return $this->paginator($this->createQueryBuilder(), (int) $pageSize, (int) $currentPage);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->paginator(...ize, (int)$currentPage) returns the type Janisbiz\LightOrm\Paginator\Paginator which is incompatible with the documented return type Janisbiz\LightOrm\Tests\...ty\TestTableOneEntity[].
Loading history...
232
    }
233
234
    /**
235
     * @param int $id
236
     * @param int $intColNotNull
237
     * @param string $varcharColNotNull
238
     * @param float $floatColNotNull
239
     * @param null|int $intColNull
240
     * @param null|string $varcharColNull
241
     * @param null|float $floatColNull
242
     * @param null|string $createdAt
243
     * @param null|string $updatedAt
244
     *
245
     * @return TestTableOneEntity
246
     */
247
    public function updateRow(
248
        $id,
249
        $varcharColNotNull,
250
        $varcharColNull = null,
251
        $updatedAt = null
252
    ) {
253
        $testTableOneEntity = $this
254
            ->createQueryBuilder()
255
            ->where(
256
                'test_table_one.id = :id',
257
                [
258
                    'id' => $id,
259
                ]
260
            )
261
            ->findOne()
262
        ;
263
264
        $testTableOneEntity
265
            ->setVarcharColNotNull($varcharColNotNull)
0 ignored issues
show
Bug introduced by
The method setVarcharColNotNull() does not exist on Janisbiz\LightOrm\Entity\EntityInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Janisbiz\LightOrm\Entity\EntityInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

265
            ->/** @scrutinizer ignore-call */ 
266
              setVarcharColNotNull($varcharColNotNull)
Loading history...
266
            ->setVarcharColNull($varcharColNull)
267
            ->setUpdatedAt($updatedAt)
268
        ;
269
270
        return $this->createQueryBuilder($testTableOneEntity)->update();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...bleOneEntity)->update() also could return the type Janisbiz\LightOrm\Entity...nterface|boolean|string which is incompatible with the documented return type Janisbiz\LightOrm\Tests\...tity\TestTableOneEntity.
Loading history...
Bug introduced by
It seems like $testTableOneEntity can also be of type string; however, parameter $entity of Janisbiz\LightOrm\Dms\My...y::createQueryBuilder() does only seem to accept Janisbiz\LightOrm\Entity\EntityInterface|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

270
        return $this->createQueryBuilder(/** @scrutinizer ignore-type */ $testTableOneEntity)->update();
Loading history...
271
    }
272
273
    /**
274
     * @param int $id
275
     */
276
    public function deleteRow($id)
277
    {
278
        $testTableOneEntity = $this
279
            ->createQueryBuilder()
280
            ->where(
281
                'test_table_one.id = :id',
282
                [
283
                    'id' => $id,
284
                ]
285
            )
286
            ->findOne()
287
        ;
288
289
        $this->createQueryBuilder($testTableOneEntity)->delete();
0 ignored issues
show
Bug introduced by
It seems like $testTableOneEntity can also be of type string; however, parameter $entity of Janisbiz\LightOrm\Dms\My...y::createQueryBuilder() does only seem to accept Janisbiz\LightOrm\Entity\EntityInterface|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

289
        $this->createQueryBuilder(/** @scrutinizer ignore-type */ $testTableOneEntity)->delete();
Loading history...
290
    }
291
292
    /**
293
     * @param TestTableOneEntity $testTableOneEntity
294
     */
295
    public function deleteEntity(TestTableOneEntity $testTableOneEntity)
296
    {
297
        $this->createQueryBuilder($testTableOneEntity)->delete();
298
    }
299
300
    /**
301
     * @return QueryBuilderInterface
302
     */
303
    private function readWithAllQueryPartsQuery()
304
    {
305
        return $this
306
            ->createQueryBuilder()
307
            ->column('test_table_two.id AS test_table_two_id')
308
            ->innerJoin(TestTableOneTwoEntity::TABLE_NAME, 'test_table_one_two.test_table_one_id = test_table_one.id')
309
            ->innerJoin(TestTableTwoEntity::TABLE_NAME, 'test_table_two.id = test_table_one_two.test_table_two_id')
310
            ->where('test_table_one.id != :id', ['id' => 1])
311
            ->whereIn(
312
                'test_table_one.id',
313
                [
314
                    2,
315
                    3,
316
                    4,
317
                    5
318
                ]
319
            )
320
            ->whereNotIn(
321
                'test_table_one.id',
322
                [
323
                    6,
324
                    7,
325
                    8,
326
                    9,
327
                    10
328
                ]
329
            )
330
            ->groupBy('test_table_one.id')
331
            ->having('test_table_one.id != :havingId', ['havingId' => 3])
332
            ->orderBy('test_table_one.id', KeywordEnum::ASC)
333
            ->limit(1)
334
            ->offset(1)
335
        ;
336
    }
337
338
    /**
339
     * @return string
340
     */
341
    protected function getEntityClass(): string
342
    {
343
        return TestTableOneEntity::class;
344
    }
345
}
346