1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\Prime\Relations\Util; |
4
|
|
|
|
5
|
|
|
use Bdf\Prime\Query\QueryInterface; |
6
|
|
|
use Bdf\Prime\Query\ReadCommandInterface; |
7
|
|
|
use Bdf\Prime\Relations\AbstractRelation; |
8
|
|
|
use Bdf\Prime\Relations\RelationInterface; |
9
|
|
|
use Bdf\Prime\Repository\RepositoryInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Adds foreign key accessor helpers for relations based on single foreign key |
13
|
|
|
* |
14
|
|
|
* @psalm-require-extends AbstractRelation |
15
|
|
|
* |
16
|
|
|
* @template L as object |
17
|
|
|
* @template R as object |
18
|
|
|
*/ |
19
|
|
|
trait ForeignKeyRelation |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The local property for the relation |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $localKey; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The distant key |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $distantKey; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
* |
39
|
|
|
* @param Q $query |
|
|
|
|
40
|
|
|
* @param mixed $value |
41
|
|
|
* @return Q |
|
|
|
|
42
|
|
|
* @template Q as \Bdf\Prime\Query\Contract\Whereable&ReadCommandInterface |
|
|
|
|
43
|
|
|
* @psalm-suppress InvalidReturnType |
|
|
|
|
44
|
|
|
* |
45
|
|
|
* @see AbstractRelation::applyWhereKeys() |
46
|
|
|
*/ |
47
|
77 |
|
protected function applyWhereKeys(ReadCommandInterface $query, $value): ReadCommandInterface |
|
|
|
|
48
|
|
|
{ |
49
|
77 |
|
return $query->where($this->distantKey, $value); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the local key value from an entity |
54
|
|
|
* If an array is given, get array of key value |
55
|
|
|
* |
56
|
|
|
* @param L|L[] $entity |
57
|
|
|
* |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
36 |
|
protected function getLocalKeyValue($entity) |
61
|
|
|
{ |
62
|
36 |
|
$mapper = $this->localRepository()->mapper(); |
63
|
|
|
|
64
|
36 |
|
if (!is_array($entity)) { |
65
|
34 |
|
return $mapper->extractOne($entity, $this->localKey); |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
$keys = []; |
69
|
|
|
|
70
|
2 |
|
foreach ($entity as $e) { |
71
|
2 |
|
$keys[] = $mapper->extractOne($e, $this->localKey); |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
return $keys; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set the local key value on an entity |
79
|
|
|
* |
80
|
|
|
* @param L $entity |
|
|
|
|
81
|
|
|
* @param mixed $id |
82
|
|
|
* |
83
|
|
|
* @return void |
|
|
|
|
84
|
|
|
*/ |
85
|
|
|
protected function setLocalKeyValue($entity, $id): void |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$this->localRepository()->mapper()->hydrateOne($entity, $this->localKey, $id); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get the local key value from an entity |
92
|
|
|
* |
93
|
|
|
* @param R $entity |
|
|
|
|
94
|
|
|
* |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
13 |
|
protected function getDistantKeyValue($entity) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
/** @psalm-suppress InvalidArgument */ |
|
|
|
|
100
|
13 |
|
return $this->relationRepository()->mapper()->extractOne($entity, $this->distantKey); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get the distance key value on an entity |
105
|
|
|
* |
106
|
|
|
* @param R $entity |
107
|
|
|
* @param mixed $id |
108
|
|
|
* |
109
|
|
|
* @return void |
|
|
|
|
110
|
|
|
*/ |
111
|
|
|
protected function setDistantKeyValue($entity, $id): void |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
/** @psalm-suppress InvalidArgument */ |
|
|
|
|
114
|
|
|
$this->relationRepository()->mapper()->hydrateOne($entity, $this->distantKey, $id); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* {@inheritdoc} |
119
|
|
|
* |
120
|
|
|
* @see RelationInterface::relationRepository() |
121
|
|
|
* @return RepositoryInterface<R> |
|
|
|
|
122
|
|
|
*/ |
123
|
|
|
abstract public function relationRepository(): RepositoryInterface; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
* |
128
|
|
|
* @see RelationInterface::localRepository() |
129
|
|
|
* @return RepositoryInterface<L> |
|
|
|
|
130
|
|
|
*/ |
131
|
|
|
abstract public function localRepository(): RepositoryInterface; |
132
|
|
|
} |
133
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths