@@ -112,15 +112,15 @@ private function collectLongLinesData(File $file, int $start): array
112112 $ lastLine = null ;
113113 for ($ i = $ start ; $ i < $ file ->numTokens ; $ i ++) {
114114 // Still processing previous line: increment length and continue.
115- if ($ lastLine && ($ tokens [$ i ]['line ' ] === $ lastLine )) {
115+ if (( $ lastLine !== null ) && ( $ lastLine > 0 ) && ($ tokens [$ i ]['line ' ] === $ lastLine )) {
116116 $ content = (string ) $ tokens [$ i ]['content ' ];
117117 $ data [$ lastLine ]['length ' ] += strlen ($ content );
118118 $ data [$ lastLine ]['nonEmptyLength ' ] += strlen (trim ($ content ));
119119 continue ;
120120 }
121121
122122 // A new line started: let's set "end" for the previous line (if this isn't 1st line)
123- if ($ lastLine && isset ($ data [$ lastLine ])) {
123+ if (( $ lastLine !== null ) && ( $ lastLine > 0 ) && isset ($ data [$ lastLine ])) {
124124 $ data [$ lastLine ]['end ' ] = $ i - 1 ;
125125 }
126126
@@ -135,32 +135,45 @@ private function collectLongLinesData(File $file, int $start): array
135135 }
136136
137137 // We still have to set the "end" for last file line.
138- if ($ lastLine && ($ data [$ lastLine ]['end ' ] === null )) {
138+ if (($ lastLine !== null ) && ($ lastLine > 0 ) && ($ data [$ lastLine ]['end ' ] === null )) {
139+ /** @var int $lastLine */
139140 $ data [$ lastLine ]['end ' ] = $ i - 1 ;
140141 }
141142
142143 $ longLines = [];
144+ /**
145+ * @var int $lineNumber
146+ * @var array{length:int, nonEmptyLength:int, start:int, end:int|null} $lineData
147+ */
143148 foreach ($ data as $ lineNumber => $ lineData ) {
144- $ lineEnd = $ lineData ['end ' ] ?? $ lineData ['start ' ];
145- if (
146- (($ lineData ['length ' ] - $ this ->lineLimit ) <= 1 ) // 1 char of tolerance
147- || ($ lineData ['nonEmptyLength ' ] === 0 ) // ignore empty lines
148- || $ this ->isLongUse ($ file , $ tokens , $ lineData ['start ' ], $ lineEnd )
149- || $ this ->isLongI10nFunction ($ file , $ tokens , $ lineData ['start ' ], $ lineEnd )
150- || $ this ->isLongWord ($ file , $ tokens , $ lineData ['start ' ], $ lineEnd )
151- ) {
152- continue ;
149+ if (!$ this ->isLengthAcceptable ($ lineData , $ file , $ tokens )) {
150+ $ longLines [$ lineNumber ] = [$ lineData ['length ' ], $ lineData ['start ' ]];
153151 }
154-
155- $ longLines [$ lineNumber ] = [$ lineData ['length ' ], $ lineData ['start ' ]];
156152 }
157153
158154 return $ longLines ;
159155 }
160156
157+ /**
158+ * @param array{length:int, nonEmptyLength:int, start:int, end:int|null} $lineData
159+ * @param File $file
160+ * @param array<int, array<string, mixed>> $tokens
161+ * @return bool
162+ */
163+ private function isLengthAcceptable (array $ lineData , File $ file , array $ tokens ): bool
164+ {
165+ $ lineEnd = $ lineData ['end ' ] ?? $ lineData ['start ' ];
166+
167+ return (($ lineData ['length ' ] - $ this ->lineLimit ) <= 1 ) // 1 char of tolerance
168+ || ($ lineData ['nonEmptyLength ' ] === 0 ) // ignore empty lines
169+ || $ this ->isLongUse ($ file , $ tokens , $ lineData ['start ' ], $ lineEnd )
170+ || $ this ->isLongI10nFunction ($ file , $ tokens , $ lineData ['start ' ], $ lineEnd )
171+ || $ this ->isLongWord ($ file , $ tokens , $ lineData ['start ' ], $ lineEnd );
172+ }
173+
161174 /**
162175 * We don't want to split a single word in multiple lines.
163- * So if there's a long word (e.g. an URL) that alone is above max line length, we don't show
176+ * So if there's a long word (e.g. a URL) that alone is above max line length, we don't show
164177 * warnings for it.
165178 *
166179 * @param File $file
0 commit comments