Test Failed
Pull Request — master (#107)
by Alex
03:44
created

MetadataProvider::calculateRoundTripRelationsFirstPass()   C

Complexity

Conditions 12
Paths 40

Size

Total Lines 56
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 56
ccs 0
cts 0
cp 0
rs 6.7092
cc 12
eloc 38
nc 40
nop 3
crap 156

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
namespace AlgoWeb\PODataLaravel\Providers;
4
5
use AlgoWeb\PODataLaravel\Models\MetadataRelationHolder;
6
7
class MetadataProvider extends MetadataProviderOld
8
{
9
    protected $relationHolder;
10
11
    public function __construct($app)
12
    {
13
        parent::__construct($app);
14
        $this->relationHolder = new MetadataRelationHolder();
15
        self::$isBooted = false;
16
    }
17
18
    /**
19
     * @return MetadataRelationHolder
20 1
     */
21
    public function getRelationHolder()
22 1
    {
23
        return $this->relationHolder;
24
    }
25 1
26
    public function calculateRoundTripRelations()
27
    {
28 1
        $modelNames = $this->getCandidateModels();
29 1
30
        foreach ($modelNames as $name) {
31
            if (!$this->getRelationHolder()->hasClass($name)) {
32
                $model = new $name();
33
                $this->getRelationHolder()->addModel($model);
34
            }
35
        }
36
37
        return $this->getRelationHolder()->getRelations();
38
    }
39
}
40