Code Duplication    Length = 36-38 lines in 2 locations

Hydration/EntityHydrator.php 2 locations

@@ 76-113 (lines=38) @@
73
                $processDescription = sprintf("of entity '%s'", $className);
74
75
                try {
76
                    if ($mapping instanceof EntityMappingInterface) {
77
                        $context = new HydrationContext($entity, $entityManager);
78
79
                        foreach ($mapping->getFieldMappings() as $fieldName => $fieldMapping) {
80
                            /** @var MappingInterface $fieldMapping */
81
82
                            $processDescription = sprintf(
83
                                "of field '%s' of entity '%s'",
84
                                $fieldName,
85
                                $className
86
                            );
87
88
                            /** @var mixed $value */
89
                            $value = $fieldMapping->resolveValue(
90
                                $context,
91
                                $dataFromAdditionalColumns
92
                            );
93
94
                            /** @var ReflectionClass $concreteClassReflection */
95
                            $concreteClassReflection = $classReflection;
96
97
                            while (!$concreteClassReflection->hasProperty($fieldName)) {
98
                                $concreteClassReflection = $concreteClassReflection->getParentClass();
99
100
                                Assert::object($concreteClassReflection, sprintf(
101
                                    "Property '%s' does not exist on object of class '%s'!",
102
                                    $fieldName,
103
                                    $className
104
                                ));
105
                            }
106
107
                            /** @var ReflectionProperty $propertyReflection */
108
                            $propertyReflection = $concreteClassReflection->getProperty($fieldName);
109
110
                            $propertyReflection->setAccessible(true);
111
                            $propertyReflection->setValue($entity, $value);
112
                        }
113
                    }
114
115
                } catch (Throwable $exception) {
116
                    throw new MappingException(sprintf(
@@ 150-185 (lines=36) @@
147
            /** @var ?EntityMappingInterface $mapping */
148
            $mapping = $this->mappingDriver->loadRDMMetadataForClass($className);
149
150
            if ($mapping instanceof EntityMappingInterface) {
151
                if ($mapping instanceof EntityMappingInterface) {
152
                    $context = new HydrationContext($entity, $entityManager);
153
154
                    foreach ($mapping->getFieldMappings() as $fieldName => $fieldMapping) {
155
                        /** @var MappingInterface $fieldMapping */
156
157
                        /** @var ReflectionClass $concreteClassReflection */
158
                        $concreteClassReflection = $classReflection;
159
160
                        while (!$concreteClassReflection->hasProperty($fieldName)) {
161
                            $concreteClassReflection = $concreteClassReflection->getParentClass();
162
163
                            Assert::notFalse($concreteClassReflection, sprintf(
164
                                "Property '%s' does not exist on object of class '%s'!",
165
                                $fieldName,
166
                                $className
167
                            ));
168
                        }
169
170
                        /** @var ReflectionProperty $propertyReflection */
171
                        $propertyReflection = $concreteClassReflection->getProperty($fieldName);
172
173
                        $propertyReflection->setAccessible(true);
174
175
                        /** @var object $actualValue */
176
                        $actualValue = $propertyReflection->getValue($entity);
177
178
                        $fieldMapping->assertValue(
179
                            $context,
180
                            $dataFromAdditionalColumns,
181
                            $actualValue
182
                        );
183
                    }
184
                }
185
            }
186
187
            $className = current(class_parents($className));
188
        } while (class_exists($className));