Passed
Push — trunk ( e297c1...a4a5c2 )
by Christian
12:21 queued 13s
created

TaxRuleCollection   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A sortByTypePosition() 0 3 1
A highestTypePosition() 0 3 3
A latestActivationDate() 0 3 3
A getApiAlias() 0 3 1
A filterByTypePosition() 0 3 1
A getExpectedClass() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\System\Tax\Aggregate\TaxRule;
4
5
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
6
use Shopware\Core\Framework\Log\Package;
7
8
/**
9
 * @extends EntityCollection<TaxRuleEntity>
10
 */
11
#[Package('customer-order')]
12
class TaxRuleCollection extends EntityCollection
13
{
14
    public function sortByTypePosition(): void
15
    {
16
        $this->sort(fn (TaxRuleEntity $entityA, TaxRuleEntity $entityB) => $entityA->getType()->getPosition() <=> $entityB->getType()->getPosition());
0 ignored issues
show
Bug introduced by
The type Shopware\Core\System\Tax...e\TaxRule\TaxRuleEntity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
    }
18
19
    public function filterByTypePosition(int $position): TaxRuleCollection
20
    {
21
        return $this->filter(fn (TaxRuleEntity $taxRule) => $taxRule->getType()->getPosition() === $position);
22
    }
23
24
    public function highestTypePosition(): ?TaxRuleEntity
25
    {
26
        return $this->reduce(fn (?TaxRuleEntity $result, TaxRuleEntity $item) => $result === null || $item->getType()->getPosition() < $result->getType()->getPosition() ? $item : $result);
27
    }
28
29
    public function latestActivationDate(): ?TaxRuleEntity
30
    {
31
        return $this->reduce(fn (?TaxRuleEntity $result, TaxRuleEntity $item) => $result === null || $item->getActiveFrom() > $result->getActiveFrom() ? $item : $result);
32
    }
33
34
    public function getApiAlias(): string
35
    {
36
        return 'tax_rule_collection';
37
    }
38
39
    protected function getExpectedClass(): string
40
    {
41
        return TaxRuleEntity::class;
42
    }
43
}
44