Skip to content

Commit de43702

Browse files
committed
done
1 parent e83d5c5 commit de43702

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

phpstan.neon

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ parameters:
1212
- '#Interface must be located in "Contract" or "Contracts" namespace#'
1313
- '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::select\(\).#'
1414
- '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::from\(\).#'
15-
- '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::whereRaw\(\).#'
15+
# - '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::whereRaw\(\).#'
1616
- '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::whereNested\(\).#'
1717
- '#Dynamic call to static method Kalnoy\\Nestedset\\QueryBuilder<.*>::whereIn\(\).#'
1818
- '#Parameter .* \$models .* of method .*::initRelation\(\) should be contravariant with parameter \$models .* of method .*::initRelation\(\)#'
1919
- '#Parameter .* \$models .* of method .*::addEagerConstraints\(\) should be contravariant with parameter \$models .* of method .*::addEagerConstraints\(\)#'
2020
- '#Parameter .* \$models .* of method .*::match\(\) should be contravariant with parameter \$models .* of method .*::match\(\)#'
21+
- '#Parameter .* \$query .* of method .*::getRelationExistenceQuery\(\) should be contravariant with parameter \$query .* of method .*::getRelationExistenceQuery\(\)#'
22+
- '#Parameter .* \$parentQuery .* of method .*::getRelationExistenceQuery\(\) should be contravariant with parameter \$parentQuery .* of method .*::getRelationExistenceQuery\(\)#'
23+
- '#Parameter .* \$results .* of method .*::match\(\) should be contravariant with parameter \$results .* of method .*::match\(\)#'

src/BaseRelation.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ abstract protected function relationExistenceCondition(string $hash, string $tab
8383

8484
/**
8585
* @param EloquentBuilder<NodeModel> $query
86-
* @param EloquentBuilder<NodeModel> $parent
86+
* @param EloquentBuilder<NodeModel> $parentQuery
8787
* @param mixed $columns
8888
*
89-
* @return EloquentBuilder<NodeModel>
89+
* @return QueryBuilder<Tmodelkey,Tmodel>
9090
*/
91-
public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilder $parent,
91+
public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilder $parentQuery,
9292
$columns = ['*']
9393
) {
9494
$query = $this->getParent()->replicate()->newScopedQuery()->select($columns);
@@ -107,7 +107,7 @@ public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilde
107107
$grammar->wrap($this->parent->getLftName()),
108108
$grammar->wrap($this->parent->getRgtName()));
109109

110-
return $query->whereRaw($condition);
110+
return $query->whereRaw($condition); /** @phpstan-ignore-line */
111111
}
112112

113113
/**
@@ -148,7 +148,7 @@ public function getResults()
148148
/**
149149
* Set the constraints for an eager load of the relation.
150150
*
151-
* @param array<int,Tmodel> $models
151+
* @param array<int,NodeModel> $models
152152
*
153153
* @return void
154154
*/
@@ -173,15 +173,16 @@ public function addEagerConstraints(array $models)
173173
/**
174174
* Match the eagerly loaded results to their parents.
175175
*
176-
* @param array<int,Tmodel> $models
177-
* @param EloquentCollection $results
176+
* @param array<int,NodeModel> $models
177+
* @param EloquentCollection<int,NodeModel> $results
178178
* @param string $relation
179179
*
180-
* @return array<int,Tmodel>
180+
* @return array<int,NodeModel>
181181
*/
182182
public function match(array $models, EloquentCollection $results, $relation)
183183
{
184184
foreach ($models as $model) {
185+
/** @disregard P1006 */
185186
$related = $this->matchForModel($model, $results);
186187

187188
$model->setRelation($relation, $related);
@@ -191,18 +192,18 @@ public function match(array $models, EloquentCollection $results, $relation)
191192
}
192193

193194
/**
194-
* @param Tmodel $model
195-
* @param EloquentCollection $results
195+
* @param NodeModel $model
196+
* @param EloquentCollection<int,NodeModel> $results
196197
*
197-
* @return Collection
198+
* @return Collection<int,Tmodelkey,Tmodel>
198199
*/
199200
protected function matchForModel(Model $model, EloquentCollection $results)
200201
{
201-
/** @var Collection<int,Tmodel> */
202+
/** @var Collection<int,Tmodelkey,Tmodel> */
202203
$result = $this->related->newCollection();
203204

204-
/** @var Tmodel $related */
205205
foreach ($results as $related) {
206+
/** @disregard P1006 */
206207
if ($this->matches($model, $related)) {
207208
$result->push($related);
208209
}

src/Collection.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function toTree($root = false)
8888
/**
8989
* @param mixed $root
9090
*
91-
* @return int|string
91+
* @return Tmodelkey
9292
*/
9393
protected function getRootNodeId($root = false)
9494
{
@@ -129,31 +129,32 @@ protected function getRootNodeId($root = false)
129129
*/
130130
public function toFlatTree($root = false): Collection
131131
{
132+
/** @Var Collection<TKey,Tmodelkey,Tmodel> */
132133
$result = new Collection();
133134

134135
if ($this->isEmpty()) {
135-
return $result;
136+
return $result; /** @phpstan-ignore-line */
136137
}
137138

138-
/** @var Node */
139+
/** @var NodeModel */
139140
$first = $this->first();
140-
/** @var Collection<int|string,TModel> */
141+
/** @var Collection<TKey,Tmodelkey,NodeModel> */
141142
$groupedNodes = $this->groupBy($first->getParentIdName());
142143

143-
return $result->flattenTree($groupedNodes, $this->getRootNodeId($root));
144+
return $result->flattenTree($groupedNodes, $this->getRootNodeId($root)); /** @phpstan-ignore-line */
144145
}
145146

146147
/**
147148
* Flatten a tree into a non recursive array.
148149
*
149-
* @param Collection<int|string,Tmodelkey,Tmodel> $groupedNodes
150-
* @param int|string $parentId
150+
* @param Collection<TKey,Tmodelkey,Tmodel> $groupedNodes
151+
* @param Tmodelkey $parentId
151152
*
152153
* @return Collection<TKey,Tmodelkey,Tmodel>
153154
*/
154155
protected function flattenTree(Collection $groupedNodes, $parentId): Collection
155156
{
156-
/** @var array<int,TModel> */
157+
/** @var array<int,NodeModel> */
157158
$nodes = $groupedNodes->get($parentId, []);
158159
foreach ($nodes as $node) {
159160
$this->push($node);

src/DescendantsRelation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ public function addConstraints()
3232
}
3333

3434
/**
35-
* @param QueryBuilder $query
36-
* @param Model $model
35+
* @param QueryBuilder<Tmodelkey,Tmodel> $query
36+
* @param NodeModel $model
3737
*/
3838
protected function addEagerConstraint($query, $model)
3939
{
4040
$query->orWhereDescendantOf($model);
4141
}
4242

4343
/**
44-
* @param Model&Node $model
45-
* @param Node $related
44+
* @param NodeModel $model
45+
* @param NodeModel $related
4646
*
4747
* @return bool
4848
*/

src/QueryBuilder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class QueryBuilder extends Builder
3131
*
3232
* @since 2.0
3333
*
34-
* @param Tmodelkey $id
34+
* @param Tmodelkey|NodeModel $id
3535
* @param bool $required
3636
*
3737
* @return array<int,int>
@@ -57,7 +57,7 @@ public function getNodeData(mixed $id, $required = false)
5757
*
5858
* @since 2.0
5959
*
60-
* @param Tmodelkey $id
60+
* @param Tmodelkey|NodeModel $id
6161
* @param bool $required
6262
*
6363
* @return array<int,int>
@@ -212,7 +212,7 @@ public function orWhereNodeBetween(array $values)
212212
*
213213
* @since 2.0
214214
*
215-
* @param Tmodelkey $id
215+
* @param Tmodelkey|NodeModel $id
216216
* @param string $boolean
217217
* @param bool $not
218218
* @param bool $andSelf
@@ -238,7 +238,7 @@ public function whereDescendantOf(mixed $id, $boolean = 'and', $not = false,
238238
}
239239

240240
/**
241-
* @param Tmodelkey $id
241+
* @param Tmodelkey|NodeModel $id
242242
*
243243
* @return QueryBuilder<Tmodelkey,Tmodel>
244244
*/
@@ -248,7 +248,7 @@ public function whereNotDescendantOf(mixed $id)
248248
}
249249

250250
/**
251-
* @param Tmodelkey $id
251+
* @param Tmodelkey|NodeModel $id
252252
*
253253
* @return QueryBuilder<Tmodelkey,Tmodel>
254254
*/

0 commit comments

Comments
 (0)