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

nextras / orm / 28896632103

07 Jul 2026 08:31PM UTC coverage: 92.166% (+0.07%) from 92.095%
28896632103

push

github

web-flow
Merge pull request #819 from nextras/set-raw-value-validation

entity: strengthen the setRawValue() contract to avoid value validation

12 of 13 new or added lines in 2 files covered. (92.31%)

4306 of 4672 relevant lines covered (92.17%)

5.42 hits per line

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

84.21
/src/Entity/PropertyWrapper/BackedEnumWrapper.php
1
<?php declare(strict_types = 1);
2

3
namespace Nextras\Orm\Entity\PropertyWrapper;
4

5

6
use BackedEnum;
7
use Nextras\Orm\Entity\ImmutableValuePropertyWrapper;
8
use Nextras\Orm\Exception\InvalidArgumentException;
9
use Nextras\Orm\Exception\NullValueException;
10
use function array_key_first;
11
use function assert;
12
use function is_int;
13
use function is_string;
14
use function is_subclass_of;
15

16

17
final class BackedEnumWrapper extends ImmutableValuePropertyWrapper
18
{
19
        public function setInjectedValue($value): bool
20
        {
21
                if ($value === null && !$this->propertyMetadata->isNullable) {
6✔
22
                        throw new NullValueException($this->propertyMetadata);
6✔
23
                }
24

25
                return parent::setInjectedValue($value);
6✔
26
        }
27

28

29
        public function convertToRawValue(mixed $value): mixed
30
        {
31
                if ($value === null) return null;
6✔
32
                $type = array_key_first($this->propertyMetadata->types);
6✔
33
                if ($value instanceof BackedEnum === false) {
6✔
34
                        throw new InvalidArgumentException('Value must be of type BackedEnum.');
6✔
35
                }
36
                if ($value instanceof $type === false) {
6✔
37
                        throw new InvalidArgumentException('Value must be of type ' . $type . '.');
×
38
                }
39

40
                return $value->value;
6✔
41
        }
42

43

44
        public function convertFromRawValue(mixed $value): ?BackedEnum
45
        {
46
                if ($value === null) {
6✔
NEW
47
                        return null;
×
48
                }
49

50
                $type = array_key_first($this->propertyMetadata->types);
6✔
51
                if (is_int($value) || is_string($value)) {
6✔
52
                        if (is_subclass_of($type, BackedEnum::class)) {
6✔
53
                                return $type::from($value);
6✔
54
                        }
55
                }
56
                if ($value instanceof BackedEnum && $value instanceof $type) {
6✔
57
                        return $value;
6✔
58
                }
59

60
                throw new InvalidArgumentException('Invalid value for enum.');
×
61
        }
62
}
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