Passed
Push — master ( 65b179...c12483 )
by Josh
01:08
created
lib/Caxy/HtmlDiff/HtmlDiff.php 2 patches
Doc Comments   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -387,6 +387,12 @@  discard block
 block discarded – undo
387 387
         return $diff->build();
388 388
     }
389 389
 
390
+    /**
391
+     * @param string $oldText
392
+     * @param string $newText
393
+     * @param string $attribute
394
+     * @param string $element
395
+     */
390 396
     protected function diffElementsByAttribute($oldText, $newText, $attribute, $element)
391 397
     {
392 398
         $oldAttribute = $this->getAttributeFromTag($oldText, $attribute);
@@ -662,7 +668,7 @@  discard block
 block discarded – undo
662 668
     /**
663 669
      * @param string $item
664 670
      *
665
-     * @return bool
671
+     * @return integer
666 672
      */
667 673
     protected function isOpeningTag($item)
668 674
     {
@@ -672,7 +678,7 @@  discard block
 block discarded – undo
672 678
     /**
673 679
      * @param string $item
674 680
      *
675
-     * @return bool
681
+     * @return integer
676 682
      */
677 683
     protected function isClosingTag($item)
678 684
     {
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
         $operations = $this->operations();
105 105
         foreach ($operations as $item) {
106
-            $this->performOperation( $item );
106
+            $this->performOperation($item);
107 107
         }
108 108
 
109 109
         if ($this->hasDiffCache()) {
@@ -117,13 +117,13 @@  discard block
 block discarded – undo
117 117
     {
118 118
         $this->wordIndices = array();
119 119
         foreach ($this->newWords as $i => $word) {
120
-            if ( $this->isTag( $word ) ) {
121
-                $word = $this->stripTagAttributes( $word );
120
+            if ($this->isTag($word)) {
121
+                $word = $this->stripTagAttributes($word);
122 122
             }
123
-            if ( isset( $this->wordIndices[ $word ] ) ) {
124
-                $this->wordIndices[ $word ][] = $i;
123
+            if (isset($this->wordIndices[$word])) {
124
+                $this->wordIndices[$word][] = $i;
125 125
             } else {
126
-                $this->wordIndices[ $word ] = array( $i );
126
+                $this->wordIndices[$word] = array($i);
127 127
             }
128 128
         }
129 129
     }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
             } elseif ($openIsolatedDiffTags > 0 && $this->isClosingIsolatedDiffTag($word, $currentIsolatedDiffTag)) {
168 168
                 $openIsolatedDiffTags--;
169 169
                 if ($openIsolatedDiffTags == 0) {
170
-                    $isolatedDiffTagIndices[] = array ('start' => $isolatedDiffTagStart, 'length' => $index - $isolatedDiffTagStart + 1, 'tagType' => $currentIsolatedDiffTag);
170
+                    $isolatedDiffTagIndices[] = array('start' => $isolatedDiffTagStart, 'length' => $index - $isolatedDiffTagStart + 1, 'tagType' => $currentIsolatedDiffTag);
171 171
                     $currentIsolatedDiffTag = null;
172 172
                 }
173 173
             }
@@ -239,16 +239,16 @@  discard block
 block discarded – undo
239 239
     {
240 240
         switch ($operation->action) {
241 241
             case 'equal' :
242
-            $this->processEqualOperation( $operation );
242
+            $this->processEqualOperation($operation);
243 243
             break;
244 244
             case 'delete' :
245
-            $this->processDeleteOperation( $operation, "diffdel" );
245
+            $this->processDeleteOperation($operation, "diffdel");
246 246
             break;
247 247
             case 'insert' :
248
-            $this->processInsertOperation( $operation, "diffins");
248
+            $this->processInsertOperation($operation, "diffins");
249 249
             break;
250 250
             case 'replace':
251
-            $this->processReplaceOperation( $operation );
251
+            $this->processReplaceOperation($operation);
252 252
             break;
253 253
             default:
254 254
             break;
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
      */
261 261
     protected function processReplaceOperation($operation)
262 262
     {
263
-        $this->processDeleteOperation( $operation, "diffmod" );
264
-        $this->processInsertOperation( $operation, "diffmod" );
263
+        $this->processDeleteOperation($operation, "diffmod");
264
+        $this->processInsertOperation($operation, "diffmod");
265 265
     }
266 266
 
267 267
     /**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                 }
283 283
             }
284 284
         }
285
-        $this->insertTag( "ins", $cssClass, $text );
285
+        $this->insertTag("ins", $cssClass, $text);
286 286
     }
287 287
 
288 288
     /**
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
                 }
304 304
             }
305 305
         }
306
-        $this->insertTag( "del", $cssClass, $text );
306
+        $this->insertTag("del", $cssClass, $text);
307 307
     }
308 308
 
309 309
     /**
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 
359 359
         $diff = HtmlDiff::create($oldText, $newText, $this->config);
360 360
 
361
-        return $wrapStart . $diff->build() . $wrapEnd;
361
+        return $wrapStart.$diff->build().$wrapEnd;
362 362
     }
363 363
 
364 364
     /**
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
                 }
423 423
             }
424 424
         }
425
-        $this->content .= implode( "", $result );
425
+        $this->content .= implode("", $result);
426 426
     }
427 427
 
428 428
     /**
@@ -527,22 +527,22 @@  discard block
 block discarded – undo
527 527
     protected function insertTag($tag, $cssClass, &$words)
528 528
     {
529 529
         while (true) {
530
-            if ( count( $words ) == 0 ) {
530
+            if (count($words) == 0) {
531 531
                 break;
532 532
             }
533 533
 
534
-            $nonTags = $this->extractConsecutiveWords( $words, 'noTag' );
534
+            $nonTags = $this->extractConsecutiveWords($words, 'noTag');
535 535
 
536 536
             $specialCaseTagInjection = '';
537 537
             $specialCaseTagInjectionIsBefore = false;
538 538
 
539
-            if ( count( $nonTags ) != 0 ) {
540
-                $text = $this->wrapText( implode( "", $nonTags ), $tag, $cssClass );
539
+            if (count($nonTags) != 0) {
540
+                $text = $this->wrapText(implode("", $nonTags), $tag, $cssClass);
541 541
                 $this->content .= $text;
542 542
             } else {
543 543
                 $firstOrDefault = false;
544 544
                 foreach ($this->config->getSpecialCaseOpeningTags() as $x) {
545
-                    if ( preg_match( $x, $words[ 0 ] ) ) {
545
+                    if (preg_match($x, $words[0])) {
546 546
                         $firstOrDefault = $x;
547 547
                         break;
548 548
                     }
@@ -550,33 +550,33 @@  discard block
 block discarded – undo
550 550
                 if ($firstOrDefault) {
551 551
                     $specialCaseTagInjection = '<ins class="mod">';
552 552
                     if ($tag == "del") {
553
-                        unset( $words[ 0 ] );
553
+                        unset($words[0]);
554 554
                     }
555
-                } elseif ( array_search( $words[ 0 ], $this->config->getSpecialCaseClosingTags()) !== false ) {
555
+                } elseif (array_search($words[0], $this->config->getSpecialCaseClosingTags()) !== false) {
556 556
                     $specialCaseTagInjection = "</ins>";
557 557
                     $specialCaseTagInjectionIsBefore = true;
558 558
                     if ($tag == "del") {
559
-                        unset( $words[ 0 ] );
559
+                        unset($words[0]);
560 560
                     }
561 561
                 }
562 562
             }
563
-            if ( count( $words ) == 0 && count( $specialCaseTagInjection ) == 0 ) {
563
+            if (count($words) == 0 && count($specialCaseTagInjection) == 0) {
564 564
                 break;
565 565
             }
566 566
             if ($specialCaseTagInjectionIsBefore) {
567
-                $this->content .= $specialCaseTagInjection . implode( "", $this->extractConsecutiveWords( $words, 'tag' ) );
567
+                $this->content .= $specialCaseTagInjection.implode("", $this->extractConsecutiveWords($words, 'tag'));
568 568
             } else {
569
-                $workTag = $this->extractConsecutiveWords( $words, 'tag' );
570
-                if ( isset( $workTag[ 0 ] ) && $this->isOpeningTag( $workTag[ 0 ] ) && !$this->isClosingTag( $workTag[ 0 ] ) ) {
571
-                    if ( strpos( $workTag[ 0 ], 'class=' ) ) {
572
-                        $workTag[ 0 ] = str_replace( 'class="', 'class="diffmod ', $workTag[ 0 ] );
573
-                        $workTag[ 0 ] = str_replace( "class='", 'class="diffmod ', $workTag[ 0 ] );
569
+                $workTag = $this->extractConsecutiveWords($words, 'tag');
570
+                if (isset($workTag[0]) && $this->isOpeningTag($workTag[0]) && !$this->isClosingTag($workTag[0])) {
571
+                    if (strpos($workTag[0], 'class=')) {
572
+                        $workTag[0] = str_replace('class="', 'class="diffmod ', $workTag[0]);
573
+                        $workTag[0] = str_replace("class='", 'class="diffmod ', $workTag[0]);
574 574
                     } else {
575
-                        $workTag[ 0 ] = str_replace( ">", ' class="diffmod">', $workTag[ 0 ] );
575
+                        $workTag[0] = str_replace(">", ' class="diffmod">', $workTag[0]);
576 576
                     }
577 577
                 }
578 578
 
579
-                $appendContent = implode( "", $workTag ) . $specialCaseTagInjection;
579
+                $appendContent = implode("", $workTag).$specialCaseTagInjection;
580 580
                 if (isset($workTag[0]) && false !== stripos($workTag[0], '<img')) {
581 581
                     $appendContent = $this->wrapText($appendContent, $tag, $cssClass);
582 582
                 }
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
      */
594 594
     protected function checkCondition($word, $condition)
595 595
     {
596
-        return $condition == 'tag' ? $this->isTag( $word ) : !$this->isTag( $word );
596
+        return $condition == 'tag' ? $this->isTag($word) : !$this->isTag($word);
597 597
     }
598 598
 
599 599
     /**
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
      */
606 606
     protected function wrapText($text, $tagName, $cssClass)
607 607
     {
608
-        return sprintf( '<%1$s class="%2$s">%3$s</%1$s>', $tagName, $cssClass, $text );
608
+        return sprintf('<%1$s class="%2$s">%3$s</%1$s>', $tagName, $cssClass, $text);
609 609
     }
610 610
 
611 611
     /**
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
         $indexOfFirstTag = null;
620 620
         $words = array_values($words);
621 621
         foreach ($words as $i => $word) {
622
-            if ( !$this->checkCondition( $word, $condition ) ) {
622
+            if (!$this->checkCondition($word, $condition)) {
623 623
                 $indexOfFirstTag = $i;
624 624
                 break;
625 625
             }
@@ -632,18 +632,18 @@  discard block
 block discarded – undo
632 632
                 }
633 633
             }
634 634
             if ($indexOfFirstTag > 0) {
635
-                array_splice( $words, 0, $indexOfFirstTag );
635
+                array_splice($words, 0, $indexOfFirstTag);
636 636
             }
637 637
 
638 638
             return $items;
639 639
         } else {
640 640
             $items = array();
641 641
             foreach ($words as $pos => $s) {
642
-                if ( $pos >= 0 && $pos <= count( $words ) ) {
642
+                if ($pos >= 0 && $pos <= count($words)) {
643 643
                     $items[] = $s;
644 644
                 }
645 645
             }
646
-            array_splice( $words, 0, count( $words ) );
646
+            array_splice($words, 0, count($words));
647 647
 
648 648
             return $items;
649 649
         }
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
      */
657 657
     protected function isTag($item)
658 658
     {
659
-        return $this->isOpeningTag( $item ) || $this->isClosingTag( $item );
659
+        return $this->isOpeningTag($item) || $this->isClosingTag($item);
660 660
     }
661 661
 
662 662
     /**
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
      */
667 667
     protected function isOpeningTag($item)
668 668
     {
669
-        return preg_match( "#<[^>]+>\\s*#iU", $item );
669
+        return preg_match("#<[^>]+>\\s*#iU", $item);
670 670
     }
671 671
 
672 672
     /**
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
      */
677 677
     protected function isClosingTag($item)
678 678
     {
679
-        return preg_match( "#</[^>]+>\\s*#iU", $item );
679
+        return preg_match("#</[^>]+>\\s*#iU", $item);
680 680
     }
681 681
 
682 682
     /**
@@ -688,10 +688,10 @@  discard block
 block discarded – undo
688 688
         $positionInNew = 0;
689 689
         $operations = array();
690 690
         $matches = $this->matchingBlocks();
691
-        $matches[] = new Match( count( $this->oldWords ), count( $this->newWords ), 0 );
691
+        $matches[] = new Match(count($this->oldWords), count($this->newWords), 0);
692 692
         foreach ($matches as $i => $match) {
693
-            $matchStartsAtCurrentPositionInOld = ( $positionInOld == $match->startInOld );
694
-            $matchStartsAtCurrentPositionInNew = ( $positionInNew == $match->startInNew );
693
+            $matchStartsAtCurrentPositionInOld = ($positionInOld == $match->startInOld);
694
+            $matchStartsAtCurrentPositionInNew = ($positionInNew == $match->startInNew);
695 695
             $action = 'none';
696 696
 
697 697
             if ($matchStartsAtCurrentPositionInOld == false && $matchStartsAtCurrentPositionInNew == false) {
@@ -704,10 +704,10 @@  discard block
 block discarded – undo
704 704
                 $action = 'none';
705 705
             }
706 706
             if ($action != 'none') {
707
-                $operations[] = new Operation( $action, $positionInOld, $match->startInOld, $positionInNew, $match->startInNew );
707
+                $operations[] = new Operation($action, $positionInOld, $match->startInOld, $positionInNew, $match->startInNew);
708 708
             }
709
-            if ( count( $match ) != 0 ) {
710
-                $operations[] = new Operation( 'equal', $match->startInOld, $match->endInOld(), $match->startInNew, $match->endInNew() );
709
+            if (count($match) != 0) {
710
+                $operations[] = new Operation('equal', $match->startInOld, $match->endInOld(), $match->startInNew, $match->endInNew());
711 711
             }
712 712
             $positionInOld = $match->endInOld();
713 713
             $positionInNew = $match->endInNew();
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
     protected function matchingBlocks()
723 723
     {
724 724
         $matchingBlocks = array();
725
-        $this->findMatchingBlocks( 0, count( $this->oldWords ), 0, count( $this->newWords ), $matchingBlocks );
725
+        $this->findMatchingBlocks(0, count($this->oldWords), 0, count($this->newWords), $matchingBlocks);
726 726
 
727 727
         return $matchingBlocks;
728 728
     }
@@ -736,14 +736,14 @@  discard block
 block discarded – undo
736 736
      */
737 737
     protected function findMatchingBlocks($startInOld, $endInOld, $startInNew, $endInNew, &$matchingBlocks)
738 738
     {
739
-        $match = $this->findMatch( $startInOld, $endInOld, $startInNew, $endInNew );
739
+        $match = $this->findMatch($startInOld, $endInOld, $startInNew, $endInNew);
740 740
         if ($match !== null) {
741 741
             if ($startInOld < $match->startInOld && $startInNew < $match->startInNew) {
742
-                $this->findMatchingBlocks( $startInOld, $match->startInOld, $startInNew, $match->startInNew, $matchingBlocks );
742
+                $this->findMatchingBlocks($startInOld, $match->startInOld, $startInNew, $match->startInNew, $matchingBlocks);
743 743
             }
744 744
             $matchingBlocks[] = $match;
745
-            if ( $match->endInOld() < $endInOld && $match->endInNew() < $endInNew ) {
746
-                $this->findMatchingBlocks( $match->endInOld(), $endInOld, $match->endInNew(), $endInNew, $matchingBlocks );
745
+            if ($match->endInOld() < $endInOld && $match->endInNew() < $endInNew) {
746
+                $this->findMatchingBlocks($match->endInOld(), $endInOld, $match->endInNew(), $endInNew, $matchingBlocks);
747 747
             }
748 748
         }
749 749
     }
@@ -755,9 +755,9 @@  discard block
 block discarded – undo
755 755
      */
756 756
     protected function stripTagAttributes($word)
757 757
     {
758
-        $word = explode( ' ', trim( $word, '<>' ) );
758
+        $word = explode(' ', trim($word, '<>'));
759 759
 
760
-        return '<' . $word[ 0 ] . '>';
760
+        return '<'.$word[0].'>';
761 761
     }
762 762
 
763 763
     /**
@@ -776,23 +776,23 @@  discard block
 block discarded – undo
776 776
         $matchLengthAt = array();
777 777
         for ($indexInOld = $startInOld; $indexInOld < $endInOld; $indexInOld++) {
778 778
             $newMatchLengthAt = array();
779
-            $index = $this->oldWords[ $indexInOld ];
780
-            if ( $this->isTag( $index ) ) {
781
-                $index = $this->stripTagAttributes( $index );
779
+            $index = $this->oldWords[$indexInOld];
780
+            if ($this->isTag($index)) {
781
+                $index = $this->stripTagAttributes($index);
782 782
             }
783
-            if ( !isset( $this->wordIndices[ $index ] ) ) {
783
+            if (!isset($this->wordIndices[$index])) {
784 784
                 $matchLengthAt = $newMatchLengthAt;
785 785
                 continue;
786 786
             }
787
-            foreach ($this->wordIndices[ $index ] as $indexInNew) {
787
+            foreach ($this->wordIndices[$index] as $indexInNew) {
788 788
                 if ($indexInNew < $startInNew) {
789 789
                     continue;
790 790
                 }
791 791
                 if ($indexInNew >= $endInNew) {
792 792
                     break;
793 793
                 }
794
-                $newMatchLength = ( isset( $matchLengthAt[ $indexInNew - 1 ] ) ? $matchLengthAt[ $indexInNew - 1 ] : 0 ) + 1;
795
-                $newMatchLengthAt[ $indexInNew ] = $newMatchLength;
794
+                $newMatchLength = (isset($matchLengthAt[$indexInNew - 1]) ? $matchLengthAt[$indexInNew - 1] : 0) + 1;
795
+                $newMatchLengthAt[$indexInNew] = $newMatchLength;
796 796
                 if ($newMatchLength > $bestMatchSize ||
797 797
                     (
798 798
                         $this->isGroupDiffs() &&
Please login to merge, or discard this patch.