Issues (389)

Admin/Form/Fields/Concerns/HasRelationships.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Arbory\Base\Admin\Form\Fields\Concerns;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Collection;
7
use Illuminate\Database\Eloquent\Relations\HasOne;
8
use Illuminate\Database\Eloquent\Relations\HasMany;
9
use Illuminate\Database\Eloquent\Relations\MorphTo;
10
use Illuminate\Database\Eloquent\Relations\MorphOne;
11
use Illuminate\Database\Eloquent\Relations\Relation;
12
use Illuminate\Database\Eloquent\Relations\BelongsTo;
13
use Illuminate\Database\Eloquent\Relations\MorphMany;
14
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
15
16
/**
17
 * Class HasRelationships.
18
 */
19
trait HasRelationships
20
{
21
    /**
22
     * @return Relation|BelongsTo|BelongsToMany|HasOne|HasMany|MorphOne|MorphMany|MorphTo
23
     */
24
    public function getRelation()
25
    {
26
        return $this->getModel()->{$this->getName()}();
0 ignored issues
show
It seems like getName() 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

26
        return $this->getModel()->{$this->/** @scrutinizer ignore-call */ getName()}();
Loading history...
It seems like getModel() 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

26
        return $this->/** @scrutinizer ignore-call */ getModel()->{$this->getName()}();
Loading history...
27
    }
28
29
    /**
30
     * @return Model
31
     */
32
    public function getRelatedModel()
33
    {
34
        return $this->getRelation()->getRelated();
35
    }
36
37
    /**
38
     * @return Collection|Model[]
39
     */
40
    public function getRelatedItems()
41
    {
42
        return $this->getRelatedModel()->all()->keyBy($this->getRelatedModel()->getKeyName());
43
    }
44
}
45