Code Duplication    Length = 29-30 lines in 2 locations

src/Data/Addon/Journal/DomainModel/RecordableHistory.php 2 locations

@@ 170-198 (lines=29) @@
167
     * @param mixed[]    $before
168
     * @param mixed[]    $after
169
     */
170
    private function diffRecursiveFromBeforeToAfter(RecordDiff $diff, $pathInArray, $before, $after)
171
    {
172
        if (! \is_array($before) && ! $before instanceof \Traversable) {
173
174
            $beforeValue = $this->convertToString($before);
175
            $afterValue  = $this->convertToString($after);
176
177
            if ($beforeValue !== $afterValue) {
178
                $diff->addChange(new RecordDiffEntry($pathInArray, $beforeValue, $afterValue));
179
            }
180
        } else {
181
182
            foreach ($before as $key => $beforeValue) {
183
184
                $afterValue = null;
185
186
                if ((\is_array($after) || $after instanceof \ArrayAccess) && isset($after[$key])) {
187
                    $afterValue = $after[$key];
188
                }
189
190
                $this->diffRecursiveFromBeforeToAfter(
191
                    $diff,
192
                    empty($pathInArray) ? $key : $pathInArray . '.' . $key,
193
                    $beforeValue,
194
                    $afterValue
195
                );
196
            }
197
        }
198
    }
199
200
    /**
201
     * @param RecordDiff $diff
@@ 206-235 (lines=30) @@
203
     * @param array      $before
204
     * @param array      $after
205
     */
206
    private function diffRecursiveFromAfterToBefore(RecordDiff $diff, $pathInArray, $before, $after)
207
    {
208
        if (! \is_array($after) && ! $after instanceof \Traversable) {
209
210
            $beforeValue = $this->convertToString($before);
211
            $afterValue  = $this->convertToString($after);
212
213
            if ($beforeValue !== $afterValue) {
214
                $diff->addChange(new RecordDiffEntry($pathInArray, $beforeValue, $afterValue));
215
            }
216
        } else {
217
218
            // first compare from before to after
219
            foreach ($after as $key => $afterValue) {
220
221
                $beforeValue = null;
222
223
                if ((\is_array($before) || $before instanceof \ArrayAccess) && isset($before[$key])) {
224
                    $beforeValue = $before[$key];
225
                }
226
227
                $this->diffRecursiveFromAfterToBefore(
228
                    $diff,
229
                    empty($pathInArray) ? $key : $pathInArray . '.' . $key,
230
                    $beforeValue,
231
                    $afterValue
232
                );
233
            }
234
        }
235
    }
236
237
    /**
238
     * @param        $value