1 | <?php |
||
17 | abstract class HasOneOrMany extends Relation |
||
18 | { |
||
19 | use HasCollectionResults; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $type = 'hasMany'; |
||
25 | |||
26 | /** |
||
27 | * @return bool |
||
28 | */ |
||
29 | public function save() |
||
39 | |||
40 | /** |
||
41 | * @return bool |
||
42 | */ |
||
43 | public function hasResults() |
||
47 | |||
48 | /** |
||
49 | * @param Record $item |
||
50 | */ |
||
51 | 1 | public function saveResult(Record $item) |
|
52 | { |
||
53 | 1 | $pk = $this->getManager()->getPrimaryKey(); |
|
54 | 1 | $fk = $this->getFK(); |
|
55 | 1 | $item->{$fk} = $this->getItem()->{$pk}; |
|
56 | 1 | $item->saveRecord(); |
|
57 | 1 | } |
|
58 | |||
59 | public function initResults() |
||
67 | |||
68 | /** |
||
69 | * @param RecordCollection $collection |
||
70 | * @param Collection $items |
||
71 | */ |
||
72 | public function populateCollection(RecordCollection $collection, $items) |
||
78 | |||
79 | /** @noinspection PhpMissingParentCallCommonInspection |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | 1 | public function populateEagerQueryFromFkList($query, $fkList) |
|
83 | { |
||
84 | 1 | $query->where($this->getFK() . ' IN ?', $fkList); |
|
85 | 1 | return $query; |
|
86 | } |
||
87 | |||
88 | /** @noinspection PhpMissingParentCallCommonInspection |
||
89 | * @param RecordCollection $collection |
||
90 | * @return array |
||
91 | */ |
||
92 | 1 | public function getEagerFkList(RecordCollection $collection) |
|
93 | { |
||
94 | 1 | if ($collection->isEmpty()) { |
|
95 | 1 | return []; |
|
96 | } |
||
97 | 1 | $key = $collection->getManager()->getPrimaryKey(); |
|
98 | 1 | $return = HelperBroker::get('Arrays')->pluck($collection, $key); |
|
99 | |||
100 | 1 | return array_unique($return); |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * @param array $dictionary |
||
105 | * @param Collection $collection |
||
106 | * @param Record $record |
||
107 | * @return AssociatedCollection |
||
108 | */ |
||
109 | public function getResultsFromCollectionDictionary($dictionary, $collection, $record) |
||
122 | |||
123 | /** |
||
124 | * Build model dictionary keyed by the relation's foreign key. |
||
125 | * |
||
126 | * @param RecordCollection $collection |
||
127 | * @return array |
||
128 | */ |
||
129 | protected function buildDictionary(RecordCollection $collection) |
||
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | protected function getDictionaryKey() |
||
146 | } |
||
147 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.