From 29dc0029cc81193ac1e296770a9edaf7d8720857 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 15 Oct 2013 12:52:58 +0400 Subject: [PATCH 1/3] PHP 5.5 compatibility fix --- lib/Diff/Renderer/Html/Array.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index 0b3f1d50..20a55162 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -177,7 +177,7 @@ private function formatLines($lines) $lines = array_map(array($this, 'ExpandTabs'), $lines); $lines = array_map(array($this, 'HtmlSafe'), $lines); foreach($lines as &$line) { - $line = preg_replace('# ( +)|^ #e', "\$this->fixSpaces('\\1')", $line); + $line = preg_replace_callback('# ( +)|^ #', __CLASS__."::fixSpaces", $line); } return $lines; } @@ -188,7 +188,7 @@ private function formatLines($lines) * @param string $spaces The string of spaces. * @return string The HTML representation of the string. */ - function fixSpaces($spaces='') + public static function fixSpaces($spaces='') { $count = strlen($spaces); if($count == 0) { From dd80390d67c2743c8e9872781b1adbd376fb6904 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 15 Oct 2013 12:53:16 +0400 Subject: [PATCH 2/3] phpdoc fixes --- lib/Diff.php | 3 ++- lib/Diff/SequenceMatcher.php | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/Diff.php b/lib/Diff.php index 35305c03..d6cecb79 100644 --- a/lib/Diff.php +++ b/lib/Diff.php @@ -80,6 +80,7 @@ class Diff * * @param array $a Array containing the lines of the first string to compare. * @param array $b Array containing the lines for the second string to compare. + * @param array $options */ public function __construct($a, $b, $options=array()) { @@ -92,7 +93,7 @@ public function __construct($a, $b, $options=array()) /** * Render a diff using the supplied rendering class and return it. * - * @param object $renderer An instance of the rendering object to use for generating the diff. + * @param Diff_Renderer_Abstract $renderer An instance of the rendering object to use for generating the diff. * @return mixed The generated diff. Exact return value depends on the rendered. */ public function render(Diff_Renderer_Abstract $renderer) diff --git a/lib/Diff/SequenceMatcher.php b/lib/Diff/SequenceMatcher.php index e819e810..67a903b3 100644 --- a/lib/Diff/SequenceMatcher.php +++ b/lib/Diff/SequenceMatcher.php @@ -83,6 +83,7 @@ class Diff_SequenceMatcher * @param string|array $a A string or array containing the lines to compare against. * @param string|array $b A string or array containing the lines to compare. * @param string|array $junkCallback Either an array or string that references a callback function (if there is one) to determine 'junk' characters. + * @param array $options */ public function __construct($a, $b, $junkCallback=null, $options) { @@ -93,6 +94,11 @@ public function __construct($a, $b, $junkCallback=null, $options) $this->setSequences($a, $b); } + /** + * Set new options + * + * @param array $options + */ public function setOptions($options) { $this->options = array_merge($this->defaultOptions, $options); @@ -206,8 +212,8 @@ private function chainB() /** * Checks if a particular character is in the junk dictionary * for the list of junk characters. - * - * @return boolean $b True if the character is considered junk. False if not. + * @param $b + * @return boolean True if the character is considered junk. False if not. */ private function isBJunk($b) { @@ -631,7 +637,7 @@ private function quickRatio() { if($this->fullBCount === null) { $this->fullBCount = array(); - $bLength = count ($b); + $bLength = count ($this->b); for($i = 0; $i < $bLength; ++$i) { $char = $this->b[$i]; $this->fullBCount[$char] = $this->arrayGetDefault($this->fullBCount, $char, 0) + 1; @@ -729,7 +735,7 @@ private function tupleSort($a, $b) } } - if(count($a) == $count($b)) { + if(count($a) == count($b)) { return 0; } else if(count($a) < count($b)) { From 71cd475aef0b1ccda2c15f5c4766a221fb71fb49 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 15 Oct 2013 13:53:22 +0400 Subject: [PATCH 3/3] Fixed callback --- lib/Diff/Renderer/Html/Array.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Diff/Renderer/Html/Array.php b/lib/Diff/Renderer/Html/Array.php index 20a55162..7113a174 100644 --- a/lib/Diff/Renderer/Html/Array.php +++ b/lib/Diff/Renderer/Html/Array.php @@ -185,11 +185,12 @@ private function formatLines($lines) /** * Replace a string containing spaces with a HTML representation using  . * - * @param string $spaces The string of spaces. + * @param string $matches Regex matches array. * @return string The HTML representation of the string. */ - public static function fixSpaces($spaces='') + public static function fixSpaces($matches) { + $spaces = isset($matches[1]) ? $matches[1] : ''; $count = strlen($spaces); if($count == 0) { return '';