Skip to content

Commit 976c200

Browse files
authored
Merge pull request #386 from phparkitect/single-letter-class
adds fix to consider valid a single letter class
2 parents 17b1c43 + 80b36c0 commit 976c200

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Analyzer/FullyQualifiedClassName.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function namespace(): string
5858

5959
public static function fromString(string $fqcn): self
6060
{
61-
$validFqcn = '/^[a-zA-Z_\x7f-\xff\\\\][a-zA-Z0-9_\x7f-\xff\\\\]*[a-zA-Z0-9_\x7f-\xff]$/';
61+
$validFqcn = '/^[a-zA-Z0-9_\x7f-\xff\\\\]*[a-zA-Z0-9_\x7f-\xff]$/';
6262

6363
if (!(bool) preg_match($validFqcn, $fqcn)) {
6464
throw new \RuntimeException("$fqcn is not a valid namespace definition");

tests/Unit/Analyzer/FullyQualifiedClassNameTest.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ class FullyQualifiedClassNameTest extends TestCase
1111
public function patternProvider(): array
1212
{
1313
return [
14-
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\Fruits\Banana', true],
15-
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\*\Banana', true],
16-
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables', true],
14+
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\Fruits\Banana', true],
15+
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\*\Banana', true],
16+
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables', true],
1717
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\\', true],
18-
1918
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\*', true],
20-
['Food\Vegetables\Fruits\Mango', '', false],
21-
['Food\Veg', 'Food\Vegetables', false],
22-
['Food\Vegetables', 'Food\Veg', false],
19+
['Food\Vegetables\Fruits\Mango', '', false],
20+
['Food\Veg', 'Food\Vegetables', false],
21+
['Food\Vegetables', 'Food\Veg', false],
2322
];
2423
}
2524

@@ -41,6 +40,12 @@ public function test_should_throw_if_invalid_namespace_is_passed(): void
4140
FullyQualifiedClassName::fromString('-Gvnn');
4241
}
4342

43+
public function test_single_letter_class_is_valid(): void
44+
{
45+
$fqcn = FullyQualifiedClassName::fromString('A');
46+
$this->assertEquals('A', $fqcn->className());
47+
}
48+
4449
public function test_should_return_class_name(): void
4550
{
4651
$fqcn = FullyQualifiedClassName::fromString('Food\Vegetables\Fruits\Banana');

0 commit comments

Comments
 (0)