Passed
Push — 4.x ( db19f6...38fd84 )
by Fabian
04:30
created

AbstractMergeBase::splitStringByLines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
declare(strict_types=1);
12
13
namespace PhpMerge\internal;
14
15
use PhpMerge\PhpMergeInterface;
16
17
/**
18
 * Class PhpMergeBase
19
 *
20
 * The base class implementing only the simplest logic which is common to all
21
 * implementations.
22
 *
23
 * @internal This class is not part of the public api.
24
 */
25
abstract class AbstractMergeBase implements PhpMergeInterface
26
{
27
28
    /**
29
     * Merge obvious cases when only one text changes..
30
     *
31
     * @param string $base
32
     *   The original text.
33
     * @param string $remote
34
     *   The first variant text.
35
     * @param string $local
36
     *   The second variant text.
37
     *
38
     * @return string|null
39
     *   The merge result or null if the merge is not obvious.
40
     */
41 21
    protected static function simpleMerge(string $base, string $remote, string $local)
42
    {
43
        // Skip complex merging if there is nothing to do.
44 21
        if ($base === $remote) {
45 4
            return $local;
46
        }
47 19
        if ($base === $local) {
48 2
            return $remote;
49
        }
50 17
        if ($remote === $local) {
51 2
            return $remote;
52
        }
53
        // Return nothing and let sub-classes deal with it.
54 15
        return null;
55
    }
56
57
    /**
58
     * Split it line-by-line.
59
     *
60
     * @param string $input
61
     *
62
     * @return array
63
     */
64 12
    protected static function splitStringByLines(string $input): array
65
    {
66 12
        return \preg_split('/(.*\R)/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
67
    }
68
}
69