22
33namespace Caxy \HtmlDiff ;
44
5- error_reporting (E_ALL );
6-
75class ListDiff extends HtmlDiff
86{
97 /**
@@ -40,8 +38,16 @@ class ListDiff extends HtmlDiff
4038 */
4139 protected $ listType ;
4240
41+ /**
42+ * Used to hold what type of list the old list is.
43+ * @var string
44+ */
4345 protected $ oldListType ;
4446
47+ /**
48+ * Used to hold what type of list the new list is.
49+ * @var string
50+ */
4551 protected $ newListType ;
4652
4753 /**
@@ -68,10 +74,16 @@ class ListDiff extends HtmlDiff
6874 */
6975 protected $ listsIndex ;
7076
77+ /**
78+ * Array that holds the index of all content outside of the array. Format is array(index => content).
79+ * @var array
80+ */
7181 protected $ contentIndex = array ();
7282
73- protected $ contentMatches = array ();
74-
83+ /**
84+ * Holds the order and data on each list/content block within this list.
85+ * @var array
86+ */
7587 protected $ diffOrderIndex = array ();
7688
7789 /**
@@ -124,6 +136,9 @@ protected function diffListContent()
124136 $ this ->diff ();
125137 }
126138
139+ /**
140+ * This function is used to populate both contentIndex and diffOrderIndex arrays for use in the diff function.
141+ */
127142 protected function indexContent ()
128143 {
129144 $ this ->contentIndex = array ();
@@ -262,12 +277,23 @@ protected function matchAndCompareLists()
262277 */
263278 $ this ->compareChildLists ();
264279 }
265-
280+
281+ /**
282+ * Creates matches for lists.
283+ */
266284 protected function compareChildLists ()
267285 {
268286 $ this ->createNewOldMatches ($ this ->childLists , $ this ->textMatches , 'content ' );
269287 }
270288
289+ /**
290+ * Abstracted function used to match items in an array.
291+ * This is used primarily for populating lists matches.
292+ *
293+ * @param array $listArray
294+ * @param array $resultArray
295+ * @param string|null $column
296+ */
271297 protected function createNewOldMatches (&$ listArray , &$ resultArray , $ column = null )
272298 {
273299 // Always compare the new against the old.
@@ -408,8 +434,6 @@ protected function buildChildLists()
408434 */
409435 protected function diff ()
410436 {
411- //$this->dump($this->diffOrderIndex, "diff order index");
412- //$this->dump($this->list, "list");
413437 // Add the opening parent node from listType. So if ol, <ol>, etc.
414438 $ this ->content = $ this ->addListTypeWrapper ();
415439
@@ -459,25 +483,15 @@ protected function diff()
459483 $ this ->content .= $ this ->addListTypeWrapper (false );
460484 }
461485
462- protected function dump ($ asset , $ string = '' )
463- {
464- ini_set ('xdebug.var_display_max_depth ' , 5 );
465- ini_set ('xdebug.var_display_max_children ' , 2000 );
466- ini_set ('xdebug.var_display_max_data ' , 1024 );
467-
468- if ($ string ) {
469- $ trueString = "======================= " . $ string ;
470- var_dump (strtoupper ($ trueString ));
471- }
472-
473- var_dump ($ asset );
474-
475- if (isset ($ trueString )) {
476- $ trueString .= " ========= END END END " ;
477- var_dump (strtoupper ($ trueString ));
478- }
479- }
480-
486+ /**
487+ * This function replaces array_column function in PHP for older versions of php.
488+ *
489+ * @param array $parentArray
490+ * @param string $column
491+ * @param mixed $value
492+ * @param boolean $allMatches
493+ * @return array|boolean
494+ */
481495 protected function getArrayByColumnValue ($ parentArray , $ column , $ value , $ allMatches = false )
482496 {
483497 $ returnArray = array ();
@@ -493,41 +507,6 @@ protected function getArrayByColumnValue($parentArray, $column, $value, $allMatc
493507
494508 return $ allMatches ? $ returnArray : false ;
495509 }
496-
497- protected function diffThisList ($ word , $ key )
498- {
499- $ listIndexValue = $ this ->getListIndexValue ($ key );
500- $ newList = $ this ->childLists ['new ' ][$ listIndexValue ];
501-
502- $ textMatchKey = $ this ->getTextMatchKey ($ listIndexValue );
503- $ oldList = $ this ->childLists ['old ' ][$ this ->textMatches [$ textMatchKey ]['old ' ]];
504-
505- return $ this ->processPlaceholders (
506- $ this ->diffElements (
507- $ this ->convertListContentArrayToString ($ oldList ),
508- $ this ->convertListContentArrayToString ($ newList ),
509- false
510- ),
511- $ this ->textMatches [$ textMatchKey ]
512- );
513- }
514-
515- protected function getListIndexValue ($ key , $ type = 'new ' )
516- {
517- return array_search ($ key , $ this ->listsIndex [$ type ]);
518- }
519-
520- protected function getTextMatchKey ($ listIndexValue , $ type = 'new ' )
521- {
522- return array_search ($ listIndexValue , array_column ($ this ->textMatches , $ type ));
523- }
524-
525- protected function getListByMatchKey ($ textMatchKey , $ type = 'old ' )
526- {
527- return array_key_exists ($ textMatchKey , $ this ->textMatches )
528- ? $ this ->childLists [$ type ][$ this ->textMatches [$ textMatchKey ][$ type ]]
529- : '' ;
530- }
531510
532511 /**
533512 * Converts the list (li) content arrays to string.
0 commit comments