@@ -46,6 +46,12 @@ class MaxLineLengthRule implements Rule
4646 */
4747 private array $ processedLines = [];
4848
49+ /**
50+ * @var array<string, array<int, bool>>
51+ * Cache of which lines contain use statements per file
52+ */
53+ private array $ useStatementLines = [];
54+
4955 /**
5056 * @param string[] $excludePatterns
5157 */
@@ -76,14 +82,24 @@ public function processNode(Node $node, Scope $scope): array
7682 return [];
7783 }
7884
79- // Skip use statements if configured to ignore them
80- if ($ this ->ignoreUseStatements && $ node instanceof Use_) {
81- return [];
82- }
83-
8485 $ filePath = $ scope ->getFile ();
8586 $ lineNumber = $ node ->getLine ();
8687
88+ // Track use statement lines for this file
89+ if ($ node instanceof Use_) {
90+ $ this ->markLineAsUseStatement ($ filePath , $ lineNumber );
91+
92+ // If ignoring use statements, skip processing this node
93+ if ($ this ->ignoreUseStatements ) {
94+ return [];
95+ }
96+ }
97+
98+ // Skip if this line is a use statement and we're ignoring them
99+ if ($ this ->ignoreUseStatements && $ this ->isUseStatementLine ($ filePath , $ lineNumber )) {
100+ return [];
101+ }
102+
87103 // Skip if we've already processed this line
88104 if ($ this ->isLineProcessed ($ filePath , $ lineNumber )) {
89105 return [];
@@ -137,6 +153,20 @@ private function markLineAsProcessed(string $filePath, int $lineNumber): void
137153 $ this ->processedLines [$ filePath ][$ lineNumber ] = true ;
138154 }
139155
156+ private function isUseStatementLine (string $ filePath , int $ lineNumber ): bool
157+ {
158+ return isset ($ this ->useStatementLines [$ filePath ][$ lineNumber ]);
159+ }
160+
161+ private function markLineAsUseStatement (string $ filePath , int $ lineNumber ): void
162+ {
163+ if (!isset ($ this ->useStatementLines [$ filePath ])) {
164+ $ this ->useStatementLines [$ filePath ] = [];
165+ }
166+
167+ $ this ->useStatementLines [$ filePath ][$ lineNumber ] = true ;
168+ }
169+
140170 private function getLineLength (string $ filePath , int $ lineNumber ): int
141171 {
142172 // Cache file line lengths to avoid reading the same file multiple times
0 commit comments