Mercurial > hg > isophonics-drupal-site
comparison vendor/sebastian/diff/src/Output/AbstractChunkOutputBuilder.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php declare(strict_types=1); | |
2 /* | |
3 * This file is part of sebastian/diff. | |
4 * | |
5 * (c) Sebastian Bergmann <sebastian@phpunit.de> | |
6 * | |
7 * For the full copyright and license information, please view the LICENSE | |
8 * file that was distributed with this source code. | |
9 */ | |
10 | |
11 namespace SebastianBergmann\Diff\Output; | |
12 | |
13 abstract class AbstractChunkOutputBuilder implements DiffOutputBuilderInterface | |
14 { | |
15 /** | |
16 * Takes input of the diff array and returns the common parts. | |
17 * Iterates through diff line by line. | |
18 * | |
19 * @param array $diff | |
20 * @param int $lineThreshold | |
21 * | |
22 * @return array | |
23 */ | |
24 protected function getCommonChunks(array $diff, int $lineThreshold = 5): array | |
25 { | |
26 $diffSize = \count($diff); | |
27 $capturing = false; | |
28 $chunkStart = 0; | |
29 $chunkSize = 0; | |
30 $commonChunks = []; | |
31 | |
32 for ($i = 0; $i < $diffSize; ++$i) { | |
33 if ($diff[$i][1] === 0 /* OLD */) { | |
34 if ($capturing === false) { | |
35 $capturing = true; | |
36 $chunkStart = $i; | |
37 $chunkSize = 0; | |
38 } else { | |
39 ++$chunkSize; | |
40 } | |
41 } elseif ($capturing !== false) { | |
42 if ($chunkSize >= $lineThreshold) { | |
43 $commonChunks[$chunkStart] = $chunkStart + $chunkSize; | |
44 } | |
45 | |
46 $capturing = false; | |
47 } | |
48 } | |
49 | |
50 if ($capturing !== false && $chunkSize >= $lineThreshold) { | |
51 $commonChunks[$chunkStart] = $chunkStart + $chunkSize; | |
52 } | |
53 | |
54 return $commonChunks; | |
55 } | |
56 } |