@@ -25,11 +25,7 @@ final class Differ
2525 */
2626 private $ showNonDiffLines ;
2727
28- /**
29- * @param string $header
30- * @param bool $showNonDiffLines
31- */
32- public function __construct ($ header = "--- Original \n+++ New \n" , $ showNonDiffLines = true )
28+ public function __construct (string $ header = "--- Original \n+++ New \n" , bool $ showNonDiffLines = true )
3329 {
3430 $ this ->header = $ header ;
3531 $ this ->showNonDiffLines = $ showNonDiffLines ;
@@ -38,13 +34,13 @@ public function __construct($header = "--- Original\n+++ New\n", $showNonDiffLin
3834 /**
3935 * Returns the diff between two arrays or strings as string.
4036 *
41- * @param array|string $from
42- * @param array|string $to
43- * @param LongestCommonSubsequenceCalculator $lcs
37+ * @param array|string $from
38+ * @param array|string $to
39+ * @param LongestCommonSubsequenceCalculator|null $lcs
4440 *
4541 * @return string
4642 */
47- public function diff ($ from , $ to , LongestCommonSubsequenceCalculator $ lcs = null )
43+ public function diff ($ from , $ to , LongestCommonSubsequenceCalculator $ lcs = null ): string
4844 {
4945 $ from = $ this ->validateDiffInput ($ from );
5046 $ to = $ this ->validateDiffInput ($ to );
@@ -63,7 +59,7 @@ public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
6359 *
6460 * @return string
6561 */
66- private function validateDiffInput ($ input )
62+ private function validateDiffInput ($ input ): string
6763 {
6864 if (!\is_array ($ input ) && !\is_string ($ input )) {
6965 return (string ) $ input ;
@@ -80,7 +76,7 @@ private function validateDiffInput($input)
8076 *
8177 * @return array
8278 */
83- private function checkIfDiffInOld (array $ diff )
79+ private function checkIfDiffInOld (array $ diff ): array
8480 {
8581 $ inOld = false ;
8682 $ i = 0 ;
@@ -115,7 +111,7 @@ private function checkIfDiffInOld(array $diff)
115111 *
116112 * @return string
117113 */
118- private function getBuffer (array $ diff , array $ old , $ start , $ end )
114+ private function getBuffer (array $ diff , array $ old , int $ start , int $ end ): string
119115 {
120116 $ buffer = $ this ->header ;
121117
@@ -145,7 +141,7 @@ private function getBuffer(array $diff, array $old, $start, $end)
145141 *
146142 * @return string
147143 */
148- private function getDiffBufferElement (array $ diff , $ buffer , $ diffIndex )
144+ private function getDiffBufferElement (array $ diff , string $ buffer , int $ diffIndex ): string
149145 {
150146 if ($ diff [$ diffIndex ][1 ] === 1 /* ADDED */ ) {
151147 $ buffer .= '+ ' . $ diff [$ diffIndex ][0 ] . "\n" ;
@@ -167,7 +163,7 @@ private function getDiffBufferElement(array $diff, $buffer, $diffIndex)
167163 *
168164 * @return string
169165 */
170- private function getDiffBufferElementNew (array $ diff , $ buffer , $ diffIndex )
166+ private function getDiffBufferElementNew (array $ diff , string $ buffer , int $ diffIndex ): string
171167 {
172168 if ($ this ->showNonDiffLines === true ) {
173169 $ buffer .= "@@ @@ \n" ;
@@ -193,7 +189,7 @@ private function getDiffBufferElementNew(array $diff, $buffer, $diffIndex)
193189 *
194190 * @return array
195191 */
196- public function diffToArray ($ from , $ to , LongestCommonSubsequenceCalculator $ lcs = null )
192+ public function diffToArray ($ from , $ to , LongestCommonSubsequenceCalculator $ lcs = null ): array
197193 {
198194 if (\is_string ($ from )) {
199195 $ fromMatches = $ this ->getNewLineMatches ($ from );
@@ -273,7 +269,7 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
273269 *
274270 * @return array
275271 */
276- private function getNewLineMatches ($ string )
272+ private function getNewLineMatches (string $ string ): array
277273 {
278274 \preg_match_all ('(\r\n|\r|\n) ' , $ string , $ stringMatches );
279275
@@ -287,7 +283,7 @@ private function getNewLineMatches($string)
287283 *
288284 * @return array
289285 */
290- private function splitStringByLines ($ input )
286+ private function splitStringByLines (string $ input ): array
291287 {
292288 return \preg_split ('(\r\n|\r|\n) ' , $ input );
293289 }
@@ -298,7 +294,7 @@ private function splitStringByLines($input)
298294 *
299295 * @return LongestCommonSubsequenceCalculator
300296 */
301- private function selectLcsImplementation (array $ from , array $ to )
297+ private function selectLcsImplementation (array $ from , array $ to ): LongestCommonSubsequenceCalculator
302298 {
303299 // We do not want to use the time-efficient implementation if its memory
304300 // footprint will probably exceed this value. Note that the footprint
@@ -336,20 +332,14 @@ private function calculateEstimatedFootprint(array $from, array $to)
336332 *
337333 * @return bool
338334 */
339- private function detectUnmatchedLineEndings (array $ fromMatches , array $ toMatches )
335+ private function detectUnmatchedLineEndings (array $ fromMatches , array $ toMatches ): bool
340336 {
341337 return isset ($ fromMatches [0 ], $ toMatches [0 ]) &&
342338 \count ($ fromMatches [0 ]) === \count ($ toMatches [0 ]) &&
343339 $ fromMatches [0 ] !== $ toMatches [0 ];
344340 }
345341
346- /**
347- * @param array $from
348- * @param array $to
349- *
350- * @return array
351- */
352- private static function getArrayDiffParted (array &$ from , array &$ to )
342+ private static function getArrayDiffParted (array &$ from , array &$ to ): array
353343 {
354344 $ start = [];
355345 $ end = [];
0 commit comments