• 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

89.58
/src/PropertyMapping/EmbeddableMapping.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\ORM\PropertyMapping;
6

7
use Brick\ORM\EmbeddableMetadata;
8
use Brick\ORM\Gateway;
9
use Brick\ORM\ObjectFactory;
10
use Brick\ORM\PropertyMapping;
11
use ReflectionObject;
12

13
use function array_slice;
14

15
/**
16
 * @internal
17
 */
18
class EmbeddableMapping implements PropertyMapping
19
{
20
    /**
21
     * The class metadata of the target entity.
22
     */
23
    public EmbeddableMetadata $classMetadata;
24

25
    public string $fieldNamePrefix;
26

27
    public bool $isNullable;
28

29
    /**
30
     * @param EmbeddableMetadata $classMetadata   The target entity class metadata.
31
     * @param string             $fieldNamePrefix The prefix for field names.
32
     * @param bool               $isNullable      Whether the property is nullable.
33
     */
34
    public function __construct(EmbeddableMetadata $classMetadata, string $fieldNamePrefix, bool $isNullable)
35
    {
36
        $this->classMetadata = $classMetadata;
×
UNCOV
37
        $this->fieldNamePrefix = $fieldNamePrefix;
×
UNCOV
38
        $this->isNullable = $isNullable;
×
39
    }
40

41
    public function getType(): ?string
42
    {
UNCOV
43
        return $this->classMetadata->className;
×
44
    }
45

46
    public function isNullable(): bool
47
    {
UNCOV
48
        return $this->isNullable;
×
49
    }
50

51
    /**
52
     * @todo precompute for better performance
53
     */
54
    public function getFieldNames(): array
55
    {
56
        $names = [];
28✔
57

58
        foreach ($this->classMetadata->properties as $prop) {
28✔
59
            foreach ($this->classMetadata->propertyMappings[$prop]->getFieldNames() as $name) {
28✔
60
                $names[] = $this->fieldNamePrefix . $name;
28✔
61
            }
62
        }
63

64
        return $names;
28✔
65
    }
66

67
    /**
68
     * @todo precompute for better performance
69
     */
70
    public function getInputValuesCount(): int
71
    {
72
        $count = 0;
21✔
73

74
        foreach ($this->classMetadata->properties as $prop) {
21✔
75
            $propertyMapping = $this->classMetadata->propertyMappings[$prop];
21✔
76
            $count += $propertyMapping->getInputValuesCount();
21✔
77
        }
78

79
        return $count;
21✔
80
    }
81

82
    /**
83
     * @todo precompute for better performance
84
     */
85
    public function getFieldToInputValuesSQL(array $fieldNames): array
86
    {
87
        $wrappedFields = [];
25✔
88
        $currentIndex = 0;
25✔
89

90
        foreach ($this->classMetadata->properties as $prop) {
25✔
91
            $propertyMapping = $this->classMetadata->propertyMappings[$prop];
25✔
92
            $readFieldCount = $propertyMapping->getInputValuesCount();
25✔
93

94
            $currentFieldNames = array_slice($fieldNames, $currentIndex, $readFieldCount);
25✔
95
            $currentIndex += $readFieldCount;
25✔
96

97
            foreach ($propertyMapping->getFieldToInputValuesSQL($currentFieldNames) as $wrappedField) {
25✔
98
                $wrappedFields[] = $wrappedField;
25✔
99
            }
100
        }
101

102
        return $wrappedFields;
25✔
103
    }
104

105
    public function convertInputValuesToProp(Gateway $gateway, array $values): mixed
106
    {
107
        $currentIndex = 0;
3✔
108

109
        $propValues = [];
3✔
110

111
        foreach ($this->classMetadata->properties as $prop) {
3✔
112
            $propertyMapping = $this->classMetadata->propertyMappings[$prop];
3✔
113
            $readFieldCount = $propertyMapping->getInputValuesCount();
3✔
114

115
            $currentInputValues = array_slice($values, $currentIndex, $readFieldCount);
3✔
116
            $currentIndex += $readFieldCount;
3✔
117

118
            $propValues[$prop] = $propertyMapping->convertInputValuesToProp($gateway, $currentInputValues);
3✔
119
        }
120

121
        /** @todo keep an ObjectFactory cache. */
122
        $objectFactory = new ObjectFactory();
3✔
123

124
        return $objectFactory->instantiate($this->classMetadata, $propValues);
3✔
125
    }
126

127
    public function convertPropToFields(mixed $propValue): array
128
    {
129
        $result = [];
4✔
130

131
        /** @var object|null $entity */
132
        $entity = $propValue;
4✔
133

134
        $r = null;
4✔
135

136
        foreach ($this->classMetadata->properties as $prop) {
4✔
137
            if ($entity === null) {
4✔
138
                $idPropValue = null;
3✔
139
            } else {
140
                if ($r === null) {
3✔
141
                    $r = new ReflectionObject($entity);
3✔
142
                }
143

144
                $p = $r->getProperty($prop);
3✔
145
                $idPropValue = $p->getValue($entity);
3✔
146
            }
147

148
            foreach ($this->classMetadata->propertyMappings[$prop]->convertPropToFields($idPropValue) as $expressionAndValues) {
4✔
149
                $result[] = $expressionAndValues;
4✔
150
            }
151
        }
152

153
        return $result;
4✔
154
    }
155
}
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