forked from chrisboulton/php-diff
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from JBlond/php-diff-52
Resolve #52 and fixes.
- Loading branch information
Showing
12 changed files
with
126 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,14 @@ | |
* | ||
* PHP version 7.2 or greater | ||
* | ||
* @package jblond | ||
* @author Chris Boulton <[email protected]> | ||
* @author Mario Brandt <[email protected]> | ||
* @author Ferry Cools <[email protected]> | ||
* @package jblond | ||
* @author Chris Boulton <[email protected]> | ||
* @author Mario Brandt <[email protected]> | ||
* @author Ferry Cools <[email protected]> | ||
* @copyright (c) 2020 Mario Brandt | ||
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php | ||
* @version 2.1.1 | ||
* @link https://github.com/JBlond/php-diff | ||
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php | ||
* @version 2.1.1 | ||
* @link https://github.com/JBlond/php-diff | ||
*/ | ||
class Diff | ||
{ | ||
|
@@ -70,9 +70,14 @@ class Diff | |
/** | ||
* @var array Associative array containing the options that will be applied for generating the diff. | ||
* The key-value pairs are set at the constructor of this class. | ||
* | ||
* @see Diff::setOptions() | ||
*/ | ||
private $options = []; | ||
/** | ||
* @var bool True when compared versions are identical, False otherwise. | ||
*/ | ||
private $identical; | ||
|
||
/** | ||
* The constructor. | ||
|
@@ -169,9 +174,9 @@ public function getVersion2(): array | |
* Render a diff-view using a rendering class and get its results. | ||
* | ||
* @param object|Context|Unified|UnifiedHtml|Inline|SideBySide $renderer An instance of the rendering object, | ||
* used for generating the diff-view. | ||
* used for generating the diff-view. | ||
* | ||
* @return mixed The generated diff-view. The type of the return value depends on the applied rendereder. | ||
* @return mixed The generated diff-view. The type of the return value depends on the applied renderer. | ||
*/ | ||
public function render(object $renderer) | ||
{ | ||
|
@@ -221,6 +226,20 @@ public function getArrayRange(array $array, int $start = 0, $end = null): array | |
return array_slice($array, $start, $length); | ||
} | ||
|
||
/** | ||
* Get if the compared versions are identical or have differences. | ||
* | ||
* @return bool True when identical. | ||
*/ | ||
public function isIdentical(): bool | ||
{ | ||
if ($this->groupedCodes === null) { | ||
$this->getGroupedOpCodes(); | ||
} | ||
|
||
return $this->identical; | ||
} | ||
|
||
/** | ||
* Generate a list of the compiled and grouped op-codes for the differences between two strings. | ||
* | ||
|
@@ -240,6 +259,8 @@ public function getGroupedOpCodes(): array | |
//Get and cache the grouped op-codes. | ||
$sequenceMatcher = new SequenceMatcher($this->version1, $this->version2, $this->options); | ||
$this->groupedCodes = $sequenceMatcher->getGroupedOpCodes(); | ||
$opCodes = $sequenceMatcher->getOpCodes(); | ||
$this->identical = count($opCodes) == 1 && $opCodes[0][0] == 'equal'; | ||
|
||
return $this->groupedCodes; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.