Skip to content

Commit

Permalink
Class constant is not a referenced name (fixes #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 18, 2016
1 parent 0ae638c commit 5269229
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions SlevomatCodingStandard/Helpers/ReferencedNameHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private static function isReferencedName(PHP_CodeSniffer_File $phpcsFile, $start
T_DOUBLE_COLON,
T_OBJECT_OPERATOR,
T_NAMESPACE,
T_CONST,
];

if ($previousToken['code'] === T_USE) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Helpers/ReferencedNameHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,13 @@ public function testReturnTypehint()
$this->assertSame('\OtherNamespace\Lorem', $names[1]->getNameAsReferencedInFile());
}

public function testConstantIsNotReferencedName()
{
$codeSnifferFile = $this->getCodeSnifferFile(
__DIR__ . '/data/class-constant.php'
);
$names = ReferencedNameHelper::getAllReferencedNames($codeSnifferFile, 0);
$this->assertCount(0, $names);
}

}
8 changes: 8 additions & 0 deletions tests/Helpers/data/class-constant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

class Foo
{

const URL = 'bar';

}
6 changes: 6 additions & 0 deletions tests/Sniffs/Namespaces/UnusedUsesSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@ public function testTypeWithUnderscoresInAnnotation()
$this->assertNoSniffError($report, 5);
}

public function testMatchingCaseOfUseAndClassConstant()
{
$report = $this->checkFile(__DIR__ . '/data/matchingCaseOfUseAndClassConstant.php');
$this->assertNoSniffErrorInFile($report);
}

}
18 changes: 18 additions & 0 deletions tests/Sniffs/Namespaces/data/matchingCaseOfUseAndClassConstant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Hele\Sms;

use Nette\Http\Url;

class Test
{

const URL = 'https://foo.com';

public function sendMessage()
{
$url = new Url(self::URL);
$url->getAbsoluteUrl();
}

}

0 comments on commit 5269229

Please sign in to comment.