Completed
Pull Request — master (#141)
by Bhanu
37:51 queued 34s
created
phpdocumentor/reflection-docblock/src/phpDocumentor/Reflection/DocBlock.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -271,7 +271,6 @@
 block discarded – undo
271 271
      * Sets the text portion (short and long description combined) of the doc
272 272
      * block.
273 273
      *
274
-     * @param string $docblock The new text portion of the doc block.
275 274
      * 
276 275
      * @return $this This doc block.
277 276
      */
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -225,14 +225,14 @@
 block discarded – undo
225 225
             if ('@' !== $tags[0]) {
226 226
                 throw new \LogicException(
227 227
                     'A tag block started with text instead of an actual tag,'
228
-                    . ' this makes the tag block invalid: ' . $tags
228
+                    . ' this makes the tag block invalid: '.$tags
229 229
                 );
230 230
             }
231 231
             foreach (explode("\n", $tags) as $tag_line) {
232 232
                 if (isset($tag_line[0]) && ($tag_line[0] === '@')) {
233 233
                     $result[] = $tag_line;
234 234
                 } else {
235
-                    $result[count($result) - 1] .= "\n" . $tag_line;
235
+                    $result[count($result) - 1] .= "\n".$tag_line;
236 236
                 }
237 237
             }
238 238
 
Please login to merge, or discard this patch.
reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Location.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
 
45 45
     /**
46 46
      * 
47
-     * @param type $lineNumber
47
+     * @param integer $lineNumber
48 48
      * @return $this
49 49
      */
50 50
     public function setLineNumber($lineNumber)
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function setLineNumber($lineNumber)
51 51
     {
52
-        $this->lineNumber = (int)$lineNumber;
52
+        $this->lineNumber = (int) $lineNumber;
53 53
 
54 54
         return $this;
55 55
     }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function setColumnNumber($columnNumber)
71 71
     {
72
-        $this->columnNumber = (int)$columnNumber;
72
+        $this->columnNumber = (int) $columnNumber;
73 73
 
74 74
         return $this;
75 75
     }
Please login to merge, or discard this patch.
reflection-docblock/src/phpDocumentor/Reflection/DocBlock/Serializer.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     /**
62 62
      * Sets the string to indent comments with.
63 63
      * 
64
-     * @param string $indentationString The string to indent comments with.
64
+     * @param string $indentString The string to indent comments with.
65 65
      * 
66 66
      * @return $this This serializer object.
67 67
      */
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
     /**
162 162
      * Generate a DocBlock comment.
163 163
      *
164
-     * @param DocBlock The DocBlock to serialize.
164
+     * @param DocBlock  DocBlock to serialize.
165 165
      * 
166 166
      * @return string The serialized doc block.
167 167
      */
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      */
68 68
     public function setIndentationString($indentString)
69 69
     {
70
-        $this->indentString = (string)$indentString;
70
+        $this->indentString = (string) $indentString;
71 71
         return $this;
72 72
     }
73 73
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function setIndent($indent)
92 92
     {
93
-        $this->indent = (int)$indent;
93
+        $this->indent = (int) $indent;
94 94
         return $this;
95 95
     }
96 96
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function setIsFirstLineIndented($indentFirstLine)
118 118
     {
119
-        $this->isFirstLineIndented = (bool)$indentFirstLine;
119
+        $this->isFirstLineIndented = (bool) $indentFirstLine;
120 120
         return $this;
121 121
     }
122 122
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function setLineLength($lineLength)
145 145
     {
146
-        $this->lineLength = null === $lineLength ? null : (int)$lineLength;
146
+        $this->lineLength = null === $lineLength ? null : (int) $lineLength;
147 147
         return $this;
148 148
     }
149 149
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             $comment .= "{$indent} * {$tagText}\n";
192 192
         }
193 193
 
194
-        $comment .= $indent . ' */';
194
+        $comment .= $indent.' */';
195 195
 
196 196
         return $comment;
197 197
     }
Please login to merge, or discard this patch.
src/phpDocumentor/Reflection/DocBlock/Type/Collection.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,6 @@
 block discarded – undo
56 56
      *
57 57
      * @param string[] $types    Array containing a list of types to add to this
58 58
      *     container.
59
-     * @param Context  $location The current invoking location.
60 59
      */
61 60
     public function __construct(
62 61
         array $types = array(),
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         }
153 153
 
154 154
         if ($this->isTypeAnArray($type)) {
155
-            return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
155
+            return $this->expand(substr($type, 0, -2)).self::OPERATOR_ARRAY;
156 156
         }
157 157
 
158 158
         if ($this->isRelativeType($type) && !$this->isTypeAKeyword($type)) {
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
                 if ('' !== $namespace) {
167 167
                     $namespace .= self::OPERATOR_NAMESPACE;
168 168
                 }
169
-                return self::OPERATOR_NAMESPACE . $namespace . $type;
169
+                return self::OPERATOR_NAMESPACE.$namespace.$type;
170 170
             }
171 171
 
172 172
             $type_parts[0] = $namespace_aliases[$type_parts[0]];
Please login to merge, or discard this patch.
tests/phpDocumentor/Reflection/DocBlock/Tag/ExampleTagTest.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
      * @param string $exContent
32 32
      * @param string $exStartingLine
33 33
      * @param string $exLineCount
34
-     * @param string $exFilepath
34
+     * @param string $exFilePath
35 35
      *
36 36
      * @covers \phpDocumentor\Reflection\DocBlock\Tag\ExampleTag
37 37
      * @dataProvider provideDataForConstuctor
Please login to merge, or discard this patch.
vendor/phpspec/php-diff/lib/Diff/SequenceMatcher.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 	 * The ratio is calculated as (2 * number of matches) / total number of
608 608
 	 * elements in both sequences.
609 609
 	 *
610
-	 * @return float The calculated ratio.
610
+	 * @return integer The calculated ratio.
611 611
 	 */
612 612
 	public function Ratio()
613 613
 	{
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
 	 * Return an upper bound ratio really quickly for the similarity of the strings.
669 669
 	 * This is quicker to compute than Ratio() and quickRatio().
670 670
 	 *
671
-	 * @return float The calculated ratio.
671
+	 * @return integer The calculated ratio.
672 672
 	 */
673 673
 	private function realquickRatio()
674 674
 	{
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 	 *
685 685
 	 * @param int $matches The number of matches in the two strings.
686 686
 	 * @param int $length The length of the two strings.
687
-	 * @return float The calculated ratio.
687
+	 * @return integer The calculated ratio.
688 688
 	 */
689 689
 	private function calculateRatio($matches, $length=0)
690 690
 	{
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @param string|array $junkCallback Either an array or string that references a callback function (if there is one) to determine 'junk' characters.
86 86
 	 * @param array $options
87 87
 	 */
88
-	public function __construct($a, $b, $junkCallback=null, $options)
88
+	public function __construct($a, $b, $junkCallback = null, $options)
89 89
 	{
90 90
 		$this->a = null;
91 91
 		$this->b = null;
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
 	 */
125 125
 	public function setSeq1($a)
126 126
 	{
127
-		if(!is_array($a)) {
127
+		if (!is_array($a)) {
128 128
 			$a = str_split($a);
129 129
 		}
130
-		if($a == $this->a) {
130
+		if ($a == $this->a) {
131 131
 			return;
132 132
 		}
133 133
 
134
-		$this->a= $a;
134
+		$this->a = $a;
135 135
 		$this->matchingBlocks = null;
136 136
 		$this->opCodes = null;
137 137
 	}
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function setSeq2($b)
146 146
 	{
147
-		if(!is_array($b)) {
147
+		if (!is_array($b)) {
148 148
 			$b = str_split($b);
149 149
 		}
150
-		if($b == $this->b) {
150
+		if ($b == $this->b) {
151 151
 			return;
152 152
 		}
153 153
 
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
 	 */
165 165
 	private function chainB()
166 166
 	{
167
-		$length = count ($this->b);
167
+		$length = count($this->b);
168 168
 		$this->b2j = array();
169 169
 		$popularDict = array();
170 170
 
171
-		for($i = 0; $i < $length; ++$i) {
171
+		for ($i = 0; $i < $length; ++$i) {
172 172
 			$char = $this->b[$i];
173
-			if(isset($this->b2j[$char])) {
174
-				if($length >= 200 && count($this->b2j[$char]) * 100 > $length) {
173
+			if (isset($this->b2j[$char])) {
174
+				if ($length >= 200 && count($this->b2j[$char]) * 100 > $length) {
175 175
 					$popularDict[$char] = 1;
176 176
 					unset($this->b2j[$char]);
177 177
 				}
@@ -187,21 +187,21 @@  discard block
 block discarded – undo
187 187
 		}
188 188
 
189 189
 		// Remove leftovers
190
-		foreach(array_keys($popularDict) as $char) {
190
+		foreach (array_keys($popularDict) as $char) {
191 191
 			unset($this->b2j[$char]);
192 192
 		}
193 193
 
194 194
 		$this->junkDict = array();
195
-		if(is_callable($this->junkCallback)) {
196
-			foreach(array_keys($popularDict) as $char) {
197
-				if(call_user_func($this->junkCallback, $char)) {
195
+		if (is_callable($this->junkCallback)) {
196
+			foreach (array_keys($popularDict) as $char) {
197
+				if (call_user_func($this->junkCallback, $char)) {
198 198
 					$this->junkDict[$char] = 1;
199 199
 					unset($popularDict[$char]);
200 200
 				}
201 201
 			}
202 202
 
203
-			foreach(array_keys($this->b2j) as $char) {
204
-				if(call_user_func($this->junkCallback, $char)) {
203
+			foreach (array_keys($this->b2j) as $char) {
204
+				if (call_user_func($this->junkCallback, $char)) {
205 205
 					$this->junkDict[$char] = 1;
206 206
 					unset($this->b2j[$char]);
207 207
 				}
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 */
218 218
 	private function isBJunk($b)
219 219
 	{
220
-		if(isset($this->juncDict[$b])) {
220
+		if (isset($this->juncDict[$b])) {
221 221
 			return true;
222 222
 		}
223 223
 
@@ -255,20 +255,20 @@  discard block
 block discarded – undo
255 255
 		$j2Len = array();
256 256
 		$nothing = array();
257 257
 
258
-		for($i = $alo; $i < $ahi; ++$i) {
258
+		for ($i = $alo; $i < $ahi; ++$i) {
259 259
 			$newJ2Len = array();
260 260
 			$jDict = $this->arrayGetDefault($this->b2j, $a[$i], $nothing);
261
-			foreach($jDict as $jKey => $j) {
262
-				if($j < $blo) {
261
+			foreach ($jDict as $jKey => $j) {
262
+				if ($j < $blo) {
263 263
 					continue;
264 264
 				}
265
-				else if($j >= $bhi) {
265
+				else if ($j >= $bhi) {
266 266
 					break;
267 267
 				}
268 268
 
269
-				$k = $this->arrayGetDefault($j2Len, $j -1, 0) + 1;
269
+				$k = $this->arrayGetDefault($j2Len, $j - 1, 0) + 1;
270 270
 				$newJ2Len[$j] = $k;
271
-				if($k > $bestSize) {
271
+				if ($k > $bestSize) {
272 272
 					$bestI = $i - $k + 1;
273 273
 					$bestJ = $j - $k + 1;
274 274
 					$bestSize = $k;
@@ -278,26 +278,26 @@  discard block
 block discarded – undo
278 278
 			$j2Len = $newJ2Len;
279 279
 		}
280 280
 
281
-		while($bestI > $alo && $bestJ > $blo && !$this->isBJunk($b[$bestJ - 1]) &&
281
+		while ($bestI > $alo && $bestJ > $blo && !$this->isBJunk($b[$bestJ - 1]) &&
282 282
 			!$this->linesAreDifferent($bestI - 1, $bestJ - 1)) {
283 283
 				--$bestI;
284 284
 				--$bestJ;
285 285
 				++$bestSize;
286 286
 		}
287 287
 
288
-		while($bestI + $bestSize < $ahi && ($bestJ + $bestSize) < $bhi &&
288
+		while ($bestI + $bestSize < $ahi && ($bestJ + $bestSize) < $bhi &&
289 289
 			!$this->isBJunk($b[$bestJ + $bestSize]) && !$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)) {
290 290
 				++$bestSize;
291 291
 		}
292 292
 
293
-		while($bestI > $alo && $bestJ > $blo && $this->isBJunk($b[$bestJ - 1]) &&
293
+		while ($bestI > $alo && $bestJ > $blo && $this->isBJunk($b[$bestJ - 1]) &&
294 294
 			!$this->isLineDifferent($bestI - 1, $bestJ - 1)) {
295 295
 				--$bestI;
296 296
 				--$bestJ;
297 297
 				++$bestSize;
298 298
 		}
299 299
 
300
-		while($bestI + $bestSize < $ahi && $bestJ + $bestSize < $bhi &&
300
+		while ($bestI + $bestSize < $ahi && $bestJ + $bestSize < $bhi &&
301 301
 			$this->isBJunk($b[$bestJ + $bestSize]) && !$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)) {
302 302
 					++$bestSize;
303 303
 		}
@@ -321,18 +321,18 @@  discard block
 block discarded – undo
321 321
 		$lineA = $this->a[$aIndex];
322 322
 		$lineB = $this->b[$bIndex];
323 323
 
324
-		if($this->options['ignoreWhitespace']) {
324
+		if ($this->options['ignoreWhitespace']) {
325 325
 			$replace = array("\t", ' ');
326 326
 			$lineA = str_replace($replace, '', $lineA);
327 327
 			$lineB = str_replace($replace, '', $lineB);
328 328
 		}
329 329
 
330
-		if($this->options['ignoreCase']) {
330
+		if ($this->options['ignoreCase']) {
331 331
 			$lineA = strtolower($lineA);
332 332
 			$lineB = strtolower($lineB);
333 333
 		}
334 334
 
335
-		if($lineA != $lineB) {
335
+		if ($lineA != $lineB) {
336 336
 			return true;
337 337
 		}
338 338
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	 */
352 352
 	public function getMatchingBlocks()
353 353
 	{
354
-		if(!empty($this->matchingBlocks)) {
354
+		if (!empty($this->matchingBlocks)) {
355 355
 			return $this->matchingBlocks;
356 356
 		}
357 357
 
@@ -368,13 +368,13 @@  discard block
 block discarded – undo
368 368
 		);
369 369
 
370 370
 		$matchingBlocks = array();
371
-		while(!empty($queue)) {
371
+		while (!empty($queue)) {
372 372
 			list($alo, $ahi, $blo, $bhi) = array_pop($queue);
373 373
 			$x = $this->findLongestMatch($alo, $ahi, $blo, $bhi);
374 374
 			list($i, $j, $k) = $x;
375
-			if($k) {
375
+			if ($k) {
376 376
 				$matchingBlocks[] = $x;
377
-				if($alo < $i && $blo < $j) {
377
+				if ($alo < $i && $blo < $j) {
378 378
 					$queue[] = array(
379 379
 						$alo,
380 380
 						$i,
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 					);
384 384
 				}
385 385
 
386
-				if($i + $k < $ahi && $j + $k < $bhi) {
386
+				if ($i + $k < $ahi && $j + $k < $bhi) {
387 387
 					$queue[] = array(
388 388
 						$i + $k,
389 389
 						$ahi,
@@ -400,13 +400,13 @@  discard block
 block discarded – undo
400 400
 		$j1 = 0;
401 401
 		$k1 = 0;
402 402
 		$nonAdjacent = array();
403
-		foreach($matchingBlocks as $block) {
403
+		foreach ($matchingBlocks as $block) {
404 404
 			list($i2, $j2, $k2) = $block;
405
-			if($i1 + $k1 == $i2 && $j1 + $k1 == $j2) {
405
+			if ($i1 + $k1 == $i2 && $j1 + $k1 == $j2) {
406 406
 				$k1 += $k2;
407 407
 			}
408 408
 			else {
409
-				if($k1) {
409
+				if ($k1) {
410 410
 					$nonAdjacent[] = array(
411 411
 						$i1,
412 412
 						$j1,
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 			}
421 421
 		}
422 422
 
423
-		if($k1) {
423
+		if ($k1) {
424 424
 			$nonAdjacent[] = array(
425 425
 				$i1,
426 426
 				$j1,
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	 */
463 463
 	public function getOpCodes()
464 464
 	{
465
-		if(!empty($this->opCodes)) {
465
+		if (!empty($this->opCodes)) {
466 466
 			return $this->opCodes;
467 467
 		}
468 468
 
@@ -471,20 +471,20 @@  discard block
 block discarded – undo
471 471
 		$this->opCodes = array();
472 472
 
473 473
 		$blocks = $this->getMatchingBlocks();
474
-		foreach($blocks as $block) {
474
+		foreach ($blocks as $block) {
475 475
 			list($ai, $bj, $size) = $block;
476 476
 			$tag = '';
477
-			if($i < $ai && $j < $bj) {
477
+			if ($i < $ai && $j < $bj) {
478 478
 				$tag = 'replace';
479 479
 			}
480
-			else if($i < $ai) {
480
+			else if ($i < $ai) {
481 481
 				$tag = 'delete';
482 482
 			}
483
-			else if($j < $bj) {
483
+			else if ($j < $bj) {
484 484
 				$tag = 'insert';
485 485
 			}
486 486
 
487
-			if($tag) {
487
+			if ($tag) {
488 488
 				$this->opCodes[] = array(
489 489
 					$tag,
490 490
 					$i,
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 			$i = $ai + $size;
498 498
 			$j = $bj + $size;
499 499
 
500
-			if($size) {
500
+			if ($size) {
501 501
 				$this->opCodes[] = array(
502 502
 					'equal',
503 503
 					$ai,
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
 	 * @param int $context The number of lines of context to provide around the groups.
525 525
 	 * @return array Nested array of all of the grouped opcodes.
526 526
 	 */
527
-	public function getGroupedOpcodes($context=3)
527
+	public function getGroupedOpcodes($context = 3)
528 528
 	{
529 529
 		$opCodes = $this->getOpCodes();
530
-		if(empty($opCodes)) {
530
+		if (empty($opCodes)) {
531 531
 			$opCodes = array(
532 532
 				array(
533 533
 					'equal',
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 			);
540 540
 		}
541 541
 
542
-		if($opCodes[0][0] == 'equal') {
542
+		if ($opCodes[0][0] == 'equal') {
543 543
 			$opCodes[0] = array(
544 544
 				$opCodes[0][0],
545 545
 				max($opCodes[0][1], $opCodes[0][2] - $context),
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 		}
551 551
 
552 552
 		$lastItem = count($opCodes) - 1;
553
-		if($opCodes[$lastItem][0] == 'equal') {
553
+		if ($opCodes[$lastItem][0] == 'equal') {
554 554
 			list($tag, $i1, $i2, $j1, $j2) = $opCodes[$lastItem];
555 555
 			$opCodes[$lastItem] = array(
556 556
 				$tag,
@@ -564,9 +564,9 @@  discard block
 block discarded – undo
564 564
 		$maxRange = $context * 2;
565 565
 		$groups = array();
566 566
 		$group = array();
567
-		foreach($opCodes as $code) {
567
+		foreach ($opCodes as $code) {
568 568
 			list($tag, $i1, $i2, $j1, $j2) = $code;
569
-			if($tag == 'equal' && $i2 - $i1 > $maxRange) {
569
+			if ($tag == 'equal' && $i2 - $i1 > $maxRange) {
570 570
 				$group[] = array(
571 571
 					$tag,
572 572
 					$i1,
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 			);
589 589
 		}
590 590
 
591
-		if(!empty($group) && !(count($group) == 1 && $group[0][0] == 'equal')) {
591
+		if (!empty($group) && !(count($group) == 1 && $group[0][0] == 'equal')) {
592 592
 			$groups[] = $group;
593 593
 		}
594 594
 
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 	public function Ratio()
613 613
 	{
614 614
 		$matches = array_reduce($this->getMatchingBlocks(), array($this, 'ratioReduce'), 0);
615
-		return $this->calculateRatio($matches, count ($this->a) + count ($this->b));
615
+		return $this->calculateRatio($matches, count($this->a) + count($this->b));
616 616
 	}
617 617
 
618 618
 	/**
@@ -635,10 +635,10 @@  discard block
 block discarded – undo
635 635
 	 */
636 636
 	private function quickRatio()
637 637
 	{
638
-		if($this->fullBCount === null) {
638
+		if ($this->fullBCount === null) {
639 639
 			$this->fullBCount = array();
640
-			$bLength = count ($this->b);
641
-			for($i = 0; $i < $bLength; ++$i) {
640
+			$bLength = count($this->b);
641
+			for ($i = 0; $i < $bLength; ++$i) {
642 642
 				$char = $this->b[$i];
643 643
 				$this->fullBCount[$char] = $this->arrayGetDefault($this->fullBCount, $char, 0) + 1;
644 644
 			}
@@ -646,22 +646,22 @@  discard block
 block discarded – undo
646 646
 
647 647
 		$avail = array();
648 648
 		$matches = 0;
649
-		$aLength = count ($this->a);
650
-		for($i = 0; $i < $aLength; ++$i) {
649
+		$aLength = count($this->a);
650
+		for ($i = 0; $i < $aLength; ++$i) {
651 651
 			$char = $this->a[$i];
652
-			if(isset($avail[$char])) {
652
+			if (isset($avail[$char])) {
653 653
 				$numb = $avail[$char];
654 654
 			}
655 655
 			else {
656 656
 				$numb = $this->arrayGetDefault($this->fullBCount, $char, 0);
657 657
 			}
658 658
 			$avail[$char] = $numb - 1;
659
-			if($numb > 0) {
659
+			if ($numb > 0) {
660 660
 				++$matches;
661 661
 			}
662 662
 		}
663 663
 
664
-		$this->calculateRatio($matches, count ($this->a) + count ($this->b));
664
+		$this->calculateRatio($matches, count($this->a) + count($this->b));
665 665
 	}
666 666
 
667 667
 	/**
@@ -672,8 +672,8 @@  discard block
 block discarded – undo
672 672
 	 */
673 673
 	private function realquickRatio()
674 674
 	{
675
-		$aLength = count ($this->a);
676
-		$bLength = count ($this->b);
675
+		$aLength = count($this->a);
676
+		$bLength = count($this->b);
677 677
 
678 678
 		return $this->calculateRatio(min($aLength, $bLength), $aLength + $bLength);
679 679
 	}
@@ -686,9 +686,9 @@  discard block
 block discarded – undo
686 686
 	 * @param int $length The length of the two strings.
687 687
 	 * @return float The calculated ratio.
688 688
 	 */
689
-	private function calculateRatio($matches, $length=0)
689
+	private function calculateRatio($matches, $length = 0)
690 690
 	{
691
-		if($length) {
691
+		if ($length) {
692 692
 			return 2 * ($matches / $length);
693 693
 		}
694 694
 		else {
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 	 */
709 709
 	private function arrayGetDefault($array, $key, $default)
710 710
 	{
711
-		if(isset($array[$key])) {
711
+		if (isset($array[$key])) {
712 712
 			return $array[$key];
713 713
 		}
714 714
 		else {
@@ -726,19 +726,19 @@  discard block
 block discarded – undo
726 726
 	private function tupleSort($a, $b)
727 727
 	{
728 728
 		$max = max(count($a), count($b));
729
-		for($i = 0; $i < $max; ++$i) {
730
-			if($a[$i] < $b[$i]) {
729
+		for ($i = 0; $i < $max; ++$i) {
730
+			if ($a[$i] < $b[$i]) {
731 731
 				return -1;
732 732
 			}
733
-			else if($a[$i] > $b[$i]) {
733
+			else if ($a[$i] > $b[$i]) {
734 734
 				return 1;
735 735
 			}
736 736
 		}
737 737
 
738
-		if(count($a) == count($b)) {
738
+		if (count($a) == count($b)) {
739 739
 			return 0;
740 740
 		}
741
-		else if(count($a) < count($b)) {
741
+		else if (count($a) < count($b)) {
742 742
 			return -1;
743 743
 		}
744 744
 		else {
Please login to merge, or discard this patch.
Braces   +12 added lines, -24 removed lines patch added patch discarded remove patch
@@ -174,12 +174,10 @@  discard block
 block discarded – undo
174 174
 				if($length >= 200 && count($this->b2j[$char]) * 100 > $length) {
175 175
 					$popularDict[$char] = 1;
176 176
 					unset($this->b2j[$char]);
177
-				}
178
-				else {
177
+				} else {
179 178
 					$this->b2j[$char][] = $i;
180 179
 				}
181
-			}
182
-			else {
180
+			} else {
183 181
 				$this->b2j[$char] = array(
184 182
 					$i
185 183
 				);
@@ -261,8 +259,7 @@  discard block
 block discarded – undo
261 259
 			foreach($jDict as $jKey => $j) {
262 260
 				if($j < $blo) {
263 261
 					continue;
264
-				}
265
-				else if($j >= $bhi) {
262
+				} else if($j >= $bhi) {
266 263
 					break;
267 264
 				}
268 265
 
@@ -404,8 +401,7 @@  discard block
 block discarded – undo
404 401
 			list($i2, $j2, $k2) = $block;
405 402
 			if($i1 + $k1 == $i2 && $j1 + $k1 == $j2) {
406 403
 				$k1 += $k2;
407
-			}
408
-			else {
404
+			} else {
409 405
 				if($k1) {
410 406
 					$nonAdjacent[] = array(
411 407
 						$i1,
@@ -476,11 +472,9 @@  discard block
 block discarded – undo
476 472
 			$tag = '';
477 473
 			if($i < $ai && $j < $bj) {
478 474
 				$tag = 'replace';
479
-			}
480
-			else if($i < $ai) {
475
+			} else if($i < $ai) {
481 476
 				$tag = 'delete';
482
-			}
483
-			else if($j < $bj) {
477
+			} else if($j < $bj) {
484 478
 				$tag = 'insert';
485 479
 			}
486 480
 
@@ -651,8 +645,7 @@  discard block
 block discarded – undo
651 645
 			$char = $this->a[$i];
652 646
 			if(isset($avail[$char])) {
653 647
 				$numb = $avail[$char];
654
-			}
655
-			else {
648
+			} else {
656 649
 				$numb = $this->arrayGetDefault($this->fullBCount, $char, 0);
657 650
 			}
658 651
 			$avail[$char] = $numb - 1;
@@ -690,8 +683,7 @@  discard block
 block discarded – undo
690 683
 	{
691 684
 		if($length) {
692 685
 			return 2 * ($matches / $length);
693
-		}
694
-		else {
686
+		} else {
695 687
 			return 1;
696 688
 		}
697 689
 	}
@@ -710,8 +702,7 @@  discard block
 block discarded – undo
710 702
 	{
711 703
 		if(isset($array[$key])) {
712 704
 			return $array[$key];
713
-		}
714
-		else {
705
+		} else {
715 706
 			return $default;
716 707
 		}
717 708
 	}
@@ -729,19 +720,16 @@  discard block
 block discarded – undo
729 720
 		for($i = 0; $i < $max; ++$i) {
730 721
 			if($a[$i] < $b[$i]) {
731 722
 				return -1;
732
-			}
733
-			else if($a[$i] > $b[$i]) {
723
+			} else if($a[$i] > $b[$i]) {
734 724
 				return 1;
735 725
 			}
736 726
 		}
737 727
 
738 728
 		if(count($a) == count($b)) {
739 729
 			return 0;
740
-		}
741
-		else if(count($a) < count($b)) {
730
+		} else if(count($a) < count($b)) {
742 731
 			return -1;
743
-		}
744
-		else {
732
+		} else {
745 733
 			return 1;
746 734
 		}
747 735
 	}
Please login to merge, or discard this patch.
Indentation   +703 added lines, -703 removed lines patch added patch discarded remove patch
@@ -42,707 +42,707 @@
 block discarded – undo
42 42
 
43 43
 class Diff_SequenceMatcher
44 44
 {
45
-	/**
46
-	 * @var string|array Either a string or an array containing a callback function to determine if a line is "junk" or not.
47
-	 */
48
-	private $junkCallback = null;
49
-
50
-	/**
51
-	 * @var array The first sequence to compare against.
52
-	 */
53
-	private $a = null;
54
-
55
-	/**
56
-	 * @var array The second sequence.
57
-	 */
58
-	private $b = null;
59
-
60
-	/**
61
-	 * @var array Array of characters that are considered junk from the second sequence. Characters are the array key.
62
-	 */
63
-	private $junkDict = array();
64
-
65
-	/**
66
-	 * @var array Array of indices that do not contain junk elements.
67
-	 */
68
-	private $b2j = array();
69
-
70
-	private $options = array();
71
-
72
-	private $defaultOptions = array(
73
-		'ignoreNewLines' => false,
74
-		'ignoreWhitespace' => false,
75
-		'ignoreCase' => false
76
-	);
77
-
78
-	/**
79
-	 * The constructor. With the sequences being passed, they'll be set for the
80
-	 * sequence matcher and it will perform a basic cleanup & calculate junk
81
-	 * elements.
82
-	 *
83
-	 * @param string|array $a A string or array containing the lines to compare against.
84
-	 * @param string|array $b A string or array containing the lines to compare.
85
-	 * @param string|array $junkCallback Either an array or string that references a callback function (if there is one) to determine 'junk' characters.
86
-	 * @param array $options
87
-	 */
88
-	public function __construct($a, $b, $junkCallback=null, $options)
89
-	{
90
-		$this->a = null;
91
-		$this->b = null;
92
-		$this->junkCallback = $junkCallback;
93
-		$this->setOptions($options);
94
-		$this->setSequences($a, $b);
95
-	}
96
-
97
-	/**
98
-	 * Set new options
99
-	 *
100
-	 * @param array $options
101
-	 */
102
-	public function setOptions($options)
103
-	{
104
-		$this->options = array_merge($this->defaultOptions, $options);
105
-	}
106
-
107
-	/**
108
-	 * Set the first and second sequences to use with the sequence matcher.
109
-	 *
110
-	 * @param string|array $a A string or array containing the lines to compare against.
111
-	 * @param string|array $b A string or array containing the lines to compare.
112
-	 */
113
-	public function setSequences($a, $b)
114
-	{
115
-		$this->setSeq1($a);
116
-		$this->setSeq2($b);
117
-	}
118
-
119
-	/**
120
-	 * Set the first sequence ($a) and reset any internal caches to indicate that
121
-	 * when calling the calculation methods, we need to recalculate them.
122
-	 *
123
-	 * @param string|array $a The sequence to set as the first sequence.
124
-	 */
125
-	public function setSeq1($a)
126
-	{
127
-		if(!is_array($a)) {
128
-			$a = str_split($a);
129
-		}
130
-		if($a == $this->a) {
131
-			return;
132
-		}
133
-
134
-		$this->a= $a;
135
-		$this->matchingBlocks = null;
136
-		$this->opCodes = null;
137
-	}
138
-
139
-	/**
140
-	 * Set the second sequence ($b) and reset any internal caches to indicate that
141
-	 * when calling the calculation methods, we need to recalculate them.
142
-	 *
143
-	 * @param string|array $b The sequence to set as the second sequence.
144
-	 */
145
-	public function setSeq2($b)
146
-	{
147
-		if(!is_array($b)) {
148
-			$b = str_split($b);
149
-		}
150
-		if($b == $this->b) {
151
-			return;
152
-		}
153
-
154
-		$this->b = $b;
155
-		$this->matchingBlocks = null;
156
-		$this->opCodes = null;
157
-		$this->fullBCount = null;
158
-		$this->chainB();
159
-	}
160
-
161
-	/**
162
-	 * Generate the internal arrays containing the list of junk and non-junk
163
-	 * characters for the second ($b) sequence.
164
-	 */
165
-	private function chainB()
166
-	{
167
-		$length = count ($this->b);
168
-		$this->b2j = array();
169
-		$popularDict = array();
170
-
171
-		for($i = 0; $i < $length; ++$i) {
172
-			$char = $this->b[$i];
173
-			if(isset($this->b2j[$char])) {
174
-				if($length >= 200 && count($this->b2j[$char]) * 100 > $length) {
175
-					$popularDict[$char] = 1;
176
-					unset($this->b2j[$char]);
177
-				}
178
-				else {
179
-					$this->b2j[$char][] = $i;
180
-				}
181
-			}
182
-			else {
183
-				$this->b2j[$char] = array(
184
-					$i
185
-				);
186
-			}
187
-		}
188
-
189
-		// Remove leftovers
190
-		foreach(array_keys($popularDict) as $char) {
191
-			unset($this->b2j[$char]);
192
-		}
193
-
194
-		$this->junkDict = array();
195
-		if(is_callable($this->junkCallback)) {
196
-			foreach(array_keys($popularDict) as $char) {
197
-				if(call_user_func($this->junkCallback, $char)) {
198
-					$this->junkDict[$char] = 1;
199
-					unset($popularDict[$char]);
200
-				}
201
-			}
202
-
203
-			foreach(array_keys($this->b2j) as $char) {
204
-				if(call_user_func($this->junkCallback, $char)) {
205
-					$this->junkDict[$char] = 1;
206
-					unset($this->b2j[$char]);
207
-				}
208
-			}
209
-		}
210
-	}
211
-
212
-	/**
213
-	 * Checks if a particular character is in the junk dictionary
214
-	 * for the list of junk characters.
215
-	 * @param $b
216
-	 * @return boolean True if the character is considered junk. False if not.
217
-	 */
218
-	private function isBJunk($b)
219
-	{
220
-		if(isset($this->juncDict[$b])) {
221
-			return true;
222
-		}
223
-
224
-		return false;
225
-	}
226
-
227
-	/**
228
-	 * Find the longest matching block in the two sequences, as defined by the
229
-	 * lower and upper constraints for each sequence. (for the first sequence,
230
-	 * $alo - $ahi and for the second sequence, $blo - $bhi)
231
-	 *
232
-	 * Essentially, of all of the maximal matching blocks, return the one that
233
-	 * startest earliest in $a, and all of those maximal matching blocks that
234
-	 * start earliest in $a, return the one that starts earliest in $b.
235
-	 *
236
-	 * If the junk callback is defined, do the above but with the restriction
237
-	 * that the junk element appears in the block. Extend it as far as possible
238
-	 * by matching only junk elements in both $a and $b.
239
-	 *
240
-	 * @param int $alo The lower constraint for the first sequence.
241
-	 * @param int $ahi The upper constraint for the first sequence.
242
-	 * @param int $blo The lower constraint for the second sequence.
243
-	 * @param int $bhi The upper constraint for the second sequence.
244
-	 * @return array Array containing the longest match that includes the starting position in $a, start in $b and the length/size.
245
-	 */
246
-	public function findLongestMatch($alo, $ahi, $blo, $bhi)
247
-	{
248
-		$a = $this->a;
249
-		$b = $this->b;
250
-
251
-		$bestI = $alo;
252
-		$bestJ = $blo;
253
-		$bestSize = 0;
254
-
255
-		$j2Len = array();
256
-		$nothing = array();
257
-
258
-		for($i = $alo; $i < $ahi; ++$i) {
259
-			$newJ2Len = array();
260
-			$jDict = $this->arrayGetDefault($this->b2j, $a[$i], $nothing);
261
-			foreach($jDict as $jKey => $j) {
262
-				if($j < $blo) {
263
-					continue;
264
-				}
265
-				else if($j >= $bhi) {
266
-					break;
267
-				}
268
-
269
-				$k = $this->arrayGetDefault($j2Len, $j -1, 0) + 1;
270
-				$newJ2Len[$j] = $k;
271
-				if($k > $bestSize) {
272
-					$bestI = $i - $k + 1;
273
-					$bestJ = $j - $k + 1;
274
-					$bestSize = $k;
275
-				}
276
-			}
277
-
278
-			$j2Len = $newJ2Len;
279
-		}
280
-
281
-		while($bestI > $alo && $bestJ > $blo && !$this->isBJunk($b[$bestJ - 1]) &&
282
-			!$this->linesAreDifferent($bestI - 1, $bestJ - 1)) {
283
-				--$bestI;
284
-				--$bestJ;
285
-				++$bestSize;
286
-		}
287
-
288
-		while($bestI + $bestSize < $ahi && ($bestJ + $bestSize) < $bhi &&
289
-			!$this->isBJunk($b[$bestJ + $bestSize]) && !$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)) {
290
-				++$bestSize;
291
-		}
292
-
293
-		while($bestI > $alo && $bestJ > $blo && $this->isBJunk($b[$bestJ - 1]) &&
294
-			!$this->isLineDifferent($bestI - 1, $bestJ - 1)) {
295
-				--$bestI;
296
-				--$bestJ;
297
-				++$bestSize;
298
-		}
299
-
300
-		while($bestI + $bestSize < $ahi && $bestJ + $bestSize < $bhi &&
301
-			$this->isBJunk($b[$bestJ + $bestSize]) && !$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)) {
302
-					++$bestSize;
303
-		}
304
-
305
-		return array(
306
-			$bestI,
307
-			$bestJ,
308
-			$bestSize
309
-		);
310
-	}
311
-
312
-	/**
313
-	 * Check if the two lines at the given indexes are different or not.
314
-	 *
315
-	 * @param int $aIndex Line number to check against in a.
316
-	 * @param int $bIndex Line number to check against in b.
317
-	 * @return boolean True if the lines are different and false if not.
318
-	 */
319
-	public function linesAreDifferent($aIndex, $bIndex)
320
-	{
321
-		$lineA = $this->a[$aIndex];
322
-		$lineB = $this->b[$bIndex];
323
-
324
-		if($this->options['ignoreWhitespace']) {
325
-			$replace = array("\t", ' ');
326
-			$lineA = str_replace($replace, '', $lineA);
327
-			$lineB = str_replace($replace, '', $lineB);
328
-		}
329
-
330
-		if($this->options['ignoreCase']) {
331
-			$lineA = strtolower($lineA);
332
-			$lineB = strtolower($lineB);
333
-		}
334
-
335
-		if($lineA != $lineB) {
336
-			return true;
337
-		}
338
-
339
-		return false;
340
-	}
341
-
342
-	/**
343
-	 * Return a nested set of arrays for all of the matching sub-sequences
344
-	 * in the strings $a and $b.
345
-	 *
346
-	 * Each block contains the lower constraint of the block in $a, the lower
347
-	 * constraint of the block in $b and finally the number of lines that the
348
-	 * block continues for.
349
-	 *
350
-	 * @return array Nested array of the matching blocks, as described by the function.
351
-	 */
352
-	public function getMatchingBlocks()
353
-	{
354
-		if(!empty($this->matchingBlocks)) {
355
-			return $this->matchingBlocks;
356
-		}
357
-
358
-		$aLength = count($this->a);
359
-		$bLength = count($this->b);
360
-
361
-		$queue = array(
362
-			array(
363
-				0,
364
-				$aLength,
365
-				0,
366
-				$bLength
367
-			)
368
-		);
369
-
370
-		$matchingBlocks = array();
371
-		while(!empty($queue)) {
372
-			list($alo, $ahi, $blo, $bhi) = array_pop($queue);
373
-			$x = $this->findLongestMatch($alo, $ahi, $blo, $bhi);
374
-			list($i, $j, $k) = $x;
375
-			if($k) {
376
-				$matchingBlocks[] = $x;
377
-				if($alo < $i && $blo < $j) {
378
-					$queue[] = array(
379
-						$alo,
380
-						$i,
381
-						$blo,
382
-						$j
383
-					);
384
-				}
385
-
386
-				if($i + $k < $ahi && $j + $k < $bhi) {
387
-					$queue[] = array(
388
-						$i + $k,
389
-						$ahi,
390
-						$j + $k,
391
-						$bhi
392
-					);
393
-				}
394
-			}
395
-		}
396
-
397
-		usort($matchingBlocks, array($this, 'tupleSort'));
398
-
399
-		$i1 = 0;
400
-		$j1 = 0;
401
-		$k1 = 0;
402
-		$nonAdjacent = array();
403
-		foreach($matchingBlocks as $block) {
404
-			list($i2, $j2, $k2) = $block;
405
-			if($i1 + $k1 == $i2 && $j1 + $k1 == $j2) {
406
-				$k1 += $k2;
407
-			}
408
-			else {
409
-				if($k1) {
410
-					$nonAdjacent[] = array(
411
-						$i1,
412
-						$j1,
413
-						$k1
414
-					);
415
-				}
416
-
417
-				$i1 = $i2;
418
-				$j1 = $j2;
419
-				$k1 = $k2;
420
-			}
421
-		}
422
-
423
-		if($k1) {
424
-			$nonAdjacent[] = array(
425
-				$i1,
426
-				$j1,
427
-				$k1
428
-			);
429
-		}
430
-
431
-		$nonAdjacent[] = array(
432
-			$aLength,
433
-			$bLength,
434
-			0
435
-		);
436
-
437
-		$this->matchingBlocks = $nonAdjacent;
438
-		return $this->matchingBlocks;
439
-	}
440
-
441
-	/**
442
-	 * Return a list of all of the opcodes for the differences between the
443
-	 * two strings.
444
-	 *
445
-	 * The nested array returned contains an array describing the opcode
446
-	 * which includes:
447
-	 * 0 - The type of tag (as described below) for the opcode.
448
-	 * 1 - The beginning line in the first sequence.
449
-	 * 2 - The end line in the first sequence.
450
-	 * 3 - The beginning line in the second sequence.
451
-	 * 4 - The end line in the second sequence.
452
-	 *
453
-	 * The different types of tags include:
454
-	 * replace - The string from $i1 to $i2 in $a should be replaced by
455
-	 *           the string in $b from $j1 to $j2.
456
-	 * delete -  The string in $a from $i1 to $j2 should be deleted.
457
-	 * insert -  The string in $b from $j1 to $j2 should be inserted at
458
-	 *           $i1 in $a.
459
-	 * equal  -  The two strings with the specified ranges are equal.
460
-	 *
461
-	 * @return array Array of the opcodes describing the differences between the strings.
462
-	 */
463
-	public function getOpCodes()
464
-	{
465
-		if(!empty($this->opCodes)) {
466
-			return $this->opCodes;
467
-		}
468
-
469
-		$i = 0;
470
-		$j = 0;
471
-		$this->opCodes = array();
472
-
473
-		$blocks = $this->getMatchingBlocks();
474
-		foreach($blocks as $block) {
475
-			list($ai, $bj, $size) = $block;
476
-			$tag = '';
477
-			if($i < $ai && $j < $bj) {
478
-				$tag = 'replace';
479
-			}
480
-			else if($i < $ai) {
481
-				$tag = 'delete';
482
-			}
483
-			else if($j < $bj) {
484
-				$tag = 'insert';
485
-			}
486
-
487
-			if($tag) {
488
-				$this->opCodes[] = array(
489
-					$tag,
490
-					$i,
491
-					$ai,
492
-					$j,
493
-					$bj
494
-				);
495
-			}
496
-
497
-			$i = $ai + $size;
498
-			$j = $bj + $size;
499
-
500
-			if($size) {
501
-				$this->opCodes[] = array(
502
-					'equal',
503
-					$ai,
504
-					$i,
505
-					$bj,
506
-					$j
507
-				);
508
-			}
509
-		}
510
-		return $this->opCodes;
511
-	}
512
-
513
-	/**
514
-	 * Return a series of nested arrays containing different groups of generated
515
-	 * opcodes for the differences between the strings with up to $context lines
516
-	 * of surrounding content.
517
-	 *
518
-	 * Essentially what happens here is any big equal blocks of strings are stripped
519
-	 * out, the smaller subsets of changes are then arranged in to their groups.
520
-	 * This means that the sequence matcher and diffs do not need to include the full
521
-	 * content of the different files but can still provide context as to where the
522
-	 * changes are.
523
-	 *
524
-	 * @param int $context The number of lines of context to provide around the groups.
525
-	 * @return array Nested array of all of the grouped opcodes.
526
-	 */
527
-	public function getGroupedOpcodes($context=3)
528
-	{
529
-		$opCodes = $this->getOpCodes();
530
-		if(empty($opCodes)) {
531
-			$opCodes = array(
532
-				array(
533
-					'equal',
534
-					0,
535
-					1,
536
-					0,
537
-					1
538
-				)
539
-			);
540
-		}
541
-
542
-		if($opCodes[0][0] == 'equal') {
543
-			$opCodes[0] = array(
544
-				$opCodes[0][0],
545
-				max($opCodes[0][1], $opCodes[0][2] - $context),
546
-				$opCodes[0][2],
547
-				max($opCodes[0][3], $opCodes[0][4] - $context),
548
-				$opCodes[0][4]
549
-			);
550
-		}
551
-
552
-		$lastItem = count($opCodes) - 1;
553
-		if($opCodes[$lastItem][0] == 'equal') {
554
-			list($tag, $i1, $i2, $j1, $j2) = $opCodes[$lastItem];
555
-			$opCodes[$lastItem] = array(
556
-				$tag,
557
-				$i1,
558
-				min($i2, $i1 + $context),
559
-				$j1,
560
-				min($j2, $j1 + $context)
561
-			);
562
-		}
563
-
564
-		$maxRange = $context * 2;
565
-		$groups = array();
566
-		$group = array();
567
-		foreach($opCodes as $code) {
568
-			list($tag, $i1, $i2, $j1, $j2) = $code;
569
-			if($tag == 'equal' && $i2 - $i1 > $maxRange) {
570
-				$group[] = array(
571
-					$tag,
572
-					$i1,
573
-					min($i2, $i1 + $context),
574
-					$j1,
575
-					min($j2, $j1 + $context)
576
-				);
577
-				$groups[] = $group;
578
-				$group = array();
579
-				$i1 = max($i1, $i2 - $context);
580
-				$j1 = max($j1, $j2 - $context);
581
-			}
582
-			$group[] = array(
583
-				$tag,
584
-				$i1,
585
-				$i2,
586
-				$j1,
587
-				$j2
588
-			);
589
-		}
590
-
591
-		if(!empty($group) && !(count($group) == 1 && $group[0][0] == 'equal')) {
592
-			$groups[] = $group;
593
-		}
594
-
595
-		return $groups;
596
-	}
597
-
598
-	/**
599
-	 * Return a measure of the similarity between the two sequences.
600
-	 * This will be a float value between 0 and 1.
601
-	 *
602
-	 * Out of all of the ratio calculation functions, this is the most
603
-	 * expensive to call if getMatchingBlocks or getOpCodes is yet to be
604
-	 * called. The other calculation methods (quickRatio and realquickRatio)
605
-	 * can be used to perform quicker calculations but may be less accurate.
606
-	 *
607
-	 * The ratio is calculated as (2 * number of matches) / total number of
608
-	 * elements in both sequences.
609
-	 *
610
-	 * @return float The calculated ratio.
611
-	 */
612
-	public function Ratio()
613
-	{
614
-		$matches = array_reduce($this->getMatchingBlocks(), array($this, 'ratioReduce'), 0);
615
-		return $this->calculateRatio($matches, count ($this->a) + count ($this->b));
616
-	}
617
-
618
-	/**
619
-	 * Helper function to calculate the number of matches for Ratio().
620
-	 *
621
-	 * @param int $sum The running total for the number of matches.
622
-	 * @param array $triple Array containing the matching block triple to add to the running total.
623
-	 * @return int The new running total for the number of matches.
624
-	 */
625
-	private function ratioReduce($sum, $triple)
626
-	{
627
-		return $sum + ($triple[count($triple) - 1]);
628
-	}
629
-
630
-	/**
631
-	 * Quickly return an upper bound ratio for the similarity of the strings.
632
-	 * This is quicker to compute than Ratio().
633
-	 *
634
-	 * @return float The calculated ratio.
635
-	 */
636
-	private function quickRatio()
637
-	{
638
-		if($this->fullBCount === null) {
639
-			$this->fullBCount = array();
640
-			$bLength = count ($this->b);
641
-			for($i = 0; $i < $bLength; ++$i) {
642
-				$char = $this->b[$i];
643
-				$this->fullBCount[$char] = $this->arrayGetDefault($this->fullBCount, $char, 0) + 1;
644
-			}
645
-		}
646
-
647
-		$avail = array();
648
-		$matches = 0;
649
-		$aLength = count ($this->a);
650
-		for($i = 0; $i < $aLength; ++$i) {
651
-			$char = $this->a[$i];
652
-			if(isset($avail[$char])) {
653
-				$numb = $avail[$char];
654
-			}
655
-			else {
656
-				$numb = $this->arrayGetDefault($this->fullBCount, $char, 0);
657
-			}
658
-			$avail[$char] = $numb - 1;
659
-			if($numb > 0) {
660
-				++$matches;
661
-			}
662
-		}
663
-
664
-		$this->calculateRatio($matches, count ($this->a) + count ($this->b));
665
-	}
666
-
667
-	/**
668
-	 * Return an upper bound ratio really quickly for the similarity of the strings.
669
-	 * This is quicker to compute than Ratio() and quickRatio().
670
-	 *
671
-	 * @return float The calculated ratio.
672
-	 */
673
-	private function realquickRatio()
674
-	{
675
-		$aLength = count ($this->a);
676
-		$bLength = count ($this->b);
677
-
678
-		return $this->calculateRatio(min($aLength, $bLength), $aLength + $bLength);
679
-	}
680
-
681
-	/**
682
-	 * Helper function for calculating the ratio to measure similarity for the strings.
683
-	 * The ratio is defined as being 2 * (number of matches / total length)
684
-	 *
685
-	 * @param int $matches The number of matches in the two strings.
686
-	 * @param int $length The length of the two strings.
687
-	 * @return float The calculated ratio.
688
-	 */
689
-	private function calculateRatio($matches, $length=0)
690
-	{
691
-		if($length) {
692
-			return 2 * ($matches / $length);
693
-		}
694
-		else {
695
-			return 1;
696
-		}
697
-	}
698
-
699
-	/**
700
-	 * Helper function that provides the ability to return the value for a key
701
-	 * in an array of it exists, or if it doesn't then return a default value.
702
-	 * Essentially cleaner than doing a series of if(isset()) {} else {} calls.
703
-	 *
704
-	 * @param array $array The array to search.
705
-	 * @param string $key The key to check that exists.
706
-	 * @param mixed $default The value to return as the default value if the key doesn't exist.
707
-	 * @return mixed The value from the array if the key exists or otherwise the default.
708
-	 */
709
-	private function arrayGetDefault($array, $key, $default)
710
-	{
711
-		if(isset($array[$key])) {
712
-			return $array[$key];
713
-		}
714
-		else {
715
-			return $default;
716
-		}
717
-	}
718
-
719
-	/**
720
-	 * Sort an array by the nested arrays it contains. Helper function for getMatchingBlocks
721
-	 *
722
-	 * @param array $a First array to compare.
723
-	 * @param array $b Second array to compare.
724
-	 * @return int -1, 0 or 1, as expected by the usort function.
725
-	 */
726
-	private function tupleSort($a, $b)
727
-	{
728
-		$max = max(count($a), count($b));
729
-		for($i = 0; $i < $max; ++$i) {
730
-			if($a[$i] < $b[$i]) {
731
-				return -1;
732
-			}
733
-			else if($a[$i] > $b[$i]) {
734
-				return 1;
735
-			}
736
-		}
737
-
738
-		if(count($a) == count($b)) {
739
-			return 0;
740
-		}
741
-		else if(count($a) < count($b)) {
742
-			return -1;
743
-		}
744
-		else {
745
-			return 1;
746
-		}
747
-	}
45
+    /**
46
+     * @var string|array Either a string or an array containing a callback function to determine if a line is "junk" or not.
47
+     */
48
+    private $junkCallback = null;
49
+
50
+    /**
51
+     * @var array The first sequence to compare against.
52
+     */
53
+    private $a = null;
54
+
55
+    /**
56
+     * @var array The second sequence.
57
+     */
58
+    private $b = null;
59
+
60
+    /**
61
+     * @var array Array of characters that are considered junk from the second sequence. Characters are the array key.
62
+     */
63
+    private $junkDict = array();
64
+
65
+    /**
66
+     * @var array Array of indices that do not contain junk elements.
67
+     */
68
+    private $b2j = array();
69
+
70
+    private $options = array();
71
+
72
+    private $defaultOptions = array(
73
+        'ignoreNewLines' => false,
74
+        'ignoreWhitespace' => false,
75
+        'ignoreCase' => false
76
+    );
77
+
78
+    /**
79
+     * The constructor. With the sequences being passed, they'll be set for the
80
+     * sequence matcher and it will perform a basic cleanup & calculate junk
81
+     * elements.
82
+     *
83
+     * @param string|array $a A string or array containing the lines to compare against.
84
+     * @param string|array $b A string or array containing the lines to compare.
85
+     * @param string|array $junkCallback Either an array or string that references a callback function (if there is one) to determine 'junk' characters.
86
+     * @param array $options
87
+     */
88
+    public function __construct($a, $b, $junkCallback=null, $options)
89
+    {
90
+        $this->a = null;
91
+        $this->b = null;
92
+        $this->junkCallback = $junkCallback;
93
+        $this->setOptions($options);
94
+        $this->setSequences($a, $b);
95
+    }
96
+
97
+    /**
98
+     * Set new options
99
+     *
100
+     * @param array $options
101
+     */
102
+    public function setOptions($options)
103
+    {
104
+        $this->options = array_merge($this->defaultOptions, $options);
105
+    }
106
+
107
+    /**
108
+     * Set the first and second sequences to use with the sequence matcher.
109
+     *
110
+     * @param string|array $a A string or array containing the lines to compare against.
111
+     * @param string|array $b A string or array containing the lines to compare.
112
+     */
113
+    public function setSequences($a, $b)
114
+    {
115
+        $this->setSeq1($a);
116
+        $this->setSeq2($b);
117
+    }
118
+
119
+    /**
120
+     * Set the first sequence ($a) and reset any internal caches to indicate that
121
+     * when calling the calculation methods, we need to recalculate them.
122
+     *
123
+     * @param string|array $a The sequence to set as the first sequence.
124
+     */
125
+    public function setSeq1($a)
126
+    {
127
+        if(!is_array($a)) {
128
+            $a = str_split($a);
129
+        }
130
+        if($a == $this->a) {
131
+            return;
132
+        }
133
+
134
+        $this->a= $a;
135
+        $this->matchingBlocks = null;
136
+        $this->opCodes = null;
137
+    }
138
+
139
+    /**
140
+     * Set the second sequence ($b) and reset any internal caches to indicate that
141
+     * when calling the calculation methods, we need to recalculate them.
142
+     *
143
+     * @param string|array $b The sequence to set as the second sequence.
144
+     */
145
+    public function setSeq2($b)
146
+    {
147
+        if(!is_array($b)) {
148
+            $b = str_split($b);
149
+        }
150
+        if($b == $this->b) {
151
+            return;
152
+        }
153
+
154
+        $this->b = $b;
155
+        $this->matchingBlocks = null;
156
+        $this->opCodes = null;
157
+        $this->fullBCount = null;
158
+        $this->chainB();
159
+    }
160
+
161
+    /**
162
+     * Generate the internal arrays containing the list of junk and non-junk
163
+     * characters for the second ($b) sequence.
164
+     */
165
+    private function chainB()
166
+    {
167
+        $length = count ($this->b);
168
+        $this->b2j = array();
169
+        $popularDict = array();
170
+
171
+        for($i = 0; $i < $length; ++$i) {
172
+            $char = $this->b[$i];
173
+            if(isset($this->b2j[$char])) {
174
+                if($length >= 200 && count($this->b2j[$char]) * 100 > $length) {
175
+                    $popularDict[$char] = 1;
176
+                    unset($this->b2j[$char]);
177
+                }
178
+                else {
179
+                    $this->b2j[$char][] = $i;
180
+                }
181
+            }
182
+            else {
183
+                $this->b2j[$char] = array(
184
+                    $i
185
+                );
186
+            }
187
+        }
188
+
189
+        // Remove leftovers
190
+        foreach(array_keys($popularDict) as $char) {
191
+            unset($this->b2j[$char]);
192
+        }
193
+
194
+        $this->junkDict = array();
195
+        if(is_callable($this->junkCallback)) {
196
+            foreach(array_keys($popularDict) as $char) {
197
+                if(call_user_func($this->junkCallback, $char)) {
198
+                    $this->junkDict[$char] = 1;
199
+                    unset($popularDict[$char]);
200
+                }
201
+            }
202
+
203
+            foreach(array_keys($this->b2j) as $char) {
204
+                if(call_user_func($this->junkCallback, $char)) {
205
+                    $this->junkDict[$char] = 1;
206
+                    unset($this->b2j[$char]);
207
+                }
208
+            }
209
+        }
210
+    }
211
+
212
+    /**
213
+     * Checks if a particular character is in the junk dictionary
214
+     * for the list of junk characters.
215
+     * @param $b
216
+     * @return boolean True if the character is considered junk. False if not.
217
+     */
218
+    private function isBJunk($b)
219
+    {
220
+        if(isset($this->juncDict[$b])) {
221
+            return true;
222
+        }
223
+
224
+        return false;
225
+    }
226
+
227
+    /**
228
+     * Find the longest matching block in the two sequences, as defined by the
229
+     * lower and upper constraints for each sequence. (for the first sequence,
230
+     * $alo - $ahi and for the second sequence, $blo - $bhi)
231
+     *
232
+     * Essentially, of all of the maximal matching blocks, return the one that
233
+     * startest earliest in $a, and all of those maximal matching blocks that
234
+     * start earliest in $a, return the one that starts earliest in $b.
235
+     *
236
+     * If the junk callback is defined, do the above but with the restriction
237
+     * that the junk element appears in the block. Extend it as far as possible
238
+     * by matching only junk elements in both $a and $b.
239
+     *
240
+     * @param int $alo The lower constraint for the first sequence.
241
+     * @param int $ahi The upper constraint for the first sequence.
242
+     * @param int $blo The lower constraint for the second sequence.
243
+     * @param int $bhi The upper constraint for the second sequence.
244
+     * @return array Array containing the longest match that includes the starting position in $a, start in $b and the length/size.
245
+     */
246
+    public function findLongestMatch($alo, $ahi, $blo, $bhi)
247
+    {
248
+        $a = $this->a;
249
+        $b = $this->b;
250
+
251
+        $bestI = $alo;
252
+        $bestJ = $blo;
253
+        $bestSize = 0;
254
+
255
+        $j2Len = array();
256
+        $nothing = array();
257
+
258
+        for($i = $alo; $i < $ahi; ++$i) {
259
+            $newJ2Len = array();
260
+            $jDict = $this->arrayGetDefault($this->b2j, $a[$i], $nothing);
261
+            foreach($jDict as $jKey => $j) {
262
+                if($j < $blo) {
263
+                    continue;
264
+                }
265
+                else if($j >= $bhi) {
266
+                    break;
267
+                }
268
+
269
+                $k = $this->arrayGetDefault($j2Len, $j -1, 0) + 1;
270
+                $newJ2Len[$j] = $k;
271
+                if($k > $bestSize) {
272
+                    $bestI = $i - $k + 1;
273
+                    $bestJ = $j - $k + 1;
274
+                    $bestSize = $k;
275
+                }
276
+            }
277
+
278
+            $j2Len = $newJ2Len;
279
+        }
280
+
281
+        while($bestI > $alo && $bestJ > $blo && !$this->isBJunk($b[$bestJ - 1]) &&
282
+            !$this->linesAreDifferent($bestI - 1, $bestJ - 1)) {
283
+                --$bestI;
284
+                --$bestJ;
285
+                ++$bestSize;
286
+        }
287
+
288
+        while($bestI + $bestSize < $ahi && ($bestJ + $bestSize) < $bhi &&
289
+            !$this->isBJunk($b[$bestJ + $bestSize]) && !$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)) {
290
+                ++$bestSize;
291
+        }
292
+
293
+        while($bestI > $alo && $bestJ > $blo && $this->isBJunk($b[$bestJ - 1]) &&
294
+            !$this->isLineDifferent($bestI - 1, $bestJ - 1)) {
295
+                --$bestI;
296
+                --$bestJ;
297
+                ++$bestSize;
298
+        }
299
+
300
+        while($bestI + $bestSize < $ahi && $bestJ + $bestSize < $bhi &&
301
+            $this->isBJunk($b[$bestJ + $bestSize]) && !$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)) {
302
+                    ++$bestSize;
303
+        }
304
+
305
+        return array(
306
+            $bestI,
307
+            $bestJ,
308
+            $bestSize
309
+        );
310
+    }
311
+
312
+    /**
313
+     * Check if the two lines at the given indexes are different or not.
314
+     *
315
+     * @param int $aIndex Line number to check against in a.
316
+     * @param int $bIndex Line number to check against in b.
317
+     * @return boolean True if the lines are different and false if not.
318
+     */
319
+    public function linesAreDifferent($aIndex, $bIndex)
320
+    {
321
+        $lineA = $this->a[$aIndex];
322
+        $lineB = $this->b[$bIndex];
323
+
324
+        if($this->options['ignoreWhitespace']) {
325
+            $replace = array("\t", ' ');
326
+            $lineA = str_replace($replace, '', $lineA);
327
+            $lineB = str_replace($replace, '', $lineB);
328
+        }
329
+
330
+        if($this->options['ignoreCase']) {
331
+            $lineA = strtolower($lineA);
332
+            $lineB = strtolower($lineB);
333
+        }
334
+
335
+        if($lineA != $lineB) {
336
+            return true;
337
+        }
338
+
339
+        return false;
340
+    }
341
+
342
+    /**
343
+     * Return a nested set of arrays for all of the matching sub-sequences
344
+     * in the strings $a and $b.
345
+     *
346
+     * Each block contains the lower constraint of the block in $a, the lower
347
+     * constraint of the block in $b and finally the number of lines that the
348
+     * block continues for.
349
+     *
350
+     * @return array Nested array of the matching blocks, as described by the function.
351
+     */
352
+    public function getMatchingBlocks()
353
+    {
354
+        if(!empty($this->matchingBlocks)) {
355
+            return $this->matchingBlocks;
356
+        }
357
+
358
+        $aLength = count($this->a);
359
+        $bLength = count($this->b);
360
+
361
+        $queue = array(
362
+            array(
363
+                0,
364
+                $aLength,
365
+                0,
366
+                $bLength
367
+            )
368
+        );
369
+
370
+        $matchingBlocks = array();
371
+        while(!empty($queue)) {
372
+            list($alo, $ahi, $blo, $bhi) = array_pop($queue);
373
+            $x = $this->findLongestMatch($alo, $ahi, $blo, $bhi);
374
+            list($i, $j, $k) = $x;
375
+            if($k) {
376
+                $matchingBlocks[] = $x;
377
+                if($alo < $i && $blo < $j) {
378
+                    $queue[] = array(
379
+                        $alo,
380
+                        $i,
381
+                        $blo,
382
+                        $j
383
+                    );
384
+                }
385
+
386
+                if($i + $k < $ahi && $j + $k < $bhi) {
387
+                    $queue[] = array(
388
+                        $i + $k,
389
+                        $ahi,
390
+                        $j + $k,
391
+                        $bhi
392
+                    );
393
+                }
394
+            }
395
+        }
396
+
397
+        usort($matchingBlocks, array($this, 'tupleSort'));
398
+
399
+        $i1 = 0;
400
+        $j1 = 0;
401
+        $k1 = 0;
402
+        $nonAdjacent = array();
403
+        foreach($matchingBlocks as $block) {
404
+            list($i2, $j2, $k2) = $block;
405
+            if($i1 + $k1 == $i2 && $j1 + $k1 == $j2) {
406
+                $k1 += $k2;
407
+            }
408
+            else {
409
+                if($k1) {
410
+                    $nonAdjacent[] = array(
411
+                        $i1,
412
+                        $j1,
413
+                        $k1
414
+                    );
415
+                }
416
+
417
+                $i1 = $i2;
418
+                $j1 = $j2;
419
+                $k1 = $k2;
420
+            }
421
+        }
422
+
423
+        if($k1) {
424
+            $nonAdjacent[] = array(
425
+                $i1,
426
+                $j1,
427
+                $k1
428
+            );
429
+        }
430
+
431
+        $nonAdjacent[] = array(
432
+            $aLength,
433
+            $bLength,
434
+            0
435
+        );
436
+
437
+        $this->matchingBlocks = $nonAdjacent;
438
+        return $this->matchingBlocks;
439
+    }
440
+
441
+    /**
442
+     * Return a list of all of the opcodes for the differences between the
443
+     * two strings.
444
+     *
445
+     * The nested array returned contains an array describing the opcode
446
+     * which includes:
447
+     * 0 - The type of tag (as described below) for the opcode.
448
+     * 1 - The beginning line in the first sequence.
449
+     * 2 - The end line in the first sequence.
450
+     * 3 - The beginning line in the second sequence.
451
+     * 4 - The end line in the second sequence.
452
+     *
453
+     * The different types of tags include:
454
+     * replace - The string from $i1 to $i2 in $a should be replaced by
455
+     *           the string in $b from $j1 to $j2.
456
+     * delete -  The string in $a from $i1 to $j2 should be deleted.
457
+     * insert -  The string in $b from $j1 to $j2 should be inserted at
458
+     *           $i1 in $a.
459
+     * equal  -  The two strings with the specified ranges are equal.
460
+     *
461
+     * @return array Array of the opcodes describing the differences between the strings.
462
+     */
463
+    public function getOpCodes()
464
+    {
465
+        if(!empty($this->opCodes)) {
466
+            return $this->opCodes;
467
+        }
468
+
469
+        $i = 0;
470
+        $j = 0;
471
+        $this->opCodes = array();
472
+
473
+        $blocks = $this->getMatchingBlocks();
474
+        foreach($blocks as $block) {
475
+            list($ai, $bj, $size) = $block;
476
+            $tag = '';
477
+            if($i < $ai && $j < $bj) {
478
+                $tag = 'replace';
479
+            }
480
+            else if($i < $ai) {
481
+                $tag = 'delete';
482
+            }
483
+            else if($j < $bj) {
484
+                $tag = 'insert';
485
+            }
486
+
487
+            if($tag) {
488
+                $this->opCodes[] = array(
489
+                    $tag,
490
+                    $i,
491
+                    $ai,
492
+                    $j,
493
+                    $bj
494
+                );
495
+            }
496
+
497
+            $i = $ai + $size;
498
+            $j = $bj + $size;
499
+
500
+            if($size) {
501
+                $this->opCodes[] = array(
502
+                    'equal',
503
+                    $ai,
504
+                    $i,
505
+                    $bj,
506
+                    $j
507
+                );
508
+            }
509
+        }
510
+        return $this->opCodes;
511
+    }
512
+
513
+    /**
514
+     * Return a series of nested arrays containing different groups of generated
515
+     * opcodes for the differences between the strings with up to $context lines
516
+     * of surrounding content.
517
+     *
518
+     * Essentially what happens here is any big equal blocks of strings are stripped
519
+     * out, the smaller subsets of changes are then arranged in to their groups.
520
+     * This means that the sequence matcher and diffs do not need to include the full
521
+     * content of the different files but can still provide context as to where the
522
+     * changes are.
523
+     *
524
+     * @param int $context The number of lines of context to provide around the groups.
525
+     * @return array Nested array of all of the grouped opcodes.
526
+     */
527
+    public function getGroupedOpcodes($context=3)
528
+    {
529
+        $opCodes = $this->getOpCodes();
530
+        if(empty($opCodes)) {
531
+            $opCodes = array(
532
+                array(
533
+                    'equal',
534
+                    0,
535
+                    1,
536
+                    0,
537
+                    1
538
+                )
539
+            );
540
+        }
541
+
542
+        if($opCodes[0][0] == 'equal') {
543
+            $opCodes[0] = array(
544
+                $opCodes[0][0],
545
+                max($opCodes[0][1], $opCodes[0][2] - $context),
546
+                $opCodes[0][2],
547
+                max($opCodes[0][3], $opCodes[0][4] - $context),
548
+                $opCodes[0][4]
549
+            );
550
+        }
551
+
552
+        $lastItem = count($opCodes) - 1;
553
+        if($opCodes[$lastItem][0] == 'equal') {
554
+            list($tag, $i1, $i2, $j1, $j2) = $opCodes[$lastItem];
555
+            $opCodes[$lastItem] = array(
556
+                $tag,
557
+                $i1,
558
+                min($i2, $i1 + $context),
559
+                $j1,
560
+                min($j2, $j1 + $context)
561
+            );
562
+        }
563
+
564
+        $maxRange = $context * 2;
565
+        $groups = array();
566
+        $group = array();
567
+        foreach($opCodes as $code) {
568
+            list($tag, $i1, $i2, $j1, $j2) = $code;
569
+            if($tag == 'equal' && $i2 - $i1 > $maxRange) {
570
+                $group[] = array(
571
+                    $tag,
572
+                    $i1,
573
+                    min($i2, $i1 + $context),
574
+                    $j1,
575
+                    min($j2, $j1 + $context)
576
+                );
577
+                $groups[] = $group;
578
+                $group = array();
579
+                $i1 = max($i1, $i2 - $context);
580
+                $j1 = max($j1, $j2 - $context);
581
+            }
582
+            $group[] = array(
583
+                $tag,
584
+                $i1,
585
+                $i2,
586
+                $j1,
587
+                $j2
588
+            );
589
+        }
590
+
591
+        if(!empty($group) && !(count($group) == 1 && $group[0][0] == 'equal')) {
592
+            $groups[] = $group;
593
+        }
594
+
595
+        return $groups;
596
+    }
597
+
598
+    /**
599
+     * Return a measure of the similarity between the two sequences.
600
+     * This will be a float value between 0 and 1.
601
+     *
602
+     * Out of all of the ratio calculation functions, this is the most
603
+     * expensive to call if getMatchingBlocks or getOpCodes is yet to be
604
+     * called. The other calculation methods (quickRatio and realquickRatio)
605
+     * can be used to perform quicker calculations but may be less accurate.
606
+     *
607
+     * The ratio is calculated as (2 * number of matches) / total number of
608
+     * elements in both sequences.
609
+     *
610
+     * @return float The calculated ratio.
611
+     */
612
+    public function Ratio()
613
+    {
614
+        $matches = array_reduce($this->getMatchingBlocks(), array($this, 'ratioReduce'), 0);
615
+        return $this->calculateRatio($matches, count ($this->a) + count ($this->b));
616
+    }
617
+
618
+    /**
619
+     * Helper function to calculate the number of matches for Ratio().
620
+     *
621
+     * @param int $sum The running total for the number of matches.
622
+     * @param array $triple Array containing the matching block triple to add to the running total.
623
+     * @return int The new running total for the number of matches.
624
+     */
625
+    private function ratioReduce($sum, $triple)
626
+    {
627
+        return $sum + ($triple[count($triple) - 1]);
628
+    }
629
+
630
+    /**
631
+     * Quickly return an upper bound ratio for the similarity of the strings.
632
+     * This is quicker to compute than Ratio().
633
+     *
634
+     * @return float The calculated ratio.
635
+     */
636
+    private function quickRatio()
637
+    {
638
+        if($this->fullBCount === null) {
639
+            $this->fullBCount = array();
640
+            $bLength = count ($this->b);
641
+            for($i = 0; $i < $bLength; ++$i) {
642
+                $char = $this->b[$i];
643
+                $this->fullBCount[$char] = $this->arrayGetDefault($this->fullBCount, $char, 0) + 1;
644
+            }
645
+        }
646
+
647
+        $avail = array();
648
+        $matches = 0;
649
+        $aLength = count ($this->a);
650
+        for($i = 0; $i < $aLength; ++$i) {
651
+            $char = $this->a[$i];
652
+            if(isset($avail[$char])) {
653
+                $numb = $avail[$char];
654
+            }
655
+            else {
656
+                $numb = $this->arrayGetDefault($this->fullBCount, $char, 0);
657
+            }
658
+            $avail[$char] = $numb - 1;
659
+            if($numb > 0) {
660
+                ++$matches;
661
+            }
662
+        }
663
+
664
+        $this->calculateRatio($matches, count ($this->a) + count ($this->b));
665
+    }
666
+
667
+    /**
668
+     * Return an upper bound ratio really quickly for the similarity of the strings.
669
+     * This is quicker to compute than Ratio() and quickRatio().
670
+     *
671
+     * @return float The calculated ratio.
672
+     */
673
+    private function realquickRatio()
674
+    {
675
+        $aLength = count ($this->a);
676
+        $bLength = count ($this->b);
677
+
678
+        return $this->calculateRatio(min($aLength, $bLength), $aLength + $bLength);
679
+    }
680
+
681
+    /**
682
+     * Helper function for calculating the ratio to measure similarity for the strings.
683
+     * The ratio is defined as being 2 * (number of matches / total length)
684
+     *
685
+     * @param int $matches The number of matches in the two strings.
686
+     * @param int $length The length of the two strings.
687
+     * @return float The calculated ratio.
688
+     */
689
+    private function calculateRatio($matches, $length=0)
690
+    {
691
+        if($length) {
692
+            return 2 * ($matches / $length);
693
+        }
694
+        else {
695
+            return 1;
696
+        }
697
+    }
698
+
699
+    /**
700
+     * Helper function that provides the ability to return the value for a key
701
+     * in an array of it exists, or if it doesn't then return a default value.
702
+     * Essentially cleaner than doing a series of if(isset()) {} else {} calls.
703
+     *
704
+     * @param array $array The array to search.
705
+     * @param string $key The key to check that exists.
706
+     * @param mixed $default The value to return as the default value if the key doesn't exist.
707
+     * @return mixed The value from the array if the key exists or otherwise the default.
708
+     */
709
+    private function arrayGetDefault($array, $key, $default)
710
+    {
711
+        if(isset($array[$key])) {
712
+            return $array[$key];
713
+        }
714
+        else {
715
+            return $default;
716
+        }
717
+    }
718
+
719
+    /**
720
+     * Sort an array by the nested arrays it contains. Helper function for getMatchingBlocks
721
+     *
722
+     * @param array $a First array to compare.
723
+     * @param array $b Second array to compare.
724
+     * @return int -1, 0 or 1, as expected by the usort function.
725
+     */
726
+    private function tupleSort($a, $b)
727
+    {
728
+        $max = max(count($a), count($b));
729
+        for($i = 0; $i < $max; ++$i) {
730
+            if($a[$i] < $b[$i]) {
731
+                return -1;
732
+            }
733
+            else if($a[$i] > $b[$i]) {
734
+                return 1;
735
+            }
736
+        }
737
+
738
+        if(count($a) == count($b)) {
739
+            return 0;
740
+        }
741
+        else if(count($a) < count($b)) {
742
+            return -1;
743
+        }
744
+        else {
745
+            return 1;
746
+        }
747
+    }
748 748
 }
749 749
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/phpspec/phpspec/features/bootstrap/ApplicationContext.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-use Behat\Behat\Tester\Exception\PendingException;
4 3
 use Behat\Behat\Context\Context;
5 4
 use Behat\Gherkin\Node\PyStringNode;
6
-use Behat\Gherkin\Node\TableNode;
7 5
 use Fake\Prompter;
8 6
 use Fake\ReRunner;
9 7
 use Matcher\ApplicationOutputMatcher;
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      */
98 98
     public function iRunPhpspec($formatter = null, $option = null, $interactive = null, $spec = null)
99 99
     {
100
-        $arguments = array (
100
+        $arguments = array(
101 101
             'command' => 'run',
102 102
             'spec' => $spec
103 103
         );
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         $this->addOptionToArguments($option, $arguments);
110 110
 
111 111
         $this->lastExitCode = $this->tester->run($arguments, array(
112
-            'interactive' => (bool)$interactive,
112
+            'interactive' => (bool) $interactive,
113 113
             'decorated' => false,
114 114
         ));
115 115
     }
@@ -118,15 +118,15 @@  discard block
 block discarded – undo
118 118
      * @When I run phpspec and answer :answer when asked if I want to generate the code
119 119
      * @When I run phpspec with the option :option and (I) answer :answer when asked if I want to generate the code
120 120
      */
121
-    public function iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode($answer, $option=null)
121
+    public function iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode($answer, $option = null)
122 122
     {
123
-        $arguments = array (
123
+        $arguments = array(
124 124
             'command' => 'run'
125 125
         );
126 126
 
127 127
         $this->addOptionToArguments($option, $arguments);
128 128
 
129
-        $this->prompter->setAnswer($answer=='y');
129
+        $this->prompter->setAnswer($answer == 'y');
130 130
 
131 131
         $this->lastExitCode = $this->tester->run($arguments, array('interactive' => true));
132 132
     }
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
      */
137 137
     public function iRunPhpspecAndAnswerToBothQuestions($answer)
138 138
     {
139
-        $arguments = array (
139
+        $arguments = array(
140 140
             'command' => 'run'
141 141
         );
142 142
 
143
-        $this->prompter->setAnswer($answer=='y');
144
-        $this->prompter->setAnswer($answer=='y');
143
+        $this->prompter->setAnswer($answer == 'y');
144
+        $this->prompter->setAnswer($answer == 'y');
145 145
 
146 146
         $this->lastExitCode = $this->tester->run($arguments, array('interactive' => true));
147 147
     }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             if (preg_match('/(?P<option>[a-z-]+)=(?P<value>[a-z.]+)/', $option, $matches)) {
157 157
                 $arguments[$matches['option']] = $matches['value'];
158 158
             } else {
159
-                $arguments['--' . trim($option, '"')] = true;
159
+                $arguments['--'.trim($option, '"')] = true;
160 160
             }
161 161
         }
162 162
     }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
      */
168 168
     public function iShouldSee($output)
169 169
     {
170
-        expect($this->tester)->toHaveOutput((string)$output);
170
+        expect($this->tester)->toHaveOutput((string) $output);
171 171
     }
172 172
 
173 173
     /**
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      */
256 256
     public function iShouldBePromptedWith(PyStringNode $question)
257 257
     {
258
-        expect($this->prompter)->toHaveBeenAsked((string)$question);
258
+        expect($this->prompter)->toHaveBeenAsked((string) $question);
259 259
     }
260 260
 
261 261
     /**
@@ -278,12 +278,12 @@  discard block
 block discarded – undo
278 278
      */
279 279
     public function iRunPhpspecWithConfigAndAnswerIfIWantToGenerateTheCode($config, $answer)
280 280
     {
281
-        $arguments = array (
281
+        $arguments = array(
282 282
             'command' => 'run',
283 283
             '--config' => $config
284 284
         );
285 285
 
286
-        $this->prompter->setAnswer($answer=='y');
286
+        $this->prompter->setAnswer($answer == 'y');
287 287
 
288 288
         $this->lastExitCode = $this->tester->run($arguments, array('interactive' => true));
289 289
     }
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
      */
307 307
     public function iRunPhpspecWithTheSpec($spec)
308 308
     {
309
-        $arguments = array (
309
+        $arguments = array(
310 310
             'command' => 'run',
311 311
             1 => $spec
312 312
         );
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      */
320 320
     public function iRunPhpspecWithTheSpecAndTheConfig($spec, $config)
321 321
     {
322
-        $arguments = array (
322
+        $arguments = array(
323 323
             'command' => 'run',
324 324
             1 => $spec,
325 325
             '--config' => $config
Please login to merge, or discard this patch.
phpspec/phpspec/spec/PhpSpec/CodeAnalysis/MagicAwareAccessInspectorSpec.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use Phpspec\CodeAnalysis\AccessInspectorInterface;
6 6
 use PhpSpec\ObjectBehavior;
7
-use Prophecy\Argument;
8 7
 
9 8
 class MagicAwareAccessInspectorSpec extends ObjectBehavior
10 9
 {
Please login to merge, or discard this patch.
phpspec/spec/PhpSpec/CodeAnalysis/StaticRejectingNamespaceResolverSpec.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use PhpSpec\CodeAnalysis\NamespaceResolver;
6 6
 use PhpSpec\ObjectBehavior;
7
-use Prophecy\Argument;
8 7
 
9 8
 class StaticRejectingNamespaceResolverSpec extends ObjectBehavior
10 9
 {
Please login to merge, or discard this patch.