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

nextras / orm / 41909495460

04 Nov 2026 08:44PM UTC coverage: 92.015% (-0.002%) from 92.017%
41909495460

push

github

web-flow
Merge pull request #842 from nextras/js/dresscode

Setup DressCode

288 of 347 new or added lines in 66 files covered. (83.0%)

14 existing lines in 9 files now uncovered.

4402 of 4784 relevant lines covered (92.02%)

6.29 hits per line

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

74.36
/src/Entity/Reflection/MetadataValidator.php
1
<?php declare(strict_types = 1);
2

3
namespace Nextras\Orm\Entity\Reflection;
4

5

6
use Nextras\Orm\Exception\InvalidStateException;
7
use Nextras\Orm\Model\IRepositoryLoader;
8

9

10
class MetadataValidator
11
{
12
        /**
13
         * @param EntityMetadata[] $metadata
14
         * @throws InvalidStateException
15
         */
16
        public function validate(array $metadata, IRepositoryLoader $repositoryLoader): void
17
        {
18
                $pairs = [
7 ✔
19
                        PropertyRelationshipMetadata::MANY_HAS_MANY => PropertyRelationshipMetadata::MANY_HAS_MANY,
7 ✔
20
                        PropertyRelationshipMetadata::MANY_HAS_ONE => PropertyRelationshipMetadata::ONE_HAS_MANY,
7 ✔
21
                        PropertyRelationshipMetadata::ONE_HAS_MANY => PropertyRelationshipMetadata::MANY_HAS_ONE,
7 ✔
22
                        PropertyRelationshipMetadata::ONE_HAS_ONE => PropertyRelationshipMetadata::ONE_HAS_ONE,
7 ✔
23
                ];
24

25
                foreach ($metadata as $entityMeta) {
7 ✔
26
                        foreach ($entityMeta->getProperties() as $propertyMeta) {
7 ✔
27
                                if ($propertyMeta->relationship === null) {
7 ✔
28
                                        continue;
7 ✔
29
                                }
30

31
                                $repositoryName = $propertyMeta->relationship->repository;
7 ✔
32
                                if (!$repositoryLoader->hasRepository($repositoryName)) {
7 ✔
33
                                        throw new InvalidStateException("{$entityMeta->className}::\${$propertyMeta->name} points to unknown '{$propertyMeta->relationship->repository}' repository.");
×
34
                                }
35

36
                                if ($propertyMeta->relationship->property === null) {
7 ✔
37
                                        $relType = $propertyMeta->relationship->type;
7 ✔
38
                                        $isAllowedOneSided = ($relType === PropertyRelationshipMetadata::ONE_HAS_ONE
7 ✔
39
                                                && $propertyMeta->relationship->isMain)
7 ✔
40
                                                || ($relType === PropertyRelationshipMetadata::MANY_HAS_ONE)
7 ✔
NEW
41
                                                || ($relType === PropertyRelationshipMetadata::MANY_HAS_MANY
×
NEW
42
                                                        && $propertyMeta->relationship->isMain);
×
43
                                        if (!$isAllowedOneSided) {
7 ✔
44
                                                throw new InvalidStateException("{$entityMeta->className}::\${$propertyMeta->name} must have defined a symmetric relationship.");
×
45
                                        } else {
46
                                                continue;
7 ✔
47
                                        }
48
                                }
49

50
                                $symmetricEntityMeta = $metadata[$propertyMeta->relationship->entity];
7 ✔
51

52
                                if (!$symmetricEntityMeta->hasProperty($propertyMeta->relationship->property)) {
7 ✔
53
                                        throw new InvalidStateException("{$entityMeta->className}::\${$propertyMeta->name} has not defined a symmetric relationship in {$symmetricEntityMeta->className}::\${$propertyMeta->relationship->property}.");
×
54
                                }
55

56
                                $symmetricPropertyMeta = $symmetricEntityMeta->getProperty($propertyMeta->relationship->property);
7 ✔
57
                                if ($symmetricPropertyMeta->relationship === null) {
7 ✔
58
                                        throw new InvalidStateException("{$entityMeta->className}::\${$propertyMeta->name} has not defined a symmetric relationship in {$symmetricEntityMeta->className}::\${$propertyMeta->relationship->property}.");
×
59
                                }
60

61
                                if ($propertyMeta->name !== $symmetricPropertyMeta->relationship->property) {
7 ✔
62
                                        throw new InvalidStateException("{$entityMeta->className}::\${$propertyMeta->name} relationship with {$symmetricEntityMeta->className}::\${$propertyMeta->relationship->property} is not symmetric.");
×
63
                                }
64

65
                                if ($symmetricPropertyMeta->relationship->type !== $pairs[$propertyMeta->relationship->type]) {
7 ✔
66
                                        throw new InvalidStateException("{$entityMeta->className}::\${$propertyMeta->name} has not defined a proper reverse relationship type in {$symmetricEntityMeta->className}::\${$propertyMeta->relationship->property}.");
×
67
                                }
68

69
                                if (
70
                                        $propertyMeta->relationship->type === PropertyRelationshipMetadata::MANY_HAS_MANY
7 ✔
71
                                        || $propertyMeta->relationship->type === PropertyRelationshipMetadata::ONE_HAS_ONE
7 ✔
72
                                ) {
73
                                        if ($propertyMeta->relationship->isMain && $symmetricPropertyMeta->relationship->isMain) {
7 ✔
74
                                                throw new InvalidStateException("Only one side of relationship {$entityMeta->className}::\${$propertyMeta->name} × {$symmetricEntityMeta->className}::\${$propertyMeta->relationship->property} could be defined as a main.");
×
75
                                        } elseif (!$propertyMeta->relationship->isMain && !$symmetricPropertyMeta->relationship->isMain) {
7 ✔
76
                                                throw new InvalidStateException("At least one side of relationship {$entityMeta->className}::\${$propertyMeta->name} × {$symmetricEntityMeta->className}::\${$propertyMeta->relationship->property} has to be defined as a main.");
×
77
                                        }
78
                                }
79
                        }
80
                }
81
        }
7 ✔
82
}
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