1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace Umbrellio\LTree\Traits; |
||||
6 | |||||
7 | use Illuminate\Database\Eloquent\Concerns\HasRelationships; |
||||
8 | use Illuminate\Database\Eloquent\Model; |
||||
9 | use Umbrellio\LTree\Exceptions\InvalidTraitInjectionClass; |
||||
10 | use Umbrellio\LTree\Interfaces\LTreeModelInterface; |
||||
11 | use Umbrellio\LTree\Relations\BelongsToTree; |
||||
12 | |||||
13 | /** |
||||
14 | * @mixin HasRelationships |
||||
15 | * @mixin LTreeModelTrait |
||||
16 | * @mixin Model |
||||
17 | */ |
||||
18 | trait HasTreeRelationships |
||||
19 | { |
||||
20 | /** |
||||
21 | * @param null $ownerKey |
||||
22 | * @return BelongsToTree |
||||
23 | * |
||||
24 | * @throws InvalidTraitInjectionClass |
||||
25 | */ |
||||
26 | protected function belongsToTree( |
||||
27 | string $related, |
||||
28 | string $throwRelation, |
||||
29 | ?string $foreignKey = null, |
||||
30 | $ownerKey = null |
||||
31 | ) { |
||||
32 | $instance = $this->newRelatedInstance($related); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
33 | |||||
34 | if (!$instance instanceof LTreeModelInterface) { |
||||
35 | throw new InvalidTraitInjectionClass(sprintf( |
||||
36 | 'A class using this trait must implement an interface %s', |
||||
37 | LTreeModelInterface::class |
||||
38 | )); |
||||
39 | } |
||||
40 | |||||
41 | if ($foreignKey === null) { |
||||
42 | $foreignKey = $this |
||||
43 | ->{$throwRelation}() |
||||
44 | ->getForeignKeyName(); |
||||
45 | } |
||||
46 | |||||
47 | $ownerKey = $ownerKey ?: $instance->getKeyName(); |
||||
48 | |||||
49 | return new BelongsToTree($instance->newQuery(), $this, $throwRelation, $foreignKey, $ownerKey); |
||||
0 ignored issues
–
show
The method
newQuery() does not exist on Umbrellio\LTree\Interfaces\LTreeModelInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
50 | } |
||||
51 | } |
||||
52 |