Passed
Push — master ( 58a66f...76b4e9 )
by SignpostMarv
09:54
created

WriteableTreeTrait::ObtainLastLeafInTree()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 34
ccs 17
cts 17
cp 1
rs 9.7
c 0
b 0
f 0
cc 3
nc 2
nop 0
crap 3
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
It seems like DaftObjectDatabaseTable() 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 ignore-call  annotation

39
            $this->/** @scrutinizer ignore-call */ 
40
                   DaftObjectDatabaseTable() .
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
Bug introduced by
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 ignore-call  annotation

53
        return $this->/** @scrutinizer ignore-call */ RecallDaftObjectOrThrow($res);
Loading history...
54
    }
55
}
56