Passed
Pull Request — master (#4)
by Fabian
14:31
created

PhpMergeBase::splitStringByLines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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 84
    protected static function simpleMerge(string $base, string $remote, string $local)
46
    {
47
        // Skip complex merging if there is nothing to do.
48 84
        if ($base == $remote) {
49 16
            return $local;
50
        }
51 76
        if ($base == $local) {
52 8
            return $remote;
53
        }
54 68
        if ($remote == $local) {
55 8
            return $remote;
56
        }
57
        // Return nothing and let sub-classes deal with it.
58 60
        return null;
59
    }
60
61
    /**
62
     * Split it line-by-line.
63
     *
64
     * @param string $input
65
     *
66
     * @return array
67
     */
68
    protected static function splitStringByLines(string $input): array
69
    {
70
        return \preg_split('/(.*\R)/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
71
    }
72
}
73