forked from chrisboulton/php-diff
-
Notifications
You must be signed in to change notification settings - Fork 4
Resolve #52 and fixes. #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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(); | ||
JBlond marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.