• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nextras / orm / 40780907175

28 Oct 2026 10:33PM UTC coverage: 92.01% (+0.01%) from 91.998%
40780907175

Pull #842

github

web-flow
Merge 6ce4bf857 into 10fe91984
Pull Request #842: Setup DressCode

253 of 306 new or added lines in 64 files covered. (82.68%)

13 existing lines in 9 files now uncovered.

4399 of 4781 relevant lines covered (92.01%)

5.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/src/Collection/Functions/BaseNumericAggregateFunction.php
1
<?php declare(strict_types = 1);
2

3
namespace Nextras\Orm\Collection\Functions;
4

5

6
use Nextras\Dbal\QueryBuilder\QueryBuilder;
7
use Nextras\Orm\Collection\Aggregations\Aggregator;
8
use Nextras\Orm\Collection\Aggregations\NumericAggregator;
9
use Nextras\Orm\Collection\Expression\ExpressionContext;
10
use Nextras\Orm\Collection\Functions\Result\ArrayExpressionResult;
11
use Nextras\Orm\Collection\Functions\Result\DbalExpressionResult;
12
use Nextras\Orm\Collection\Helpers\ArrayCollectionHelper;
13
use Nextras\Orm\Collection\Helpers\DbalQueryBuilderHelper;
14
use Nextras\Orm\Entity\IEntity;
15
use Nextras\Orm\Exception\InvalidArgumentException;
16
use Nextras\Orm\Exception\InvalidStateException;
17
use function assert;
18
use function count;
19
use function is_array;
20
use function is_string;
21

22

23
abstract class BaseNumericAggregateFunction implements CollectionFunction
24
{
25
        protected function __construct(
5 ✔
26
                private readonly NumericAggregator $aggregator,
1 ✔
27
        )
28
        {
29
        }
6 ✔
30

31

32
        public function processArrayExpression(
33
                ArrayCollectionHelper $helper,
34
                IEntity $entity,
35
                array $args,
36
                Aggregator|null $aggregator = null,
37
        ): ArrayExpressionResult
38
        {
39
                assert(count($args) === 1 && is_string($args[0]));
40

41
                $valueReference = $helper->getValue($entity, $args[0], $aggregator);
6 ✔
42
                if ($valueReference->aggregator === null) {
6 ✔
43
                        throw new InvalidArgumentException('Aggregation has to be called over has many relationship.');
×
44
                }
45
                assert(is_array($valueReference->value));
46

47
                return new ArrayExpressionResult(
6 ✔
48
                        value: $this->aggregator->aggregateValues($valueReference->value),
6 ✔
49
                );
50
        }
51

52

53
        public function processDbalExpression(
54
                DbalQueryBuilderHelper $helper,
55
                QueryBuilder $builder,
56
                array $args,
57
                Aggregator|null $aggregator = null,
58
        ): DbalExpressionResult
59
        {
60
                assert(count($args) === 1 && is_string($args[0]));
61

62
                if ($aggregator !== null) {
6 ✔
NEW
63
                        throw new InvalidStateException('Cannot apply two aggregations simultaneously.');
×
64
                }
65

66
                return $helper
67
                        ->processExpression($builder, $args[0], $this->aggregator)
6 ✔
68
                        ->applyAggregator(ExpressionContext::ValueExpression);
6 ✔
69
        }
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc