HasAggregates   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
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 33
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);
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, /** @scrutinizer ignore-type */ $this, $options);
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
    abstract public function getOption($name);
45
}
46