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.
- HTML renderer Inline, SideBySide and Unified return false when there's nothing to render. - Text renderer Context, InlineCli and Unified return false when there's nothing to render. Main renderer returns false when there's nothing to render. - Text renderer InlineCli renders line-ending `\n` instead of `PHP_EOL`. - Added missing docBlock content. - Updated docBlock of the SubRenderer Interface. - Added method Diff::isIdentical(). - Updated README.md to reflect Diff::isIdentical().
- Loading branch information
DigiLive
authored and
DigiLive
committed
Jul 22, 2020
1 parent
10986ac
commit fda4852
Showing
12 changed files
with
125 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 | ||
{ | ||
|
@@ -73,6 +73,10 @@ class Diff | |
* @see Diff::setOptions() | ||
*/ | ||
private $options = []; | ||
/** | ||
* @var bool True when compared versions are identical, False otherwise. | ||
*/ | ||
private $identical; | ||
|
||
/** | ||
* The constructor. | ||
|
@@ -169,9 +173,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 +225,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->getGroupedOpCodes() === null) { | ||
$this->getGroupedOpCodes(); | ||
} | ||
|
||
return $this->identical; | ||
} | ||
|
||
/** | ||
* Generate a list of the compiled and grouped op-codes for the differences between two strings. | ||
* | ||
|
@@ -240,6 +258,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.