Skip to content

Commit 8eb18e2

Browse files
committed
Fix bug in Psr4Sniff when class has not namespace
1 parent 43421f0 commit 8eb18e2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## not released
4+
- Fix bug in `Psr4Sniff` when class has not namespace.
5+
36
## 0.11.0
47
- Fix false positive in `ReturnTypeDeclarationSniff` with nullable types.
58
- Relax check for missing return type when `{aType}|null` doc bloc is present.

Inpsyde/Sniffs/CodeQuality/Psr4Sniff.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
final class Psr4Sniff implements Sniff
2222
{
2323
/**
24-
* @var string|null
24+
* @var array
2525
*/
26-
public $psr4 = null;
26+
public $psr4;
2727

2828
/**
2929
* @var array
@@ -74,6 +74,7 @@ private function checkFilenameOnly(
7474
string $className,
7575
string $entityType
7676
) {
77+
7778
if (basename($file->getFilename()) === "{$className}.php") {
7879
return;
7980
}
@@ -105,8 +106,9 @@ private function checkPsr4(
105106
) {
106107

107108
list(, $namespace) = PhpcsHelpers::findNamespace($file, $position);
109+
$namespace = is_string($namespace) ? "{$namespace}\\" : '';
108110

109-
$fullyQualifiedName = "{$namespace}\\{$className}";
111+
$fullyQualifiedName = $namespace . $className;
110112
foreach ($this->exclude as $excluded) {
111113
if (strpos($fullyQualifiedName, $excluded) === 0) {
112114
return;

0 commit comments

Comments
 (0)