Code Duplication    Length = 20-20 lines in 2 locations

src/Comparator/DiffContext.php 1 location

@@ 116-135 (lines=20) @@
113
     *
114
     * @throws \Nnx\FormComparator\Comparator\Exception\IncorrectElementTypeException
115
     */
116
    protected function validateElementType(ElementInterface $sourceElement, ElementInterface $targetElement)
117
    {
118
        $baseType = ElementInterface::class;
119
        if ($sourceElement instanceof Collection) {
120
            $baseType = Collection::class;
121
        } elseif ($sourceElement instanceof FieldsetInterface) {
122
            $baseType = FieldsetInterface::class;
123
        }
124
125
        if (!$targetElement instanceof $baseType) {
126
            $targetElementName = $targetElement->getName();
127
            $targetElementClass = get_class($targetElement);
128
            $errMsg = sprintf(
129
                'Element %s not implement %s',
130
                is_string($targetElementName) ? sprintf('%s(%s)', $targetElementName, $targetElementClass) : $targetElementClass,
131
                $baseType
132
            );
133
            throw new Exception\IncorrectElementTypeException($errMsg);
134
        }
135
    }
136
137
    /**
138
     * Элемент который сравнивают

src/Comparator/FormDiffService.php 1 location

@@ 111-130 (lines=20) @@
108
     *
109
     * @throws \Nnx\FormComparator\Comparator\Exception\IncorrectElementTypeException
110
     */
111
    protected function validateElementType(ElementInterface $sourceElement, ElementInterface $targetElement)
112
    {
113
        $baseType = ElementInterface::class;
114
        if ($sourceElement instanceof Collection) {
115
            $baseType = Collection::class;
116
        } elseif ($sourceElement instanceof FieldsetInterface) {
117
            $baseType = FieldsetInterface::class;
118
        }
119
120
        if (!$targetElement instanceof $baseType) {
121
            $targetElementName = $targetElement->getName();
122
            $targetElementClass = get_class($targetElement);
123
            $errMsg = sprintf(
124
                'Element %s not implement %s',
125
                is_string($targetElementName) ? sprintf('%s(%s)', $targetElementName, $targetElementClass) : $targetElementClass,
126
                $baseType
127
            );
128
            throw new Exception\IncorrectElementTypeException($errMsg);
129
        }
130
    }
131
132
    /**
133
     * Подготавливает список изменнные элементов для двух Fieldset'ов формы