Skip to content

Commit 3591515

Browse files
committed
Optimize constant usage
Instead of defining constants with the same name and values at different namespaces, they're now defined at an interface which can be shared among classes by implementing this interface.
1 parent dabb467 commit 3591515

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

lib/jblond/Diff.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace jblond;
66

77
use InvalidArgumentException;
8+
use jblond\Diff\ConstantsInterface;
89
use jblond\Diff\SequenceMatcher;
910
use jblond\Diff\Similarity;
1011
use OutOfRangeException;
@@ -26,20 +27,8 @@
2627
* @version 2.3.0
2728
* @link https://github.com/JBlond/php-diff
2829
*/
29-
class Diff
30+
class Diff implements ConstantsInterface
3031
{
31-
/**
32-
* Flag to disable ignore of successive empty/blank lines.
33-
*/
34-
public const DIFF_IGNORE_LINE_NONE = 0;
35-
/**
36-
* Flag to ignore successive empty lines.
37-
*/
38-
public const DIFF_IGNORE_LINE_EMPTY = 1;
39-
/**
40-
* Flag to ignore successive blank lines. (Lines which contain no or only non printable characters.)
41-
*/
42-
public const DIFF_IGNORE_LINE_BLANK = 2;
4332
/**
4433
* @var array The first version to compare.
4534
* Each element contains a line of this string.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace jblond\Diff;
4+
/**
5+
* Constant Interface
6+
*
7+
* Defines the library constants which needs to be shared across the different classes.
8+
*
9+
* PHP version 7.2 or greater
10+
*
11+
* @package jblond
12+
* @author Ferry Cools <[email protected]>
13+
* @copyright (c) 2020 Mario Brandt
14+
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
15+
* @version 2.3.0
16+
* @link https://github.com/JBlond/php-diff
17+
*/
18+
interface ConstantsInterface
19+
{
20+
/**
21+
* Flag to disable ignore of successive empty/blank lines.
22+
*/
23+
public const DIFF_IGNORE_LINE_NONE = 0;
24+
/**
25+
* Flag to ignore empty lines.
26+
*/
27+
public const DIFF_IGNORE_LINE_EMPTY = 1;
28+
/**
29+
* Flag to ignore blank lines. (Lines which contain no or only non printable characters.)
30+
*/
31+
public const DIFF_IGNORE_LINE_BLANK = 2;
32+
33+
}

lib/jblond/Diff/SequenceMatcher.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,8 @@
2020
* @version 2.3.0
2121
* @link https://github.com/JBlond/php-diff
2222
*/
23-
class SequenceMatcher
23+
class SequenceMatcher implements ConstantsInterface
2424
{
25-
/**
26-
* Flag to disable ignore of successive empty/blank lines.
27-
*/
28-
public const DIFF_IGNORE_LINE_NONE = 0;
29-
/**
30-
* Flag to ignore empty lines.
31-
*/
32-
public const DIFF_IGNORE_LINE_EMPTY = 1;
33-
/**
34-
* Flag to ignore blank lines. (Lines which contain no or only non printable characters.)
35-
*/
36-
public const DIFF_IGNORE_LINE_BLANK = 2;
3725
/**
3826
* @var array The first sequence to compare against.
3927
*/
@@ -360,12 +348,18 @@ public function getOpCodes(): array
360348
$part2 = array_slice($this->new, $j, $bj - $j);
361349

362350
if ($this->options['ignoreLines'] == 2) {
363-
array_walk($part1, function (&$line) {
364-
$line = trim($line);
365-
});
366-
array_walk($part2, function (&$line) {
367-
$line = trim($line);
368-
});
351+
array_walk(
352+
$part1,
353+
function (&$line) {
354+
$line = trim($line);
355+
}
356+
);
357+
array_walk(
358+
$part2,
359+
function (&$line) {
360+
$line = trim($line);
361+
}
362+
);
369363
unset($line);
370364
}
371365

0 commit comments

Comments
 (0)