@@ -505,6 +505,7 @@ discard block |
||
| 505 | 505 | * @param string $oldList |
| 506 | 506 | * @param array $match |
| 507 | 507 | * @param array $index |
| 508 | + * @param string $type |
|
| 508 | 509 | * @return string |
| 509 | 510 | */ |
| 510 | 511 | protected function addListElementToContent($newList, $oldList, array $match, array $index, $type) |
@@ -588,7 +589,7 @@ discard block |
||
| 588 | 589 | /** |
| 589 | 590 | * Converts the list (li) content arrays to string. |
| 590 | 591 | * |
| 591 | - * @param array $listContentArray |
|
| 592 | + * @param string $listContentArray |
|
| 592 | 593 | * @return string |
| 593 | 594 | */ |
| 594 | 595 | protected function convertListContentArrayToString($listContentArray) |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | protected $listIsolatedDiffTags = array(); |
| 21 | 21 | |
| 22 | 22 | /** @var array */ |
| 23 | - protected $isolatedDiffTags = array ( |
|
| 23 | + protected $isolatedDiffTags = array( |
|
| 24 | 24 | 'ol' => '[[REPLACE_ORDERED_LIST]]', |
| 25 | 25 | 'ul' => '[[REPLACE_UNORDERED_LIST]]', |
| 26 | 26 | 'dl' => '[[REPLACE_DEFINITION_LIST]]', |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | $columns = $this->getArrayColumn($bestMatchPercentages, $key); |
| 358 | 358 | $thisBestMatches = array_filter( |
| 359 | 359 | $columns, |
| 360 | - function ($v) use ($percent) { |
|
| 360 | + function($v) use ($percent) { |
|
| 361 | 361 | return $v > $percent; |
| 362 | 362 | } |
| 363 | 363 | ); |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | $match = $word == self::$listPlaceHolder; |
| 606 | 606 | |
| 607 | 607 | $content[] = $match |
| 608 | - ? "<li>" . $this->convertListContentArrayToString($listContentArray['kids'][$nestedListCount]) . "</li>" |
|
| 608 | + ? "<li>".$this->convertListContentArrayToString($listContentArray['kids'][$nestedListCount])."</li>" |
|
| 609 | 609 | : $word; |
| 610 | 610 | |
| 611 | 611 | if ($match) { |
@@ -652,7 +652,7 @@ discard block |
||
| 652 | 652 | $content = $preContent; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - $returnText[] = is_array($preContent) ? $preContent[0] . $content . $preContent[2] : $content; |
|
| 655 | + $returnText[] = is_array($preContent) ? $preContent[0].$content.$preContent[2] : $content; |
|
| 656 | 656 | } |
| 657 | 657 | // Return the result. |
| 658 | 658 | return implode(' ', $returnText); |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | if ($opening) { |
| 788 | 788 | return $this->newParentTag ?: $this->oldParentTag; |
| 789 | 789 | } else { |
| 790 | - return "<" . (!$opening ? "/" : '') . $this->listType . ">"; |
|
| 790 | + return "<".(!$opening ? "/" : '').$this->listType.">"; |
|
| 791 | 791 | } |
| 792 | 792 | } |
| 793 | 793 | |
@@ -14,6 +14,9 @@ |
||
| 14 | 14 | |
| 15 | 15 | protected $endTag; |
| 16 | 16 | |
| 17 | + /** |
|
| 18 | + * @param null|string $listType |
|
| 19 | + */ |
|
| 17 | 20 | public function __construct($listType, $startTag, $endTag, $listItems = array(), $attributes = array()) |
| 18 | 21 | { |
| 19 | 22 | $this->listType = $listType; |
@@ -217,12 +217,18 @@ discard block |
||
| 217 | 217 | return $diffList; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | + /** |
|
| 221 | + * @param string $type |
|
| 222 | + */ |
|
| 220 | 223 | protected function isOpeningListTag($word, $type = null) |
| 221 | 224 | { |
| 222 | 225 | $filter = $type !== null ? array('<' . $type) : array('<ul', '<ol', '<dl'); |
| 223 | 226 | return in_array(substr($word, 0, 3), $filter); |
| 224 | 227 | } |
| 225 | 228 | |
| 229 | + /** |
|
| 230 | + * @param string $type |
|
| 231 | + */ |
|
| 226 | 232 | protected function isClosingListTag($word, $type = null) |
| 227 | 233 | { |
| 228 | 234 | $filter = $type !== null ? array('</' . $type) : array('</ul', '</ol', '</dl'); |
@@ -230,6 +236,9 @@ discard block |
||
| 230 | 236 | return in_array(substr($word, 0, 4), $filter); |
| 231 | 237 | } |
| 232 | 238 | |
| 239 | + /** |
|
| 240 | + * @param string $type |
|
| 241 | + */ |
|
| 233 | 242 | protected function isOpeningListItemTag($word, $type = null) |
| 234 | 243 | { |
| 235 | 244 | $filter = $type !== null ? array('<' . $type) : array('<li', '<dd', '<dt'); |
@@ -237,6 +246,9 @@ discard block |
||
| 237 | 246 | return in_array(substr($word, 0, 3), $filter); |
| 238 | 247 | } |
| 239 | 248 | |
| 249 | + /** |
|
| 250 | + * @param string $type |
|
| 251 | + */ |
|
| 240 | 252 | protected function isClosingListItemTag($word, $type = null) |
| 241 | 253 | { |
| 242 | 254 | $filter = $type !== null ? array('</' . $type) : array('</li', '</dd', '</dt'); |
@@ -219,27 +219,27 @@ |
||
| 219 | 219 | |
| 220 | 220 | protected function isOpeningListTag($word, $type = null) |
| 221 | 221 | { |
| 222 | - $filter = $type !== null ? array('<' . $type) : array('<ul', '<ol', '<dl'); |
|
| 222 | + $filter = $type !== null ? array('<'.$type) : array('<ul', '<ol', '<dl'); |
|
| 223 | 223 | return in_array(substr($word, 0, 3), $filter); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | protected function isClosingListTag($word, $type = null) |
| 227 | 227 | { |
| 228 | - $filter = $type !== null ? array('</' . $type) : array('</ul', '</ol', '</dl'); |
|
| 228 | + $filter = $type !== null ? array('</'.$type) : array('</ul', '</ol', '</dl'); |
|
| 229 | 229 | |
| 230 | 230 | return in_array(substr($word, 0, 4), $filter); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | protected function isOpeningListItemTag($word, $type = null) |
| 234 | 234 | { |
| 235 | - $filter = $type !== null ? array('<' . $type) : array('<li', '<dd', '<dt'); |
|
| 235 | + $filter = $type !== null ? array('<'.$type) : array('<li', '<dd', '<dt'); |
|
| 236 | 236 | |
| 237 | 237 | return in_array(substr($word, 0, 3), $filter); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | protected function isClosingListItemTag($word, $type = null) |
| 241 | 241 | { |
| 242 | - $filter = $type !== null ? array('</' . $type) : array('</li', '</dd', '</dt'); |
|
| 242 | + $filter = $type !== null ? array('</'.$type) : array('</li', '</dd', '</dt'); |
|
| 243 | 243 | |
| 244 | 244 | return in_array(substr($word, 0, 4), $filter); |
| 245 | 245 | } |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | /** |
| 626 | 626 | * @param string $item |
| 627 | 627 | * |
| 628 | - * @return bool |
|
| 628 | + * @return integer |
|
| 629 | 629 | */ |
| 630 | 630 | protected function isOpeningTag($item) |
| 631 | 631 | { |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | /** |
| 636 | 636 | * @param string $item |
| 637 | 637 | * |
| 638 | - * @return bool |
|
| 638 | + * @return integer |
|
| 639 | 639 | */ |
| 640 | 640 | protected function isClosingTag($item) |
| 641 | 641 | { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | $operations = $this->operations(); |
| 99 | 99 | foreach ($operations as $item) { |
| 100 | - $this->performOperation( $item ); |
|
| 100 | + $this->performOperation($item); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | return $this->content; |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | $this->wordIndices = array(); |
| 109 | 109 | foreach ($this->newWords as $i => $word) { |
| 110 | - if ( $this->isTag( $word ) ) { |
|
| 111 | - $word = $this->stripTagAttributes( $word ); |
|
| 110 | + if ($this->isTag($word)) { |
|
| 111 | + $word = $this->stripTagAttributes($word); |
|
| 112 | 112 | } |
| 113 | - if ( isset( $this->wordIndices[ $word ] ) ) { |
|
| 114 | - $this->wordIndices[ $word ][] = $i; |
|
| 113 | + if (isset($this->wordIndices[$word])) { |
|
| 114 | + $this->wordIndices[$word][] = $i; |
|
| 115 | 115 | } else { |
| 116 | - $this->wordIndices[ $word ] = array( $i ); |
|
| 116 | + $this->wordIndices[$word] = array($i); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | } elseif ($openIsolatedDiffTags > 0 && $this->isClosingIsolatedDiffTag($word, $currentIsolatedDiffTag)) { |
| 147 | 147 | $openIsolatedDiffTags--; |
| 148 | 148 | if ($openIsolatedDiffTags == 0) { |
| 149 | - $isolatedDiffTagIndicies[] = array ('start' => $isolatedDiffTagStart, 'length' => $index - $isolatedDiffTagStart + 1, 'tagType' => $currentIsolatedDiffTag); |
|
| 149 | + $isolatedDiffTagIndicies[] = array('start' => $isolatedDiffTagStart, 'length' => $index - $isolatedDiffTagStart + 1, 'tagType' => $currentIsolatedDiffTag); |
|
| 150 | 150 | $currentIsolatedDiffTag = null; |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -211,16 +211,16 @@ discard block |
||
| 211 | 211 | { |
| 212 | 212 | switch ($operation->action) { |
| 213 | 213 | case 'equal' : |
| 214 | - $this->processEqualOperation( $operation ); |
|
| 214 | + $this->processEqualOperation($operation); |
|
| 215 | 215 | break; |
| 216 | 216 | case 'delete' : |
| 217 | - $this->processDeleteOperation( $operation, "diffdel" ); |
|
| 217 | + $this->processDeleteOperation($operation, "diffdel"); |
|
| 218 | 218 | break; |
| 219 | 219 | case 'insert' : |
| 220 | - $this->processInsertOperation( $operation, "diffins"); |
|
| 220 | + $this->processInsertOperation($operation, "diffins"); |
|
| 221 | 221 | break; |
| 222 | 222 | case 'replace': |
| 223 | - $this->processReplaceOperation( $operation ); |
|
| 223 | + $this->processReplaceOperation($operation); |
|
| 224 | 224 | break; |
| 225 | 225 | default: |
| 226 | 226 | break; |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | protected function processReplaceOperation($operation) |
| 234 | 234 | { |
| 235 | - $this->processDeleteOperation( $operation, "diffmod" ); |
|
| 236 | - $this->processInsertOperation( $operation, "diffmod" ); |
|
| 235 | + $this->processDeleteOperation($operation, "diffmod"); |
|
| 236 | + $this->processInsertOperation($operation, "diffmod"); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | - $this->insertTag( "ins", $cssClass, $text ); |
|
| 257 | + $this->insertTag("ins", $cssClass, $text); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | - $this->insertTag( "del", $cssClass, $text ); |
|
| 278 | + $this->insertTag("del", $cssClass, $text); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | |
| 329 | 329 | $diff = HtmlDiff::create($oldText, $newText, $this->config); |
| 330 | 330 | |
| 331 | - return $wrapStart . $diff->build() . $wrapEnd; |
|
| 331 | + return $wrapStart.$diff->build().$wrapEnd; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | - $this->content .= implode( "", $result ); |
|
| 399 | + $this->content .= implode("", $result); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -491,22 +491,22 @@ discard block |
||
| 491 | 491 | protected function insertTag($tag, $cssClass, &$words) |
| 492 | 492 | { |
| 493 | 493 | while (true) { |
| 494 | - if ( count( $words ) == 0 ) { |
|
| 494 | + if (count($words) == 0) { |
|
| 495 | 495 | break; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - $nonTags = $this->extractConsecutiveWords( $words, 'noTag' ); |
|
| 498 | + $nonTags = $this->extractConsecutiveWords($words, 'noTag'); |
|
| 499 | 499 | |
| 500 | 500 | $specialCaseTagInjection = ''; |
| 501 | 501 | $specialCaseTagInjectionIsBefore = false; |
| 502 | 502 | |
| 503 | - if ( count( $nonTags ) != 0 ) { |
|
| 504 | - $text = $this->wrapText( implode( "", $nonTags ), $tag, $cssClass ); |
|
| 503 | + if (count($nonTags) != 0) { |
|
| 504 | + $text = $this->wrapText(implode("", $nonTags), $tag, $cssClass); |
|
| 505 | 505 | $this->content .= $text; |
| 506 | 506 | } else { |
| 507 | 507 | $firstOrDefault = false; |
| 508 | 508 | foreach ($this->config->getSpecialCaseOpeningTags() as $x) { |
| 509 | - if ( preg_match( $x, $words[ 0 ] ) ) { |
|
| 509 | + if (preg_match($x, $words[0])) { |
|
| 510 | 510 | $firstOrDefault = $x; |
| 511 | 511 | break; |
| 512 | 512 | } |
@@ -514,32 +514,32 @@ discard block |
||
| 514 | 514 | if ($firstOrDefault) { |
| 515 | 515 | $specialCaseTagInjection = '<ins class="mod">'; |
| 516 | 516 | if ($tag == "del") { |
| 517 | - unset( $words[ 0 ] ); |
|
| 517 | + unset($words[0]); |
|
| 518 | 518 | } |
| 519 | - } elseif ( array_search( $words[ 0 ], $this->config->getSpecialCaseClosingTags()) !== false ) { |
|
| 519 | + } elseif (array_search($words[0], $this->config->getSpecialCaseClosingTags()) !== false) { |
|
| 520 | 520 | $specialCaseTagInjection = "</ins>"; |
| 521 | 521 | $specialCaseTagInjectionIsBefore = true; |
| 522 | 522 | if ($tag == "del") { |
| 523 | - unset( $words[ 0 ] ); |
|
| 523 | + unset($words[0]); |
|
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | - if ( count( $words ) == 0 && count( $specialCaseTagInjection ) == 0 ) { |
|
| 527 | + if (count($words) == 0 && count($specialCaseTagInjection) == 0) { |
|
| 528 | 528 | break; |
| 529 | 529 | } |
| 530 | 530 | if ($specialCaseTagInjectionIsBefore) { |
| 531 | - $this->content .= $specialCaseTagInjection . implode( "", $this->extractConsecutiveWords( $words, 'tag' ) ); |
|
| 531 | + $this->content .= $specialCaseTagInjection.implode("", $this->extractConsecutiveWords($words, 'tag')); |
|
| 532 | 532 | } else { |
| 533 | - $workTag = $this->extractConsecutiveWords( $words, 'tag' ); |
|
| 534 | - if ( isset( $workTag[ 0 ] ) && $this->isOpeningTag( $workTag[ 0 ] ) && !$this->isClosingTag( $workTag[ 0 ] ) ) { |
|
| 535 | - if ( strpos( $workTag[ 0 ], 'class=' ) ) { |
|
| 536 | - $workTag[ 0 ] = str_replace( 'class="', 'class="diffmod ', $workTag[ 0 ] ); |
|
| 537 | - $workTag[ 0 ] = str_replace( "class='", 'class="diffmod ', $workTag[ 0 ] ); |
|
| 533 | + $workTag = $this->extractConsecutiveWords($words, 'tag'); |
|
| 534 | + if (isset($workTag[0]) && $this->isOpeningTag($workTag[0]) && !$this->isClosingTag($workTag[0])) { |
|
| 535 | + if (strpos($workTag[0], 'class=')) { |
|
| 536 | + $workTag[0] = str_replace('class="', 'class="diffmod ', $workTag[0]); |
|
| 537 | + $workTag[0] = str_replace("class='", 'class="diffmod ', $workTag[0]); |
|
| 538 | 538 | } else { |
| 539 | - $workTag[ 0 ] = str_replace( ">", ' class="diffmod">', $workTag[ 0 ] ); |
|
| 539 | + $workTag[0] = str_replace(">", ' class="diffmod">', $workTag[0]); |
|
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | - $this->content .= implode( "", $workTag ) . $specialCaseTagInjection; |
|
| 542 | + $this->content .= implode("", $workTag).$specialCaseTagInjection; |
|
| 543 | 543 | } |
| 544 | 544 | } |
| 545 | 545 | } |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | */ |
| 553 | 553 | protected function checkCondition($word, $condition) |
| 554 | 554 | { |
| 555 | - return $condition == 'tag' ? $this->isTag( $word ) : !$this->isTag( $word ); |
|
| 555 | + return $condition == 'tag' ? $this->isTag($word) : !$this->isTag($word); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | /** |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | */ |
| 565 | 565 | protected function wrapText($text, $tagName, $cssClass) |
| 566 | 566 | { |
| 567 | - return sprintf( '<%1$s class="%2$s">%3$s</%1$s>', $tagName, $cssClass, $text ); |
|
| 567 | + return sprintf('<%1$s class="%2$s">%3$s</%1$s>', $tagName, $cssClass, $text); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | /** |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | $indexOfFirstTag = null; |
| 579 | 579 | $words = array_values($words); |
| 580 | 580 | foreach ($words as $i => $word) { |
| 581 | - if ( !$this->checkCondition( $word, $condition ) ) { |
|
| 581 | + if (!$this->checkCondition($word, $condition)) { |
|
| 582 | 582 | $indexOfFirstTag = $i; |
| 583 | 583 | break; |
| 584 | 584 | } |
@@ -591,18 +591,18 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | } |
| 593 | 593 | if ($indexOfFirstTag > 0) { |
| 594 | - array_splice( $words, 0, $indexOfFirstTag ); |
|
| 594 | + array_splice($words, 0, $indexOfFirstTag); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | return $items; |
| 598 | 598 | } else { |
| 599 | 599 | $items = array(); |
| 600 | 600 | foreach ($words as $pos => $s) { |
| 601 | - if ( $pos >= 0 && $pos <= count( $words ) ) { |
|
| 601 | + if ($pos >= 0 && $pos <= count($words)) { |
|
| 602 | 602 | $items[] = $s; |
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | - array_splice( $words, 0, count( $words ) ); |
|
| 605 | + array_splice($words, 0, count($words)); |
|
| 606 | 606 | |
| 607 | 607 | return $items; |
| 608 | 608 | } |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | */ |
| 616 | 616 | protected function isTag($item) |
| 617 | 617 | { |
| 618 | - return $this->isOpeningTag( $item ) || $this->isClosingTag( $item ); |
|
| 618 | + return $this->isOpeningTag($item) || $this->isClosingTag($item); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | */ |
| 626 | 626 | protected function isOpeningTag($item) |
| 627 | 627 | { |
| 628 | - return preg_match( "#<[^>]+>\\s*#iU", $item ); |
|
| 628 | + return preg_match("#<[^>]+>\\s*#iU", $item); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | */ |
| 636 | 636 | protected function isClosingTag($item) |
| 637 | 637 | { |
| 638 | - return preg_match( "#</[^>]+>\\s*#iU", $item ); |
|
| 638 | + return preg_match("#</[^>]+>\\s*#iU", $item); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -647,10 +647,10 @@ discard block |
||
| 647 | 647 | $positionInNew = 0; |
| 648 | 648 | $operations = array(); |
| 649 | 649 | $matches = $this->matchingBlocks(); |
| 650 | - $matches[] = new Match( count( $this->oldWords ), count( $this->newWords ), 0 ); |
|
| 650 | + $matches[] = new Match(count($this->oldWords), count($this->newWords), 0); |
|
| 651 | 651 | foreach ($matches as $i => $match) { |
| 652 | - $matchStartsAtCurrentPositionInOld = ( $positionInOld == $match->startInOld ); |
|
| 653 | - $matchStartsAtCurrentPositionInNew = ( $positionInNew == $match->startInNew ); |
|
| 652 | + $matchStartsAtCurrentPositionInOld = ($positionInOld == $match->startInOld); |
|
| 653 | + $matchStartsAtCurrentPositionInNew = ($positionInNew == $match->startInNew); |
|
| 654 | 654 | $action = 'none'; |
| 655 | 655 | |
| 656 | 656 | if ($matchStartsAtCurrentPositionInOld == false && $matchStartsAtCurrentPositionInNew == false) { |
@@ -663,10 +663,10 @@ discard block |
||
| 663 | 663 | $action = 'none'; |
| 664 | 664 | } |
| 665 | 665 | if ($action != 'none') { |
| 666 | - $operations[] = new Operation( $action, $positionInOld, $match->startInOld, $positionInNew, $match->startInNew ); |
|
| 666 | + $operations[] = new Operation($action, $positionInOld, $match->startInOld, $positionInNew, $match->startInNew); |
|
| 667 | 667 | } |
| 668 | - if ( count( $match ) != 0 ) { |
|
| 669 | - $operations[] = new Operation( 'equal', $match->startInOld, $match->endInOld(), $match->startInNew, $match->endInNew() ); |
|
| 668 | + if (count($match) != 0) { |
|
| 669 | + $operations[] = new Operation('equal', $match->startInOld, $match->endInOld(), $match->startInNew, $match->endInNew()); |
|
| 670 | 670 | } |
| 671 | 671 | $positionInOld = $match->endInOld(); |
| 672 | 672 | $positionInNew = $match->endInNew(); |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | protected function matchingBlocks() |
| 682 | 682 | { |
| 683 | 683 | $matchingBlocks = array(); |
| 684 | - $this->findMatchingBlocks( 0, count( $this->oldWords ), 0, count( $this->newWords ), $matchingBlocks ); |
|
| 684 | + $this->findMatchingBlocks(0, count($this->oldWords), 0, count($this->newWords), $matchingBlocks); |
|
| 685 | 685 | |
| 686 | 686 | return $matchingBlocks; |
| 687 | 687 | } |
@@ -695,14 +695,14 @@ discard block |
||
| 695 | 695 | */ |
| 696 | 696 | protected function findMatchingBlocks($startInOld, $endInOld, $startInNew, $endInNew, &$matchingBlocks) |
| 697 | 697 | { |
| 698 | - $match = $this->findMatch( $startInOld, $endInOld, $startInNew, $endInNew ); |
|
| 698 | + $match = $this->findMatch($startInOld, $endInOld, $startInNew, $endInNew); |
|
| 699 | 699 | if ($match !== null) { |
| 700 | 700 | if ($startInOld < $match->startInOld && $startInNew < $match->startInNew) { |
| 701 | - $this->findMatchingBlocks( $startInOld, $match->startInOld, $startInNew, $match->startInNew, $matchingBlocks ); |
|
| 701 | + $this->findMatchingBlocks($startInOld, $match->startInOld, $startInNew, $match->startInNew, $matchingBlocks); |
|
| 702 | 702 | } |
| 703 | 703 | $matchingBlocks[] = $match; |
| 704 | - if ( $match->endInOld() < $endInOld && $match->endInNew() < $endInNew ) { |
|
| 705 | - $this->findMatchingBlocks( $match->endInOld(), $endInOld, $match->endInNew(), $endInNew, $matchingBlocks ); |
|
| 704 | + if ($match->endInOld() < $endInOld && $match->endInNew() < $endInNew) { |
|
| 705 | + $this->findMatchingBlocks($match->endInOld(), $endInOld, $match->endInNew(), $endInNew, $matchingBlocks); |
|
| 706 | 706 | } |
| 707 | 707 | } |
| 708 | 708 | } |
@@ -714,9 +714,9 @@ discard block |
||
| 714 | 714 | */ |
| 715 | 715 | protected function stripTagAttributes($word) |
| 716 | 716 | { |
| 717 | - $word = explode( ' ', trim( $word, '<>' ) ); |
|
| 717 | + $word = explode(' ', trim($word, '<>')); |
|
| 718 | 718 | |
| 719 | - return '<' . $word[ 0 ] . '>'; |
|
| 719 | + return '<'.$word[0].'>'; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | /** |
@@ -735,23 +735,23 @@ discard block |
||
| 735 | 735 | $matchLengthAt = array(); |
| 736 | 736 | for ($indexInOld = $startInOld; $indexInOld < $endInOld; $indexInOld++) { |
| 737 | 737 | $newMatchLengthAt = array(); |
| 738 | - $index = $this->oldWords[ $indexInOld ]; |
|
| 739 | - if ( $this->isTag( $index ) ) { |
|
| 740 | - $index = $this->stripTagAttributes( $index ); |
|
| 738 | + $index = $this->oldWords[$indexInOld]; |
|
| 739 | + if ($this->isTag($index)) { |
|
| 740 | + $index = $this->stripTagAttributes($index); |
|
| 741 | 741 | } |
| 742 | - if ( !isset( $this->wordIndices[ $index ] ) ) { |
|
| 742 | + if (!isset($this->wordIndices[$index])) { |
|
| 743 | 743 | $matchLengthAt = $newMatchLengthAt; |
| 744 | 744 | continue; |
| 745 | 745 | } |
| 746 | - foreach ($this->wordIndices[ $index ] as $indexInNew) { |
|
| 746 | + foreach ($this->wordIndices[$index] as $indexInNew) { |
|
| 747 | 747 | if ($indexInNew < $startInNew) { |
| 748 | 748 | continue; |
| 749 | 749 | } |
| 750 | 750 | if ($indexInNew >= $endInNew) { |
| 751 | 751 | break; |
| 752 | 752 | } |
| 753 | - $newMatchLength = ( isset( $matchLengthAt[ $indexInNew - 1 ] ) ? $matchLengthAt[ $indexInNew - 1 ] : 0 ) + 1; |
|
| 754 | - $newMatchLengthAt[ $indexInNew ] = $newMatchLength; |
|
| 753 | + $newMatchLength = (isset($matchLengthAt[$indexInNew - 1]) ? $matchLengthAt[$indexInNew - 1] : 0) + 1; |
|
| 754 | + $newMatchLengthAt[$indexInNew] = $newMatchLength; |
|
| 755 | 755 | if ($newMatchLength > $bestMatchSize || |
| 756 | 756 | ( |
| 757 | 757 | $this->isGroupDiffs() && |
@@ -8,6 +8,10 @@ |
||
| 8 | 8 | public $startInNew; |
| 9 | 9 | public $size; |
| 10 | 10 | |
| 11 | + /** |
|
| 12 | + * @param integer $startInOld |
|
| 13 | + * @param integer $size |
|
| 14 | + */ |
|
| 11 | 15 | public function __construct($startInOld, $startInNew, $size) |
| 12 | 16 | { |
| 13 | 17 | $this->startInOld = $startInOld; |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | /** |
| 231 | 231 | * @param Operation $operation |
| 232 | - * @param array $oldRows |
|
| 233 | - * @param array $newRows |
|
| 232 | + * @param TableRow[] $oldRows |
|
| 233 | + * @param TableRow[] $newRows |
|
| 234 | 234 | * @param array $appliedRowSpans |
| 235 | 235 | */ |
| 236 | 236 | protected function processEqualOperation(Operation $operation, $oldRows, $newRows, &$appliedRowSpans) |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | |
| 250 | 250 | /** |
| 251 | 251 | * @param Operation $operation |
| 252 | - * @param array $oldRows |
|
| 253 | - * @param array $newRows |
|
| 252 | + * @param TableRow[] $oldRows |
|
| 253 | + * @param TableRow[] $newRows |
|
| 254 | 254 | * @param array $appliedRowSpans |
| 255 | 255 | */ |
| 256 | 256 | protected function processReplaceOperation(Operation $operation, $oldRows, $newRows, &$appliedRowSpans) |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function getColspan() |
| 44 | 44 | { |
| 45 | - return (int)$this->getAttribute('colspan') ?: 1; |
|
| 45 | + return (int) $this->getAttribute('colspan') ?: 1; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -50,6 +50,6 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function getRowspan() |
| 52 | 52 | { |
| 53 | - return (int)$this->getAttribute('rowspan') ?: 1; |
|
| 53 | + return (int) $this->getAttribute('rowspan') ?: 1; |
|
| 54 | 54 | } |
| 55 | 55 | } |
@@ -95,7 +95,7 @@ |
||
| 95 | 95 | /** |
| 96 | 96 | * @param int $matchThreshold |
| 97 | 97 | * |
| 98 | - * @return AbstractDiff |
|
| 98 | + * @return HtmlDiffConfig |
|
| 99 | 99 | */ |
| 100 | 100 | public function setMatchThreshold($matchThreshold) |
| 101 | 101 | { |
@@ -282,13 +282,13 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | protected function getStringBetween($str, $start, $end) |
| 284 | 284 | { |
| 285 | - $expStr = explode( $start, $str, 2 ); |
|
| 286 | - if ( count( $expStr ) > 1 ) { |
|
| 287 | - $expStr = explode( $end, $expStr[ 1 ] ); |
|
| 288 | - if ( count( $expStr ) > 1 ) { |
|
| 289 | - array_pop( $expStr ); |
|
| 285 | + $expStr = explode($start, $str, 2); |
|
| 286 | + if (count($expStr) > 1) { |
|
| 287 | + $expStr = explode($end, $expStr[1]); |
|
| 288 | + if (count($expStr) > 1) { |
|
| 289 | + array_pop($expStr); |
|
| 290 | 290 | |
| 291 | - return implode( $end, $expStr ); |
|
| 291 | + return implode($end, $expStr); |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | protected function purifyHtml($html) |
| 304 | 304 | { |
| 305 | - if ( class_exists( 'Tidy' ) && false ) { |
|
| 306 | - $config = array( 'output-xhtml' => true, 'indent' => false ); |
|
| 305 | + if (class_exists('Tidy') && false) { |
|
| 306 | + $config = array('output-xhtml' => true, 'indent' => false); |
|
| 307 | 307 | $tidy = new tidy(); |
| 308 | - $tidy->parseString( $html, $config, 'utf8' ); |
|
| 308 | + $tidy->parseString($html, $config, 'utf8'); |
|
| 309 | 309 | $html = (string) $tidy; |
| 310 | 310 | |
| 311 | - return $this->getStringBetween( $html, '<body>' ); |
|
| 311 | + return $this->getStringBetween($html, '<body>'); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | return $html; |
@@ -316,8 +316,8 @@ discard block |
||
| 316 | 316 | |
| 317 | 317 | protected function splitInputsToWords() |
| 318 | 318 | { |
| 319 | - $this->oldWords = $this->convertHtmlToListOfWords( $this->explode( $this->oldText ) ); |
|
| 320 | - $this->newWords = $this->convertHtmlToListOfWords( $this->explode( $this->newText ) ); |
|
| 319 | + $this->oldWords = $this->convertHtmlToListOfWords($this->explode($this->oldText)); |
|
| 320 | + $this->newWords = $this->convertHtmlToListOfWords($this->explode($this->newText)); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | foreach ($characterString as $i => $character) { |
| 344 | 344 | switch ($mode) { |
| 345 | 345 | case 'character': |
| 346 | - if ( $this->isStartOfTag( $character ) ) { |
|
| 346 | + if ($this->isStartOfTag($character)) { |
|
| 347 | 347 | if ($current_word != '') { |
| 348 | 348 | $words[] = $current_word; |
| 349 | 349 | } |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | } else { |
| 359 | 359 | if ( |
| 360 | 360 | (ctype_alnum($character) && (strlen($current_word) == 0 || $this->isPartOfWord($current_word))) || |
| 361 | - (in_array($character, $this->config->getSpecialCaseChars()) && isset($characterString[$i+1]) && $this->isPartOfWord($characterString[$i+1])) |
|
| 361 | + (in_array($character, $this->config->getSpecialCaseChars()) && isset($characterString[$i + 1]) && $this->isPartOfWord($characterString[$i + 1])) |
|
| 362 | 362 | ) { |
| 363 | 363 | $current_word .= $character; |
| 364 | 364 | } else { |
@@ -368,12 +368,12 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | break; |
| 370 | 370 | case 'tag' : |
| 371 | - if ( $this->isEndOfTag( $character ) ) { |
|
| 371 | + if ($this->isEndOfTag($character)) { |
|
| 372 | 372 | $current_word .= ">"; |
| 373 | 373 | $words[] = $current_word; |
| 374 | 374 | $current_word = ""; |
| 375 | 375 | |
| 376 | - if ( !preg_match('[^\s]', $character ) ) { |
|
| 376 | + if (!preg_match('[^\s]', $character)) { |
|
| 377 | 377 | $mode = 'whitespace'; |
| 378 | 378 | } else { |
| 379 | 379 | $mode = 'character'; |
@@ -383,13 +383,13 @@ discard block |
||
| 383 | 383 | } |
| 384 | 384 | break; |
| 385 | 385 | case 'whitespace': |
| 386 | - if ( $this->isStartOfTag( $character ) ) { |
|
| 386 | + if ($this->isStartOfTag($character)) { |
|
| 387 | 387 | if ($current_word !== '') { |
| 388 | 388 | $words[] = $current_word; |
| 389 | 389 | } |
| 390 | 390 | $current_word = "<"; |
| 391 | 391 | $mode = 'tag'; |
| 392 | - } elseif ( preg_match( "/\s/", $character ) ) { |
|
| 392 | + } elseif (preg_match("/\s/", $character)) { |
|
| 393 | 393 | $current_word .= $character; |
| 394 | 394 | $current_word = preg_replace('/\s+/S', ' ', $current_word); |
| 395 | 395 | } else { |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | */ |
| 439 | 439 | protected function isWhiteSpace($value) |
| 440 | 440 | { |
| 441 | - return !preg_match( '[^\s]', $value ); |
|
| 441 | + return !preg_match('[^\s]', $value); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | /** |
@@ -449,6 +449,6 @@ discard block |
||
| 449 | 449 | protected function explode($value) |
| 450 | 450 | { |
| 451 | 451 | // as suggested by @onassar |
| 452 | - return preg_split( '//u', $value ); |
|
| 452 | + return preg_split('//u', $value); |
|
| 453 | 453 | } |
| 454 | 454 | } |