Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 38aa821

Browse files
committed
fixed logic in ReferenceUsedNamesAfterUsageSniff
1 parent 3159be2 commit 38aa821

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

‎InfinityloopCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesAfterUsageSniff.php‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,29 +174,29 @@ public function process(File $phpcsFile, $openTagPointer) : void
174174
$lineLength = \strlen(TokenHelper::getContent($phpcsFile, $start, $end));
175175

176176
if (!$shouldBeUsed
177-
|| ($this->count !== null && $referenced[$canonicalName] < $this->count)
178-
&& ($this->length !== null && $this->length > \strlen($canonicalName))
179-
&& ($this->lineLength !== null && $this->lineClassLength !== null && ($this->lineClassLength >= \strlen($canonicalName)
180-
|| $this->lineLength >= $lineLength))
177+
|| ($this->count === null || $this->count > $referenced[$canonicalName])
178+
&& ($this->length === null || $this->length > \strlen($canonicalName))
179+
&& ($this->lineLength === null || $this->lineClassLength === null || $this->lineClassLength > \strlen($canonicalName)
180+
|| $this->lineLength > $lineLength)
181181
) {
182182
continue;
183183
}
184184

185185
$reason = '';
186186

187-
if ($referenced[$canonicalName] >= $this->count) {
187+
if ($this->count !== null && $referenced[$canonicalName] >= $this->count) {
188188
$reason = 'because it\'s used more than ' . $this->count . ' times.';
189189
}
190190

191-
if ($this->length !== null && $this->length < \strlen($canonicalName)) {
191+
if ($this->length !== null && $this->length <= \strlen($canonicalName)) {
192192
$reason = $reason === ''
193193
? 'because it\'s length is more than ' . $this->length . ' symbols.'
194194
: 'because it\'s used more than ' . $this->count . ' times and it\'s length is more than '
195-
. $this->length . ' symbols.';
195+
. $this->length . ' symbols.';
196196
}
197197

198-
if ($this->lineLength !== null && $this->lineClassLength !== null && \strlen($canonicalName) > $this->lineClassLength
199-
&& $lineLength > $this->lineLength) {
198+
if ($this->lineLength !== null && $this->lineClassLength !== null && \strlen($canonicalName) >= $this->lineClassLength
199+
&& $lineLength >= $this->lineLength) {
200200
$reason = 'because line length is more than ' . $this->lineLength
201201
. ' symbols and class length is more than ' . $this->lineClassLength . ' symbols.';
202202
}
@@ -485,7 +485,7 @@ private function getUniqueNameFromNamespace(string $first, string $second) : arr
485485
private function getNormalizedClassName(string $name, array $useStatements, File $phpcsFile) : array
486486
{
487487
$unqualifiedName = NamespaceHelper::getUnqualifiedNameFromFullyQualifiedName($name);
488-
$className = ClassHelper::getName($phpcsFile, TokenHelper::findNext($phpcsFile, \T_CLASS, 0));
488+
$className = ClassHelper::getName($phpcsFile, TokenHelper::findNext($phpcsFile, [\T_CLASS, \T_INTERFACE, T_TRAIT], 0));
489489

490490
if ($className === $unqualifiedName) {
491491
return $this->getUniqueNameFromNamespace(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /