1 | <?php |
||||
2 | /** |
||||
3 | * Base daft objects. |
||||
4 | * |
||||
5 | * @author SignpostMarv |
||||
6 | */ |
||||
7 | declare(strict_types=1); |
||||
8 | |||||
9 | namespace SignpostMarv\DaftObject\EasyDB; |
||||
10 | |||||
11 | use PDO; |
||||
12 | use SignpostMarv\DaftObject\DaftNestedWriteableObject; |
||||
13 | use SignpostMarv\DaftObject\DefinesOwnArrayIdInterface; |
||||
14 | |||||
15 | /** |
||||
16 | * @template T as DaftNestedWriteableObject |
||||
17 | */ |
||||
18 | trait WriteableTreeTrait |
||||
19 | { |
||||
20 | 24 | protected function ObtainLastLeafInTree() : DaftNestedWriteableObject |
|||
21 | { |
||||
22 | /** |
||||
23 | * @var \ParagonIE\EasyDB\EasyDB |
||||
24 | */ |
||||
25 | 24 | $db = $this->db; |
|||
26 | |||||
27 | /** |
||||
28 | * @psalm-var class-string<T> |
||||
29 | */ |
||||
30 | 24 | $type = $this->type; |
|||
31 | |||||
32 | 24 | $sth = $db->prepare( |
|||
33 | 'SELECT ' . |
||||
34 | 24 | implode(',', array_map( |
|||
35 | 24 | [$db, 'escapeIdentifier'], |
|||
36 | 24 | $type::DaftObjectIdProperties() |
|||
37 | )) . |
||||
38 | 24 | ' FROM ' . |
|||
39 | 24 | $this->DaftObjectDatabaseTable() . |
|||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
40 | 24 | ' ORDER BY ' . |
|||
41 | 24 | $db->escapeIdentifier('intNestedLeft') . |
|||
42 | 24 | ' DESC LIMIT 1' |
|||
43 | ); |
||||
44 | |||||
45 | 24 | $sth->execute(); |
|||
46 | |||||
47 | 24 | $res = $sth->fetch(PDO::FETCH_ASSOC); |
|||
48 | |||||
49 | 24 | if (1 === count($res) && ! is_a($type, DefinesOwnArrayIdInterface::class, true)) { |
|||
50 | 24 | $res = current($res); |
|||
51 | } |
||||
52 | |||||
53 | 24 | return $this->RecallDaftObjectOrThrow($res); |
|||
0 ignored issues
–
show
It seems like
RecallDaftObjectOrThrow() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
54 | } |
||||
55 | } |
||||
56 |