44
55class ListDiff extends HtmlDiff
66{
7+ /** @var array */
78 protected $ listWords = array ();
9+
10+ /** @var array */
811 protected $ listTags = array ();
12+
13+ /** @var array */
914 protected $ listIsolatedDiffTags = array ();
15+
16+ /** @var array */
1017 protected $ isolatedDiffTags = array (
1118 'ol ' => '[[REPLACE_ORDERED_LIST]] ' ,
1219 'ul ' => '[[REPLACE_UNORDERED_LIST]] ' ,
1320 'dl ' => '[[REPLACE_DEFINITION_LIST]] ' ,
1421 );
22+
23+ /**
24+ * List (li) placeholder.
25+ * @var string
26+ */
1527 protected static $ listPlaceHolder = "[[REPLACE_LIST_ITEM]] " ;
16- protected $ listType ; // holds the type of list this is ol, ul, dl
17- protected $ list ; // hold the old/new content of the content of the list
18- protected $ childLists ; // contains the old/new child lists content within this list
19- protected $ textMatches ; // contains the old/new text strings that match
20- protected $ listsIndex ; // contains the indexed start positions of each list within word string.
28+
29+ /**
30+ * Holds the type of list this is ol, ul, dl.
31+ * @var string
32+ */
33+ protected $ listType ;
34+
35+ /**
36+ * Hold the old/new content of the content of the list.
37+ * @var array
38+ */
39+ protected $ list ;
40+
41+ /**
42+ * Contains the old/new child lists content within this list.
43+ * @var array
44+ */
45+ protected $ childLists ;
46+
47+ /**
48+ * Contains the old/new text strings that match
49+ * @var array
50+ */
51+ protected $ textMatches ;
52+
53+ /**
54+ * Contains the indexed start positions of each list within word string.
55+ * @var array
56+ */
57+ protected $ listsIndex ;
2158
2259 /**
2360 * We're using the same functions as the parent in build() to get us to the point of
@@ -87,6 +124,10 @@ protected function formatThisListContent()
87124 }
88125 }
89126
127+ /**
128+ * @param string $tag
129+ * @return string
130+ */
90131 protected function getAndStripTag ($ tag )
91132 {
92133 $ content = explode (' ' , preg_replace ("/[^A-Za-z0-9 ]/ " , '' , $ tag ));
@@ -250,6 +291,12 @@ protected function diff()
250291 $ this ->content .= $ this ->addListTypeWrapper (false );
251292 }
252293
294+ /**
295+ * Converts the list (li) content arrays to string.
296+ *
297+ * @param array $listContentArray
298+ * @return string
299+ */
253300 protected function convertListContentArrayToString ($ listContentArray )
254301 {
255302 if (!is_array ($ listContentArray )) {
@@ -278,6 +325,10 @@ protected function convertListContentArrayToString($listContentArray)
278325 /**
279326 * Return the contents of each list node.
280327 * Process any placeholders for nested lists.
328+ *
329+ * @param string $text
330+ * @param array $matches
331+ * @return string
281332 */
282333 protected function processPlaceholders ($ text , array $ matches )
283334 {
@@ -313,6 +364,12 @@ protected function processPlaceholders($text, array $matches)
313364 return implode (' ' , $ returnText );
314365 }
315366
367+ /**
368+ * Checks to see if a diff tag is in string.
369+ *
370+ * @param string $word
371+ * @return string
372+ */
316373 protected function checkWordForDiffTag ($ word )
317374 {
318375 foreach ($ this ->isolatedDiffTags as $ diffTag ) {
@@ -334,6 +391,9 @@ protected function checkWordForDiffTag($word)
334391
335392 /**
336393 * Used to remove new lines.
394+ *
395+ * @param string $text
396+ * @return string
337397 */
338398 protected function stripNewLine ($ text )
339399 {
@@ -342,6 +402,10 @@ protected function stripNewLine($text)
342402
343403 /**
344404 * Grab the list content using the listsIndex array.
405+ *
406+ * @param string $indexKey
407+ * @param array $matches
408+ * @return array
345409 */
346410 protected function getListContent ($ indexKey = 'new ' , array $ matches )
347411 {
@@ -360,7 +424,14 @@ protected function getListContent($indexKey = 'new', array $matches)
360424 return $ bucket ;
361425 }
362426
363- protected function findEndForIndex ($ index , $ start )
427+ /**
428+ * Finds the end of list within its index.
429+ *
430+ * @param array $index
431+ * @param integer $start
432+ * @return integer
433+ */
434+ protected function findEndForIndex (array $ index , $ start )
364435 {
365436 $ array = array_splice ($ index , $ start );
366437 $ count = 0 ;
@@ -410,6 +481,9 @@ protected function indexLists()
410481
411482 /**
412483 * Adds the opening or closing list html element, based on listType.
484+ *
485+ * @param boolean $opening
486+ * @return string
413487 */
414488 protected function addListTypeWrapper ($ opening = true )
415489 {
@@ -427,6 +501,10 @@ public function replaceListIsolatedDiffTags()
427501
428502 /**
429503 * Grab the contents of a list node.
504+ *
505+ * @param array $contentArray
506+ * @param boolean $stripTags
507+ * @return array
430508 */
431509 protected function getListsContent (array $ contentArray , $ stripTags = true )
432510 {
@@ -458,7 +536,19 @@ protected function getListsContent(array $contentArray, $stripTags = true)
458536 return $ lematches ;
459537 }
460538
461- protected function addStringToArrayByDepth ($ word , &$ array , $ targetDepth , $ thisDepth , $ nestedCount )
539+ /**
540+ * This function helps build the list content array of a list.
541+ * If a list has another list within it, the inner list is replaced with the list placeholder and the inner list
542+ * content becomes a child of the parent list.
543+ * This goes recursively down.
544+ *
545+ * @param string $word
546+ * @param array $array
547+ * @param integer $targetDepth
548+ * @param integer $thisDepth
549+ * @param array $nestedCount
550+ */
551+ protected function addStringToArrayByDepth ($ word , array &$ array , $ targetDepth , $ thisDepth , array $ nestedCount )
462552 {
463553 // determine what depth we're at
464554 if ($ targetDepth == $ thisDepth ) {
@@ -500,6 +590,7 @@ protected function addStringToArrayByDepth($word, &$array, $targetDepth, $thisDe
500590 );
501591
502592 } else {
593+
503594 if ($ nestedCount [$ targetDepth ] > count ($ array [count ($ array ) - 1 ]['kids ' ])) {
504595 $ array [count ($ array ) - 1 ]['kids ' ][] = $ newArray ;
505596 $ array [count ($ array ) - 1 ]['content ' ] .= self ::$ listPlaceHolder ;
@@ -520,6 +611,12 @@ protected function addStringToArrayByDepth($word, &$array, $targetDepth, $thisDe
520611 }
521612 }
522613
614+ /**
615+ * Checks if text is opening list tag.
616+ *
617+ * @param string $item
618+ * @return boolean
619+ */
523620 protected function isOpeningListTag ($ item )
524621 {
525622 if (preg_match ("#<li[^>]*> \\s*#iU " , $ item )) {
@@ -528,7 +625,13 @@ protected function isOpeningListTag($item)
528625
529626 return false ;
530627 }
531-
628+
629+ /**
630+ * Check if text is closing list tag.
631+ *
632+ * @param string $item
633+ * @return boolean
634+ */
532635 protected function isClosingListTag ($ item )
533636 {
534637 if (preg_match ("#</li[^>]*> \\s*#iU " , $ item )) {
0 commit comments