Skip to content
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

Fixed warnings "count(): Parameter must be an array... #65

Merged
merged 2 commits into from
Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Caxy/HtmlDiff/AbstractDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ protected function convertHtmlToListOfWords($characterString)
$mode = 'character';
$current_word = '';
$words = array();
$keepNewLines = $this->getConfig()->isKeepNewLines();
foreach ($characterString as $i => $character) {
switch ($mode) {
case 'character':
Expand All @@ -488,7 +489,7 @@ protected function convertHtmlToListOfWords($characterString)
if ($current_word !== '') {
$words[] = $current_word;
}
$current_word = preg_replace('/\s+/S', ' ', $character);
$current_word = $keepNewLines ? $character : preg_replace('/\s+/S', ' ', $character);
$mode = 'whitespace';
} else {
if (
Expand Down Expand Up @@ -526,7 +527,7 @@ protected function convertHtmlToListOfWords($characterString)
$mode = 'tag';
} elseif (preg_match("/\s/", $character)) {
$current_word .= $character;
$current_word = preg_replace('/\s+/S', ' ', $current_word);
if (!$keepNewLines) $current_word = preg_replace('/\s+/S', ' ', $current_word);
} else {
if ($current_word != '') {
$words[] = $current_word;
Expand Down
2 changes: 1 addition & 1 deletion lib/Caxy/HtmlDiff/HtmlDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ protected function insertTag($tag, $cssClass, &$words)
}
}
}
if (count($words) == 0 && count($specialCaseTagInjection) == 0) {
if (count($words) == 0 && strlen($specialCaseTagInjection) == 0) {
break;
}
if ($specialCaseTagInjectionIsBefore) {
Expand Down
23 changes: 23 additions & 0 deletions lib/Caxy/HtmlDiff/HtmlDiffConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class HtmlDiffConfig
*/
protected $insertSpaceInReplace = false;

/**
* Whether to keep newlines in the diff
* @var bool
*/
protected $keepNewLines = false;

/**
* @var string
*/
Expand All @@ -48,6 +54,7 @@ class HtmlDiffConfig
'i' => '[[REPLACE_EM]]',
'a' => '[[REPLACE_A]]',
'img' => '[[REPLACE_IMG]]',
'pre' => '[[REPLACE_PRE]]',
);

/**
Expand Down Expand Up @@ -293,6 +300,22 @@ public function setInsertSpaceInReplace($insertSpaceInReplace)
return $this;
}

/**
* @return bool
*/
public function isKeepNewLines()
{
return $this->keepNewLines;
}

/**
* @param bool $keepNewLines
*/
public function setKeepNewLines($keepNewLines)
{
$this->keepNewLines = $keepNewLines;
}

/**
* @return array
*/
Expand Down
6 changes: 5 additions & 1 deletion lib/Caxy/HtmlDiff/Match.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Caxy\HtmlDiff;

class Match
class Match implements \Countable
{
public $startInOld;
public $startInNew;
Expand All @@ -24,4 +24,8 @@ public function endInNew()
{
return $this->startInNew + $this->size;
}

public function count() {
return (int)$this->size;
}
}