bircher /
php-merge
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the php-merge package. |
||
| 4 | * |
||
| 5 | * (c) Fabian Bircher <[email protected]> |
||
| 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 PhpMerge\internal; |
||
| 12 | |||
| 13 | use PhpMerge\PhpMergeInterface; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Class PhpMergeBase |
||
| 17 | * |
||
| 18 | * The base class implementing only the simplest logic which is common to all |
||
| 19 | * implementations. |
||
| 20 | * |
||
| 21 | * @package PhpMerge |
||
| 22 | * @author Fabian Bircher <[email protected]> |
||
| 23 | * @copyright Fabian Bircher <[email protected]> |
||
| 24 | * @license https://opensource.org/licenses/MIT |
||
| 25 | * @version Release: @package_version@ |
||
| 26 | * @link http://github.com/bircher/php-merge |
||
| 27 | * @internal This class is not part of the public api. |
||
| 28 | */ |
||
| 29 | abstract class PhpMergeBase implements PhpMergeInterface |
||
| 30 | { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Merge obvious cases when only one text changes.. |
||
| 34 | * |
||
| 35 | * @param string $base |
||
| 36 | * The original text. |
||
| 37 | * @param string $remote |
||
| 38 | * The first variant text. |
||
| 39 | * @param string $local |
||
| 40 | * The second variant text. |
||
| 41 | * |
||
| 42 | * @return string|null |
||
| 43 | * The merge result or null if the merge is not obvious. |
||
| 44 | */ |
||
| 45 | 21 | protected static function simpleMerge(string $base, string $remote, string $local) |
|
| 46 | { |
||
| 47 | // Skip complex merging if there is nothing to do. |
||
| 48 | 21 | if ($base == $remote) { |
|
| 49 | 4 | return $local; |
|
| 50 | } |
||
| 51 | 19 | if ($base == $local) { |
|
| 52 | 2 | return $remote; |
|
| 53 | } |
||
| 54 | 17 | if ($remote == $local) { |
|
| 55 | 2 | return $remote; |
|
| 56 | } |
||
| 57 | // Return nothing and let sub-classes deal with it. |
||
| 58 | 15 | return null; |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Split it line-by-line. |
||
| 63 | * |
||
| 64 | * @param string $input |
||
| 65 | * |
||
| 66 | * @return array |
||
| 67 | */ |
||
| 68 | 12 | protected static function splitStringByLines(string $input): array |
|
| 69 | { |
||
| 70 | 12 | return \preg_split('/(.*\R)/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 71 | } |
||
| 72 | } |
||
| 73 |