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

brick / orm / 23255296146

18 Mar 2026 04:24PM UTC coverage: 47.104%. Remained the same
23255296146

push

github

BenMorel
Avoid \Exception that somehow confuses ECS

1 of 5 new or added lines in 1 file covered. (20.0%)

402 existing lines in 24 files now uncovered.

553 of 1174 relevant lines covered (47.1%)

10.6 hits per line

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

50.0
/src/PropertyMapping/JsonMapping.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\ORM\PropertyMapping;
6

7
use Brick\ORM\Gateway;
8
use Brick\ORM\PropertyMapping;
9

10
use function json_decode;
11
use function json_encode;
12

13
/**
14
 * Maps a column of any type to a JSON datatype in the database.
15
 */
16
class JsonMapping implements PropertyMapping
17
{
18
    public string $fieldName;
19

20
    public bool $isNullable;
21

22
    /**
23
     * Whether to decode JSON objects as associative arrays (true) or stdClass objects (false).
24
     */
25
    public bool $objectAsArray;
26

27
    public function __construct(string $fieldName, bool $isNullable, bool $objectAsArray)
28
    {
UNCOV
29
        $this->fieldName = $fieldName;
×
UNCOV
30
        $this->isNullable = $isNullable;
×
UNCOV
31
        $this->objectAsArray = $objectAsArray;
×
32
    }
33

34
    public function isNullable(): bool
35
    {
UNCOV
36
        return $this->isNullable;
×
37
    }
38

39
    public function getFieldNames(): array
40
    {
41
        return [$this->fieldName];
7✔
42
    }
43

44
    public function getInputValuesCount(): int
45
    {
46
        return 1;
3✔
47
    }
48

49
    public function getFieldToInputValuesSQL(array $fieldNames): array
50
    {
51
        return $fieldNames;
4✔
52
    }
53

54
    public function getType(): ?string
55
    {
UNCOV
56
        return null;
×
57
    }
58

59
    public function convertInputValuesToProp(Gateway $gateway, array $values): mixed
60
    {
61
        /** @var array{string|null} $values */
62

63
        if ($values[0] === null) {
3✔
UNCOV
64
            return null;
×
65
        }
66

67
        return json_decode($values[0], $this->objectAsArray);
3✔
68
    }
69

70
    public function convertPropToFields(mixed $propValue): array
71
    {
72
        if ($propValue === null) {
4✔
UNCOV
73
            return [
×
UNCOV
74
                ['NULL'],
×
UNCOV
75
            ];
×
76
        }
77

78
        return [
4✔
79
            ['?', json_encode($propValue)],
4✔
80
        ];
4✔
81
    }
82
}
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

© 2026 Coveralls, Inc