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

nextras / orm / 13354993605

16 Feb 2025 12:29PM UTC coverage: 91.73% (-0.3%) from 92.021%
13354993605

push

github

web-flow
Merge pull request #732 from nextras/datetime-property-wrapper

Datetime property wrapper

94 of 112 new or added lines in 15 files covered. (83.93%)

1 existing line in 1 file now uncovered.

4115 of 4486 relevant lines covered (91.73%)

4.57 hits per line

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

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

3
namespace Nextras\Orm\Collection\Functions;
4

5

6
use Nextras\Orm\Collection\Functions\Result\DbalExpressionResult;
7
use Nextras\Orm\Entity\PropertyComparator;
8
use Nextras\Orm\Exception\InvalidArgumentException;
9
use function count;
10
use function in_array;
11
use function is_array;
12

13

14
class CompareNotEqualsFunction extends BaseCompareFunction
15
{
16
        protected function evaluateInPhp(mixed $sourceValue, mixed $targetValue, PropertyComparator|null $comparator): bool
17
        {
18
                if ($comparator === null) {
5✔
19
                        if (is_array($targetValue)) {
5✔
20
                                return !in_array($sourceValue, $targetValue, true);
5✔
21
                        } else {
22
                                return $sourceValue !== $targetValue;
5✔
23
                        }
24
                } else {
25
                        if (is_array($targetValue)) {
5✔
26
                                foreach ($targetValue as $targetSubValue) {
5✔
27
                                        if ($comparator->equals($sourceValue, $targetSubValue)) return false;
5✔
28
                                }
29
                                return true;
5✔
30
                        } else {
NEW
31
                                return !$comparator->equals($sourceValue, $targetValue);
×
32
                        }
33
                }
34
        }
35

36

37
        protected function evaluateInDb(
38
                DbalExpressionResult $expression,
39
                mixed $value,
40
                string|array|null $modifier,
41
        ): DbalExpressionResult
42
        {
43
                if (is_array($value)) {
5✔
44
                        if (count($value) > 0) {
5✔
45
                                // Multi-column primary key handling
46
                                // Construct multiOr simplification as array{list<Fqn>, modifiers: list<string>, values: list<list<mixed>>}
47
                                $args = $expression->getArgsForExpansion();
5✔
48
                                if (count($args) === 2 && $args[0] === '%column' && is_array($args[1]) && is_array($modifier)) {
5✔
49
                                        $columns = $args[1];
5✔
50
                                        $data = [];
5✔
51
                                        foreach ($value as $dataSet) {
5✔
52
                                                $set = [];
5✔
53
                                                foreach ($dataSet as $i => $dataSetValue) {
5✔
54
                                                        $set[] = [$columns[$i], $dataSetValue, $modifier[$i] ?? null];
5✔
55
                                                }
56
                                                $data[] = $set;
5✔
57
                                        }
58
                                        return $expression->withArgs('NOT (%multiOr)', [$data]);
5✔
59
                                } else {
60
                                        if (is_array($modifier)) throw new InvalidArgumentException();
5✔
61
                                        $modifier = $modifier ?? '%any';
5✔
62
                                        if ($modifier !== '%any') $modifier .= '[]';
5✔
63
                                        return $expression->append("NOT IN $modifier", $value);
5✔
64
                                }
65
                        } else {
66
                                return $expression->withArgs('1=1', []);
5✔
67
                        }
68
                } elseif ($value === null) {
5✔
69
                        return $expression->append('IS NOT NULL');
5✔
70
                } else {
71
                        if (is_array($modifier)) throw new InvalidArgumentException();
5✔
72
                        $modifier = $modifier ?? '%any';
5✔
73
                        return $expression->append("!= $modifier", $value);
5✔
74
                }
75
        }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc