1 | <?php |
||||
2 | |||||
3 | namespace Bdf\Prime\Relations; |
||||
4 | |||||
5 | use Bdf\Prime\Query\Custom\KeyValue\KeyValueQuery; |
||||
6 | use Bdf\Prime\Query\ReadCommandInterface; |
||||
7 | |||||
8 | /** |
||||
9 | * HasOne |
||||
10 | * |
||||
11 | * @template L as object |
||||
12 | * @template R as object |
||||
13 | * |
||||
14 | * @extends OneOrMany<L, R> |
||||
15 | */ |
||||
16 | class HasOne extends OneOrMany |
||||
17 | { |
||||
18 | /** |
||||
19 | * {@inheritdoc} |
||||
20 | */ |
||||
21 | protected $saveStrategy = self::SAVE_STRATEGY_ADD; |
||||
22 | |||||
23 | /** |
||||
24 | * Store the relation query for optimisation purpose |
||||
25 | * |
||||
26 | * @var KeyValueQuery<\Bdf\Prime\Connection\ConnectionInterface, R>|null |
||||
27 | */ |
||||
28 | private $relationQuery; |
||||
29 | |||||
30 | |||||
31 | /** |
||||
32 | * {@inheritdoc} |
||||
33 | */ |
||||
34 | 12 | protected function getForeignInfos(): array |
|||
35 | { |
||||
36 | 12 | return [$this->distant, $this->distantKey]; |
|||
37 | } |
||||
38 | |||||
39 | /** |
||||
40 | * {@inheritdoc} |
||||
41 | */ |
||||
42 | 157 | protected function relationQuery($keys, $constraints): ReadCommandInterface |
|||
43 | { |
||||
44 | // Constraints can be on relation attributes : builder must be used |
||||
45 | // @todo Handle "bulk select" |
||||
46 | 157 | if (count($keys) !== 1 || $constraints || $this->constraints) { |
|||
0 ignored issues
–
show
|
|||||
47 | 27 | return $this->query($keys, $constraints)->by($this->distantKey); |
|||
0 ignored issues
–
show
The method
by() does not exist on Bdf\Prime\Query\QueryInterface . It seems like you code against a sub-type of said class. However, the method does not exist in Bdf\Prime\Query\SqlQueryInterface . Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
48 | } |
||||
49 | |||||
50 | 136 | if ($this->relationQuery) { |
|||
51 | 60 | return $this->relationQuery->where($this->distantKey, $keys[0]); |
|||
52 | } |
||||
53 | |||||
54 | 89 | $query = $this->distant->queries()->keyValue($this->distantKey, $keys[0]); |
|||
55 | |||||
56 | 89 | if (!$query) { |
|||
0 ignored issues
–
show
|
|||||
57 | return $this->query($keys, $constraints)->by($this->distantKey); |
||||
58 | } |
||||
59 | |||||
60 | 89 | return $this->relationQuery = $query->by($this->distantKey); |
|||
0 ignored issues
–
show
The method
by() does not exist on Bdf\Prime\Query\Contract...\KeyValueQueryInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to Bdf\Prime\Query\Contract...\KeyValueQueryInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
61 | } |
||||
62 | } |
||||
63 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.