Test Failed
Push — master ( 76b4e9...616218 )
by SignpostMarv
01:57
created

WriteableTreeTrait::RecallDaftObjectOrThrow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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
use SignpostMarv\DaftObject\SuitableForRepositoryType;
15
16
/**
17
* @template T as DaftNestedWriteableObject
18
*/
19
trait WriteableTreeTrait
20 24
{
21
    abstract protected function DaftObjectDatabaseTable() : string;
22
23
    /**
24
    * @param scalar|(scalar|array|object|null)[] $id
25 24
    *
26
    * @psalm-param class-string<T> $type
27
    *
28
    * @psalm-return T
29
    */
30 24
    public function RecallDaftObjectOrThrow(
31
        $id,
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

31
        /** @scrutinizer ignore-unused */ $id,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32 24
        string $type = SuitableForRepositoryType::class
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

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

32
        /** @scrutinizer ignore-unused */ string $type = SuitableForRepositoryType::class

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    ) : SuitableForRepositoryType;
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return SignpostMarv\DaftObject\SuitableForRepositoryType. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
34 24
35 24
    protected function ObtainLastLeafInTree() : DaftNestedWriteableObject
36 24
    {
37
        /**
38 24
        * @var \ParagonIE\EasyDB\EasyDB
39 24
        */
40 24
        $db = $this->db;
41 24
42 24
        /**
43
        * @psalm-var class-string<T>
44
        */
45 24
        $type = $this->type;
46
47 24
        $sth = $db->prepare(
48
            'SELECT ' .
49 24
            implode(',', array_map(
50 24
                [$db, 'escapeIdentifier'],
51
                $type::DaftObjectIdProperties()
52
            )) .
53 24
            ' FROM ' .
54
            $this->DaftObjectDatabaseTable() .
55
            ' ORDER BY ' .
56
            $db->escapeIdentifier('intNestedLeft') .
57
            ' DESC LIMIT 1'
58
        );
59
60
        $sth->execute();
61
62
        $res = $sth->fetch(PDO::FETCH_ASSOC);
63
64
        if (1 === count($res) && ! is_a($type, DefinesOwnArrayIdInterface::class, true)) {
65
            $res = current($res);
66
        }
67
68
        return $this->RecallDaftObjectOrThrow($res);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->RecallDaftObjectOrThrow($res) returns the type SignpostMarv\DaftObject\SuitableForRepositoryType which includes types incompatible with the type-hinted return SignpostMarv\DaftObject\DaftNestedWriteableObject.
Loading history...
69
    }
70
}
71