Skip to content

Commit

Permalink
Merge pull request #3 from thunderer/docblock-autocomplete-issue
Browse files Browse the repository at this point in the history
Docblock enumerations with `static` type qualifier
  • Loading branch information
thunderer authored Sep 28, 2019
2 parents cdf589a + 3741fc6 commit 96e76d6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace X;
use Thunder\Platenum\Enum\ConstantsEnumTrait;

/**
* @method static self ACTIVE()
* @method static self INACTIVE()
* @method static self SUSPENDED()
* @method static self DISABLED()
* @method static static ACTIVE()
* @method static static INACTIVE()
* @method static static SUSPENDED()
* @method static static DISABLED()
*/
final class AccountStatusEnum
{
Expand Down Expand Up @@ -114,8 +114,8 @@ final class BooleanEnum extends AbstractConstantsEnum
```php
/**
* @method static self TRUE()
* @method static self FALSE()
* @method static static TRUE()
* @method static static FALSE()
*/
final class BooleanEnum
{
Expand All @@ -125,8 +125,8 @@ final class BooleanEnum

```php
/**
* @method static self TRUE()
* @method static self FALSE()
* @method static static TRUE()
* @method static static FALSE()
*/
final class BooleanEnum extends AbstractDocblockEnum {}
```
Expand Down
2 changes: 1 addition & 1 deletion src/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function generateClassCode(string $type, string $fqcn, string $keys): st
}

$constantsEntries[] = ' private const '.strtoupper($key).' = '.$value.';';
$docblockEntries[] = ' * @method static self '.strtoupper($key).'()';
$docblockEntries[] = ' * @method static static '.strtoupper($key).'()';
$staticEntries[] = ' \''.strtoupper($key).'\' => '.$value.';';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Enum/DocblockEnumTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final private static function resolve(): array
throw PlatenumException::fromMissingDocblock($class);
}

if(\preg_match_all('~^\s+\*\s+@method\s+static\s+self\s+(?<key>\w+)\(\)$~m', $doc, $matches) < 1) {
if(\preg_match_all('~^\s+\*\s+@method\s+static\s+(?:self|static)\s+(?<key>\w+)\(\)$~m', $doc, $matches) < 1) {
throw PlatenumException::fromEmptyDocblock($class);
}
if(\count($matches['key']) !== substr_count($doc, '@method')) {
Expand Down
14 changes: 14 additions & 0 deletions tests/DocblockEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public function testMembers(): void
$this->assertSame($expected, $extends::getMembersAndValues());
}

public function testAcceptBothSelfAndStaticDocblockTypeQualifiers(): void
{
/** @var FakeEnum $enum */
$enum = $this->computeUniqueClassName('X');
eval('/**
* @method static self FIRST()
* @method static static SECOND()
*/
class '.$enum.' { use '.DocblockEnumTrait::class.'; }');

$this->assertSame('FIRST', $enum::FIRST()->getValue());
$this->assertSame('SECOND', $enum::SECOND()->getValue());
}

public function testExceptionDocblockNotPresent(): void
{
/** @var FakeEnum $enum */
Expand Down

0 comments on commit 96e76d6

Please sign in to comment.