@@ -70,17 +70,10 @@ public function __construct(array $options = [])
7070 throw new ConfigurationException ('commonLineThreshold ' , 'an int > 0 ' , $ options ['commonLineThreshold ' ]);
7171 }
7272
73- foreach (['fromFile ' , 'toFile ' ] as $ option ) {
74- if (!\is_string ($ options [$ option ])) {
75- throw new ConfigurationException ($ option , 'a string ' , $ options [$ option ]);
76- }
77- }
78-
79- foreach (['fromFileDate ' , 'toFileDate ' ] as $ option ) {
80- if (null !== $ options [$ option ] && !\is_string ($ options [$ option ])) {
81- throw new ConfigurationException ($ option , 'a string or <null> ' , $ options [$ option ]);
82- }
83- }
73+ $ this ->assertString ($ options , 'fromFile ' );
74+ $ this ->assertString ($ options , 'toFile ' );
75+ $ this ->assertStringOrNull ($ options , 'fromFileDate ' );
76+ $ this ->assertStringOrNull ($ options , 'toFileDate ' );
8477
8578 $ this ->header = \sprintf (
8679 "--- %s%s \n+++ %s%s \n" ,
@@ -166,7 +159,9 @@ private function writeDiffHunks($output, array $diff): void
166159 $ hunkCapture = false ;
167160 $ sameCount = $ toRange = $ fromRange = 0 ;
168161 $ toStart = $ fromStart = 1 ;
162+ $ i = 0 ;
169163
164+ /** @var int $i */
170165 foreach ($ diff as $ i => $ entry ) {
171166 if (0 === $ entry [1 ]) { // same
172167 if (false === $ hunkCapture ) {
@@ -312,4 +307,18 @@ private function writeHunk(
312307 //}
313308 }
314309 }
310+
311+ private function assertString (array $ options , string $ option ): void
312+ {
313+ if (!is_string ($ options [$ option ])) {
314+ throw new ConfigurationException ($ option , 'a string ' , $ options [$ option ]);
315+ }
316+ }
317+
318+ private function assertStringOrNull (array $ options , string $ option ): void
319+ {
320+ if (null !== $ options [$ option ] && !\is_string ($ options [$ option ])) {
321+ throw new ConfigurationException ($ option , 'a string or <null> ' , $ options [$ option ]);
322+ }
323+ }
315324}
0 commit comments