Completed
Push — master ( c2ab20...6fd91f )
by Alex
14s queued 12s
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
use ReflectionException;
20
21
trait MetadataRelationsTrait
22
{
23
    /**
24
     * @var array|string[]|null a cache for the relationship names
25
     */
26
    private static $relationNames = null;
27
28
    /**
29
     * Get model's relationships.
30
     *
31
     * @throws InvalidOperationException
32
     * @throws ReflectionException
33
     * @return array
34
     */
35
    public function getRelationships()
36
    {
37
        return self::$relationNames = self::$relationNames ??
38
                                      ModelReflectionHelper::getRelationshipsFromMethods(/** @scrutinizer ignore-type */$this);
39
    }
40
}
41