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

MetadataRelationsTrait::getCodeForMethod()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 25
rs 9.6666
cc 4
nc 6
nop 1
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