Skip to content

Commit 5269229

Browse files
committed
Class constant is not a referenced name (fixes #21)
1 parent 0ae638c commit 5269229

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

SlevomatCodingStandard/Helpers/ReferencedNameHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ private static function isReferencedName(PHP_CodeSniffer_File $phpcsFile, $start
161161
T_DOUBLE_COLON,
162162
T_OBJECT_OPERATOR,
163163
T_NAMESPACE,
164+
T_CONST,
164165
];
165166

166167
if ($previousToken['code'] === T_USE) {

tests/Helpers/ReferencedNameHelperTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,13 @@ public function testReturnTypehint()
9999
$this->assertSame('\OtherNamespace\Lorem', $names[1]->getNameAsReferencedInFile());
100100
}
101101

102+
public function testConstantIsNotReferencedName()
103+
{
104+
$codeSnifferFile = $this->getCodeSnifferFile(
105+
__DIR__ . '/data/class-constant.php'
106+
);
107+
$names = ReferencedNameHelper::getAllReferencedNames($codeSnifferFile, 0);
108+
$this->assertCount(0, $names);
109+
}
110+
102111
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
class Foo
4+
{
5+
6+
const URL = 'bar';
7+
8+
}

tests/Sniffs/Namespaces/UnusedUsesSniffTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,10 @@ public function testTypeWithUnderscoresInAnnotation()
8686
$this->assertNoSniffError($report, 5);
8787
}
8888

89+
public function testMatchingCaseOfUseAndClassConstant()
90+
{
91+
$report = $this->checkFile(__DIR__ . '/data/matchingCaseOfUseAndClassConstant.php');
92+
$this->assertNoSniffErrorInFile($report);
93+
}
94+
8995
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Hele\Sms;
4+
5+
use Nette\Http\Url;
6+
7+
class Test
8+
{
9+
10+
const URL = 'https://foo.com';
11+
12+
public function sendMessage()
13+
{
14+
$url = new Url(self::URL);
15+
$url->getAbsoluteUrl();
16+
}
17+
18+
}

0 commit comments

Comments
 (0)