Skip to content

Commit

Permalink
Merge pull request #386 from phparkitect/single-letter-class
Browse files Browse the repository at this point in the history
adds fix to consider valid a single letter class
  • Loading branch information
fain182 authored Jul 8, 2023
2 parents 17b1c43 + 80b36c0 commit 976c200
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Analyzer/FullyQualifiedClassName.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function namespace(): string

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

if (!(bool) preg_match($validFqcn, $fqcn)) {
throw new \RuntimeException("$fqcn is not a valid namespace definition");
Expand Down
19 changes: 12 additions & 7 deletions tests/Unit/Analyzer/FullyQualifiedClassNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ class FullyQualifiedClassNameTest extends TestCase
public function patternProvider(): array
{
return [
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\Fruits\Banana', true],
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\*\Banana', true],
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables', true],
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\Fruits\Banana', true],
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\*\Banana', true],
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables', true],
['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\\', true],

['Food\Vegetables\Fruits\Banana', 'Food\Vegetables\*', true],
['Food\Vegetables\Fruits\Mango', '', false],
['Food\Veg', 'Food\Vegetables', false],
['Food\Vegetables', 'Food\Veg', false],
['Food\Vegetables\Fruits\Mango', '', false],
['Food\Veg', 'Food\Vegetables', false],
['Food\Vegetables', 'Food\Veg', false],
];
}

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

public function test_single_letter_class_is_valid(): void
{
$fqcn = FullyQualifiedClassName::fromString('A');
$this->assertEquals('A', $fqcn->className());
}

public function test_should_return_class_name(): void
{
$fqcn = FullyQualifiedClassName::fromString('Food\Vegetables\Fruits\Banana');
Expand Down

0 comments on commit 976c200

Please sign in to comment.