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

martin-georgiev / postgresql-for-doctrine / 64027d602ba603c6bf7b201582e54c53d09cfb1b

25 May 2026 09:48AM UTC coverage: 98.652% (-0.06%) from 98.712%
64027d602ba603c6bf7b201582e54c53d09cfb1b

push

github

web-flow
feat: add support for range array DBAL types (#638)

198 of 204 new or added lines in 18 files covered. (97.06%)

5564 of 5640 relevant lines covered (98.65%)

36.01 hits per line

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

95.45
/src/MartinGeorgiev/Doctrine/DBAL/Types/NumRangeArray.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MartinGeorgiev\Doctrine\DBAL\Types;
6

7
use MartinGeorgiev\Doctrine\DBAL\Type;
8
use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidNumRangeArrayItemForDatabaseException;
9
use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidNumRangeArrayItemForPHPException;
10
use MartinGeorgiev\Doctrine\DBAL\Types\ValueObject\NumericRange as NumericRangeValueObject;
11
use MartinGeorgiev\Utils\PostgresArrayToPHPArrayTransformer;
12

13
/**
14
 * Implementation of PostgreSQL NUMRANGE[] data type.
15
 *
16
 * @see https://www.postgresql.org/docs/18/rangetypes.html
17
 * @since 4.6
18
 *
19
 * @author Martin Georgiev <martin.georgiev@gmail.com>
20
 */
21
class NumRangeArray extends BaseArray
22
{
23
    /**
24
     * @var string
25
     */
26
    protected const TYPE_NAME = Type::NUMRANGE_ARRAY;
27

28
    protected function transformArrayItemForPostgres(mixed $item): string
8✔
29
    {
30
        if ($item === null) {
8✔
31
            return 'NULL';
2✔
32
        }
33

34
        if (!$item instanceof NumericRangeValueObject) {
8✔
NEW
35
            throw InvalidNumRangeArrayItemForDatabaseException::forInvalidType($item);
×
36
        }
37

38
        return $this->quoteAndEscapeArrayItem((string) $item);
8✔
39
    }
40

41
    public function isValidArrayItemForDatabase(mixed $item): bool
17✔
42
    {
43
        return $item === null || $item instanceof NumericRangeValueObject;
17✔
44
    }
45

46
    public function transformArrayItemForPHP(mixed $item): ?NumericRangeValueObject
13✔
47
    {
48
        if ($item === null) {
13✔
49
            return null;
3✔
50
        }
51

52
        if (!\is_string($item)) {
12✔
53
            throw InvalidNumRangeArrayItemForPHPException::forInvalidType($item);
1✔
54
        }
55

56
        try {
57
            return NumericRangeValueObject::fromString($item);
11✔
58
        } catch (\InvalidArgumentException) {
3✔
59
            throw InvalidNumRangeArrayItemForPHPException::forInvalidFormat($item);
3✔
60
        }
61
    }
62

63
    protected function transformPostgresArrayToPHPArray(string $postgresArray): array
10✔
64
    {
65
        return PostgresArrayToPHPArrayTransformer::transformPostgresArrayToPHPArray($postgresArray);
10✔
66
    }
67

68
    protected function throwInvalidTypeException(mixed $value): never
3✔
69
    {
70
        throw InvalidNumRangeArrayItemForPHPException::forInvalidArrayType($value);
3✔
71
    }
72

73
    protected function throwInvalidItemException(mixed $item): never
3✔
74
    {
75
        throw InvalidNumRangeArrayItemForDatabaseException::forInvalidType($item);
3✔
76
    }
77
}
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