src/ThreeWayMerge.php
protected function linesAddedRemovedAndModified(
        array $ancestor,
        array $local,
        array $remote,
        $count_ancestor,
        $count_local,
        $count_remote
    ) {
        $merged = [];
        $count_array = [$count_ancestor, $count_local, $count_remote];
        sort($count_array);
        $mincount = min($count_local, $count_ancestor, $count_remote);
        $maxcount = max($count_local, $count_ancestor, $count_remote);

        // First for loop compares all 3 nodes and returns updated node.
        for ($key = 0; $key < $mincount; $key++) {
            if ($ancestor[$key] == $local[$key]) {
                $merged[$key] = $remote[$key];
            } elseif ($ancestor[$key] == $remote[$key]
                || $local[$key] == $remote[$key]) {
                $merged[$key] = $local[$key];
            } else {
                throw new ConflictException("A conflict has occured");
            }
        }

        // Second for loop compares 2 nodes and if they are identical
        // add the changes to new array otherwise throw conflict exception.
        for ($key = $mincount; $key < $count_array[1]; $key++) {
            if ($count_ancestor == $mincount
                && ($count_remote == $maxcount || $count_local == $maxcount)
            ) {
                if ($local[$key] == $remote[$key]) {
                    $merged[$key] = $local[$key];
                } else {
                    throw new ConflictException("A conflict has occured");
                }
            } elseif ($count_local == $mincount
                && ($count_ancestor == $maxcount
                    || $count_remote == $maxcount)
            ) {
                if ($ancestor[$key] == $remote[$key]) {
                    if (!isset($local[$key])) {
                        unset($merged[$key]);
                    }
                } else {
                    throw new ConflictException("A conflict has occured");
                }
            } elseif ($count_remote == $mincount
                && ($count_ancestor == $maxcount
                    || $count_local == $maxcount)) {
                if ($local[$key] == $ancestor[$key]) {
                    if (!isset($remote[$key])) {
                        unset($merged[$key]);
                    }
                } else {
                    throw new ConflictException("A conflict has occured");
                }
            }
        }

        // Third for loops just adds the newly added lines to new array.
        for ($key = $count_array[1]; $key < $maxcount; $key++) {
            if ($count_remote == $maxcount) {
                $merged[$key] = $remote[$key];
            } elseif ($count_ancestor == $maxcount) {
                $merged[$key] = $ancestor[$key];
            } elseif ($count_local == $maxcount) {
                $merged[$key] = $local[$key];
            }
        }
        return $merged;
    }
protected function linesAddedRemovedAndModified(
        array $ancestor,
        array $local,
        array $remote,
        $count_ancestor,
        $count_local,
        $count_remote
    ) {
        $merged = [];
        $count_array = [$count_ancestor, $count_local, $count_remote];
        sort($count_array);
        $mincount = min($count_local, $count_ancestor, $count_remote);
        $maxcount = max($count_local, $count_ancestor, $count_remote);

        // First for loop compares all 3 nodes and returns updated node.
        for ($key = 0; $key < $mincount; $key++) {
            if ($ancestor[$key] == $local[$key]) {
                $merged[$key] = $remote[$key];
            } elseif ($ancestor[$key] == $remote[$key]
                || $local[$key] == $remote[$key]) {
                $merged[$key] = $local[$key];
            } else {
                throw new ConflictException("A conflict has occured");
            }
        }

        // Second for loop compares 2 nodes and if they are identical
        // add the changes to new array otherwise throw conflict exception.
        for ($key = $mincount; $key < $count_array[1]; $key++) {
            if ($count_ancestor == $mincount
                && ($count_remote == $maxcount || $count_local == $maxcount)
            ) {
                if ($local[$key] == $remote[$key]) {
                    $merged[$key] = $local[$key];
                } else {
                    throw new ConflictException("A conflict has occured");
                }
            } elseif ($count_local == $mincount
                && ($count_ancestor == $maxcount
                    || $count_remote == $maxcount)
            ) {
                if ($ancestor[$key] == $remote[$key]) {
                    if (!isset($local[$key])) {
                        unset($merged[$key]);
                    }
                } else {
                    throw new ConflictException("A conflict has occured");
                }
            } elseif ($count_remote == $mincount
                && ($count_ancestor == $maxcount
                    || $count_local == $maxcount)) {
                if ($local[$key] == $ancestor[$key]) {
                    if (!isset($remote[$key])) {
                        unset($merged[$key]);
                    }
                } else {
                    throw new ConflictException("A conflict has occured");
                }
            }
        }

        // Third for loops just adds the newly added lines to new array.
        for ($key = $count_array[1]; $key < $maxcount; $key++) {
            if ($count_remote == $maxcount) {
                $merged[$key] = $remote[$key];
            } elseif ($count_ancestor == $maxcount) {
                $merged[$key] = $ancestor[$key];
            } elseif ($count_local == $maxcount) {
                $merged[$key] = $local[$key];
            }
        }
        return $merged;
    }
Method to deal with the case where Addition and removal.
takes place simuntaneously.
Example: 2 lines in ancestor, 3 lines in local.
and 1 line in remote.

@param array $ancestor
@param array $local
@param array $remote
@param int   $count_ancestor
@param int   $count_local
@param int   $count_remote

@return array
@throws Exception