Code Duplication    Length = 21-21 lines in 2 locations

src/Majora/Framework/Normalizer/MajoraNormalizer.php 2 locations

@@ 107-127 (lines=21) @@
104
     *
105
     * @return \Closure
106
     */
107
    private function createReadingDelegate()
108
    {
109
        return $this->readDelegate ?: $this->readDelegate = function ($property, PropertyAccessor $propertyAccessor) {
110
            switch (true) {
111
112
                // Public property / accessor case
113
                case $propertyAccessor->isReadable($this, $property) :
114
                    return $propertyAccessor->getValue($this, $property);
115
116
                // Private property / StdClass
117
                case property_exists($this, $property) || $this instanceof \StdClass:
118
                    return $this->$property;
119
            }
120
121
            throw new InvalidScopeException(sprintf(
122
                'Unable to read "%s" property from a "%s" object, any existing property path to read it in.',
123
                $property,
124
                get_class($this)
125
            ));
126
        };
127
    }
128
129
    /**
130
     * Normalize given object using given scope.
@@ 268-288 (lines=21) @@
265
     *
266
     * @return \Closure
267
     */
268
    private function createWrittingDelegate()
269
    {
270
        return $this->writeDelegate ?: $this->writeDelegate = function (PropertyPathInterface $property, $value, PropertyAccessor $propertyAccessor) {
271
            switch (true) {
272
273
                // Public property / accessor case
274
                case $propertyAccessor->isWritable($this, $property) :
275
                    return $propertyAccessor->setValue($this, $property, $value);
276
277
                // Private property / StdClass
278
                case property_exists($this, $property) || $this instanceof \StdClass :
279
                    return $this->$property = $value;
280
            }
281
282
            throw new InvalidScopeException(sprintf(
283
                'Unable to set "%s" property into a "%s" object, any existing property path to write it in.',
284
                $property,
285
                get_class($this)
286
            ));
287
        };
288
    }
289
290
    /**
291
     * Denormalize given object data into given normalizable object or class