Test Failed
Pull Request — master (#48)
by
unknown
03:03
created

src/Traits/HasTreeRelationships.php (2 issues)

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
It seems like newRelatedInstance() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        /** @scrutinizer ignore-call */ 
33
        $instance = $this->newRelatedInstance($related);
Loading history...
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 ignore-call  annotation

49
        return new BelongsToTree($instance->/** @scrutinizer ignore-call */ newQuery(), $this, $throwRelation, $foreignKey, $ownerKey);

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.

Loading history...
50
    }
51
}
52