Passed
Pull Request — master (#221)
by Christopher
06:28 queued 01:03
created

MetadataRelationsTrait::addRelationsHook()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 22
rs 9.9332
cc 3
nc 4
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alex
5
 * Date: 13/02/20
6
 * Time: 1:08 PM.
7
 */
8
namespace AlgoWeb\PODataLaravel\Models;
9
10
use Illuminate\Database\Eloquent\Model;
11
use Illuminate\Database\Eloquent\Relations\BelongsTo;
12
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
13
use Illuminate\Database\Eloquent\Relations\MorphMany;
14
use Illuminate\Database\Eloquent\Relations\MorphOne;
15
use Illuminate\Database\Eloquent\Relations\MorphToMany;
16
use Illuminate\Database\Eloquent\Relations\Relation;
17
use Mockery\Mock;
18
use POData\Common\InvalidOperationException;
19
20
trait MetadataRelationsTrait
21
{
22
    /**
23
     * @var array|string[]|null a cache for the relationship names
24
     */
25
    private static $relationNames = null;
26
    /**
27
     * Get model's relationships.
28
     *
29
     * @throws InvalidOperationException
30
     * @throws \ReflectionException
31
     * @return array
32
     */
33
    public function getRelationships()
34
    {
35
        return static::$relationNames =  static::$relationNames ?? ModelReflectionHelper::getRelationshipsFromMethods($this);
0 ignored issues
show
Bug introduced by
Since $relationNames is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $relationNames to at least protected.
Loading history...
Bug introduced by
$this of type AlgoWeb\PODataLaravel\Mo...\MetadataRelationsTrait is incompatible with the type Illuminate\Database\Eloquent\Model expected by parameter $model of AlgoWeb\PODataLaravel\Mo...ationshipsFromMethods(). ( Ignorable by Annotation )

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

35
        return static::$relationNames =  static::$relationNames ?? ModelReflectionHelper::getRelationshipsFromMethods(/** @scrutinizer ignore-type */ $this);
Loading history...
36
    }
37
}
38