Passed
Push — master ( ea0818...92b4a6 )
by Adrian
01:28
created

HasAggregates   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 15
c 1
b 0
f 1
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compileAggregates() 0 19 5
A getAggregates() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Relation;
5
6
use Sirius\Orm\Collection\Collection;
7
use Sirius\Orm\Entity\EntityInterface;
8
use Sirius\Orm\Entity\StateEnum;
9
use Sirius\Orm\Entity\Tracker;
10
use Sirius\Orm\Query;
11
12
trait HasAggregates
13
{
14
    protected $aggregates;
15
16
    protected function compileAggregates()
17
    {
18
        if (is_array($this->aggregates)) {
19
            return;
20
        }
21
22
        $aggregates = [];
23
        $aggregatesList = $this->getOption(RelationConfig::AGGREGATES);
0 ignored issues
show
Bug introduced by
It seems like getOption() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

23
        /** @scrutinizer ignore-call */ 
24
        $aggregatesList = $this->getOption(RelationConfig::AGGREGATES);
Loading history...
24
        if (!is_array($aggregatesList) || empty($aggregatesList)) {
25
            $this->aggregates = $aggregates;
26
            return;
27
        }
28
29
        foreach ($aggregatesList as $name => $options) {
30
            $agg = new Aggregate($name, $this, $options);
0 ignored issues
show
Bug introduced by
$this of type Sirius\Orm\Relation\HasAggregates is incompatible with the type Sirius\Orm\Relation\Relation expected by parameter $relation of Sirius\Orm\Relation\Aggregate::__construct(). ( Ignorable by Annotation )

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

30
            $agg = new Aggregate($name, /** @scrutinizer ignore-type */ $this, $options);
Loading history...
31
            $aggregates[$name] = $agg;
32
        }
33
34
        $this->aggregates = $aggregates;
35
    }
36
37
    public function getAggregates()
38
    {
39
        $this->compileAggregates();
40
41
        return $this->aggregates;
42
    }
43
}
44