Skip to content

Commit c41c680

Browse files
committed
Fix tests for Psr4Sniff
1 parent ae89c53 commit c41c680

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Inpsyde/Sniffs/CodeQuality/Psr4Sniff.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ private function checkPsr4(
107107

108108
list(, $namespace) = PhpcsHelpers::findNamespace($file, $position);
109109
$namespace = is_string($namespace) ? "{$namespace}\\" : '';
110+
$namespace = rtrim($namespace, '\\');
111+
112+
$fullyQualifiedName = $namespace . "\\{$className}";
110113

111-
$fullyQualifiedName = $namespace . $className;
112114
foreach ($this->exclude as $excluded) {
113115
if (strpos($fullyQualifiedName, $excluded) === 0) {
114116
return;
@@ -130,6 +132,7 @@ private function checkPsr4(
130132
}
131133

132134
$relativePath = array_pop($folderSplit);
135+
133136
if (basename($relativePath) !== "{$className}.php") {
134137
continue;
135138
}

tests/fixtures/Psr4Fixture.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ class ThisIsWrong
2323
}
2424
}
2525

26+
namespace Inpsyde\CodingStandard\Tests\fixtures\Foo {
27+
28+
// @phpcsErrorCodeOnNextLine InvalidPSR4
29+
class Psr4Fixture
30+
{
31+
32+
}
33+
}
34+
2635
namespace Inpsyde\CodingStandard\Foo\Bar {
2736

2837
// @phpcsErrorCodeOnNextLine InvalidPSR4
@@ -47,4 +56,4 @@ interface Psr4Fixture
4756
{
4857

4958
}
50-
}
59+
}

0 commit comments

Comments
 (0)