Skip to content

Commit 1f2c7dc

Browse files
committed
Add api breaking changes and type hints. #2
1 parent 2adc271 commit 1f2c7dc

16 files changed

+55
-31
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ language: php
33
php:
44
- 7.1
55
- 7.0
6-
- 5.6
7-
- 5.5
8-
- 5.4
96

107
before_script:
118
- git --version

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ the library as a dependency to your composer.json file.
145145
```json
146146
{
147147
"require": {
148-
"bircher/php-merge": "~1.0"
148+
"bircher/php-merge": "~2.0"
149149
}
150150
}
151151
```
@@ -155,11 +155,23 @@ To use the command line git with `GitMerge`:
155155
```json
156156
{
157157
"require": {
158-
"bircher/php-merge": "~1.0",
158+
"bircher/php-merge": "~2.0",
159159
"cpliakas/git-wrapper": "~1.0"
160160
}
161161
}
162162
```
163163

164164
Please refer to [Composer's documentation](https://github.com/composer/composer/blob/master/doc/00-intro.md#introduction)
165165
for installation and usage instructions.
166+
167+
168+
## Difference to ~1.0
169+
170+
In the ~2.0 version we dropped support for php 5 and use php 7 constructs
171+
instead. This means that the `PhpMergeInterface` type-hints the arguments and
172+
return type as strings. In addition to that all classes are now final and it
173+
is clearer what the API is. We can consider making the classes inheritable if
174+
needed without breaking the api but not the other way around.
175+
176+
If you have just been using the ~1.0 version as described in this document
177+
the version ~2.0 will continue to work.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "bircher/php-merge",
33
"type": "library",
44
"description": "A PHP merge utility using the Diff php library or the command line git.",
5-
"keywords": ["git", "merge"],
5+
"keywords": ["git", "merge", "php-merge"],
66
"homepage": "https://github.com/bircher/php-merge",
77
"license": "MIT",
88
"authors": [
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.3.0",
15+
"php": ">=7.0.0",
1616
"sebastian/diff": "^1.3"
1717
},
1818
"require-dev": {

src/PhpMerge/GitMerge.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
use GitWrapper\GitWrapper;
1414
use GitWrapper\GitException;
15+
use PhpMerge\internal\Line;
16+
use PhpMerge\internal\Hunk;
17+
use PhpMerge\internal\PhpMergeBase;
1518
use SebastianBergmann\Diff\Differ;
1619

1720
/**
@@ -31,7 +34,7 @@
3134
* @link http://github.com/bircher/php-merge
3235
* @category library
3336
*/
34-
class GitMerge extends PhpMergeBase implements PhpMergeInterface
37+
final class GitMerge extends PhpMergeBase implements PhpMergeInterface
3538
{
3639

3740
/**
@@ -63,7 +66,7 @@ class GitMerge extends PhpMergeBase implements PhpMergeInterface
6366
/**
6467
* {@inheritdoc}
6568
*/
66-
public function merge($base, $remote, $local)
69+
public function merge(string $base, string $remote, string $local) : string
6770
{
6871

6972
// Skip merging if there is nothing to do.
@@ -111,7 +114,7 @@ public function merge($base, $remote, $local)
111114
* @return string
112115
* The merged text.
113116
*/
114-
protected function mergeFile($file, $base, $remote, $local)
117+
protected function mergeFile(string $file, string $base, string $remote, string $local) : string
115118
{
116119
file_put_contents($file, $base);
117120
$this->git->add($file);
@@ -287,7 +290,8 @@ protected static function getConflicts($file, $baseText, $remoteText, $localText
287290
}
288291

289292
/**
290-
* {@inheritdoc}
293+
* @param $text
294+
* @return string
291295
*/
292296
protected static function preMergeAlter($text)
293297
{
@@ -296,7 +300,8 @@ protected static function preMergeAlter($text)
296300
}
297301

298302
/**
299-
* {@inheritdoc}
303+
* @param $text
304+
* @return bool|string
300305
*/
301306
protected static function postMergeAlter($text)
302307
{

src/PhpMerge/MergeConflict.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @version Release: @package_version@
2525
* @link http://github.com/bircher/php-merge
2626
*/
27-
class MergeConflict
27+
final class MergeConflict
2828
{
2929

3030
/**

src/PhpMerge/MergeException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @version Release: @package_version@
2525
* @link http://github.com/bircher/php-merge
2626
*/
27-
class MergeException extends \RuntimeException
27+
final class MergeException extends \RuntimeException
2828
{
2929

3030
/**
@@ -75,7 +75,7 @@ public function getConflicts()
7575
* @return string
7676
* The merged text.
7777
*/
78-
public function getMerged()
78+
public function getMerged() : string
7979
{
8080
return $this->merged;
8181
}

src/PhpMerge/PhpMerge.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
namespace PhpMerge;
1212

13+
use PhpMerge\internal\Line;
14+
use PhpMerge\internal\Hunk;
15+
use PhpMerge\internal\PhpMergeBase;
1316
use SebastianBergmann\Diff\Differ;
1417

1518
/**
@@ -26,7 +29,7 @@
2629
* @version Release: @package_version@
2730
* @link http://github.com/bircher/php-merge
2831
*/
29-
class PhpMerge extends PhpMergeBase implements PhpMergeInterface
32+
final class PhpMerge extends PhpMergeBase implements PhpMergeInterface
3033
{
3134

3235
/**
@@ -51,7 +54,7 @@ public function __construct(Differ $differ = null)
5154
/**
5255
* {@inheritdoc}
5356
*/
54-
public function merge($base, $remote, $local)
57+
public function merge(string $base, string $remote, string $local) : string
5558
{
5659
// Skip merging if there is nothing to do.
5760
if ($merged = PhpMergeBase::simpleMerge($base, $remote, $local)) {
@@ -99,7 +102,7 @@ function ($l) {
99102
* @return string[]
100103
* The merged text.
101104
*/
102-
protected static function mergeHunks($base, $remote, $local, &$conflicts = [])
105+
protected static function mergeHunks(array $base, array $remote, array $local, array &$conflicts = []) : array
103106
{
104107
$remote = new \ArrayObject($remote);
105108
$local = new \ArrayObject($local);

src/PhpMerge/PhpMergeInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ interface PhpMergeInterface
3939
* @throws MergeException
4040
* Thrown when there is a merge conflict.
4141
*/
42-
public function merge($base, $remote, $local);
42+
public function merge(string $base, string $remote, string $local) : string;
4343
}

src/PhpMerge/Hunk.php renamed to src/PhpMerge/internal/Hunk.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace PhpMerge;
11+
namespace PhpMerge\internal;
1212

1313
/**
1414
* Class Hunk
@@ -21,8 +21,9 @@
2121
* @license https://opensource.org/licenses/MIT
2222
* @version Release: @package_version@
2323
* @link http://github.com/bircher/php-merge
24+
* @internal This class is not part of the public api.
2425
*/
25-
class Hunk
26+
final class Hunk
2627
{
2728

2829
const ADDED = 1;

src/PhpMerge/Line.php renamed to src/PhpMerge/internal/Line.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace PhpMerge;
11+
namespace PhpMerge\internal;
1212

1313
use SebastianBergmann\Diff\Line as DiffLine;
1414

@@ -21,8 +21,9 @@
2121
* @license https://opensource.org/licenses/MIT
2222
* @version Release: @package_version@
2323
* @link http://github.com/bircher/php-merge
24+
* @internal This class is not part of the public api.
2425
*/
25-
class Line extends DiffLine
26+
final class Line extends DiffLine
2627
{
2728

2829
/**

0 commit comments

Comments
 (0)