Completed
Push — master ( c2ab20...6fd91f )
by Alex
14s queued 12s
created

MetadataRelationsTrait::getRelationshipsFromMethods()   B

Complexity

Conditions 11
Paths 24

Size

Total Lines 51
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 38
c 5
b 0
f 0
dl 0
loc 51
rs 7.3166
cc 11
nc 24
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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