Skip to content

Commit

Permalink
Merge pull request phpspec#2 from samdark/5.5-and-cleanup
Browse files Browse the repository at this point in the history
5.5 and cleanup
  • Loading branch information
everzet committed Nov 1, 2013
2 parents 8d82ac4 + 71cd475 commit 30e103d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions lib/Diff/Renderer/Html/Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,20 @@ 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;
}

/**
* 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.
*/
function fixSpaces($spaces='')
public static function fixSpaces($matches)
{
$spaces = isset($matches[1]) ? $matches[1] : '';
$count = strlen($spaces);
if($count == 0) {
return '';
Expand Down
14 changes: 10 additions & 4 deletions lib/Diff/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 30e103d

Please sign in to comment.