Skip to content

Commit 5701d67

Browse files
author
Kirill Nesmeyanov
committed
Add name support into the property (-read|-write) annotations
1 parent f3f8ca9 commit 5701d67

4 files changed

Lines changed: 57 additions & 15 deletions

File tree

src/DocBlock/Tag/PropertyReadTag.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@
88
use TypeLang\PhpDocParser\DocBlock\Description;
99

1010
/**
11-
* TODO Add support of property name parsing: {@link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/property.html#property-property-read-property-write}
11+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/property.html#property-property-read-property-write
1212
*/
13-
final class PropertyReadTag extends TypedTag
13+
final class PropertyReadTag extends TypedTag implements VariableNameProviderInterface
1414
{
15-
public function __construct(TypeStatement $type, Description|string|null $description = null)
16-
{
15+
/**
16+
* @param non-empty-string $variable
17+
*/
18+
public function __construct(
19+
private readonly string $variable,
20+
TypeStatement $type,
21+
Description|string|null $description = null
22+
) {
1723
parent::__construct('property-read', $type, $description);
1824
}
25+
26+
/**
27+
* @return non-empty-string
28+
*/
29+
public function getVarName(): string
30+
{
31+
return $this->variable;
32+
}
1933
}

src/DocBlock/Tag/PropertyTag.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@
88
use TypeLang\PhpDocParser\DocBlock\Description;
99

1010
/**
11-
* TODO Add support of property name parsing: {@link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/property.html#property-property-read-property-write}
11+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/property.html#property-property-read-property-write
1212
*/
13-
final class PropertyTag extends TypedTag
13+
final class PropertyTag extends TypedTag implements VariableNameProviderInterface
1414
{
15-
public function __construct(TypeStatement $type, Description|string|null $description = null)
16-
{
15+
/**
16+
* @param non-empty-string $variable
17+
*/
18+
public function __construct(
19+
private readonly string $variable,
20+
TypeStatement $type,
21+
Description|string|null $description = null
22+
) {
1723
parent::__construct('property', $type, $description);
1824
}
25+
26+
/**
27+
* @return non-empty-string
28+
*/
29+
public function getVarName(): string
30+
{
31+
return $this->variable;
32+
}
1933
}

src/DocBlock/Tag/PropertyWriteTag.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@
88
use TypeLang\PhpDocParser\DocBlock\Description;
99

1010
/**
11-
* TODO Add support of property name parsing: {@link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/property.html#property-property-read-property-write}
11+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/property.html#property-property-read-property-write
1212
*/
13-
final class PropertyWriteTag extends TypedTag
13+
final class PropertyWriteTag extends TypedTag implements VariableNameProviderInterface
1414
{
15-
public function __construct(TypeStatement $type, Description|string|null $description = null)
16-
{
15+
/**
16+
* @param non-empty-string $variable
17+
*/
18+
public function __construct(
19+
private readonly string $variable,
20+
TypeStatement $type,
21+
Description|string|null $description = null
22+
) {
1723
parent::__construct('property-write', $type, $description);
1824
}
25+
26+
/**
27+
* @return non-empty-string
28+
*/
29+
public function getVarName(): string
30+
{
31+
return $this->variable;
32+
}
1933
}

src/DocBlockFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public static function getStandardTags(
9797
yield 'var' => new CommonTypedTagFactory(VarTag::class, $parser, $descriptions);
9898
yield 'global' => new CommonTypedTagWithNameFactory(GlobalTag::class, $parser, $descriptions);
9999
yield 'param' => new CommonTypedTagWithNameFactory(ParamTag::class, $parser, $descriptions);
100-
yield 'property' => new CommonTypedTagFactory(PropertyTag::class, $parser, $descriptions);
101-
yield 'property-read' => new CommonTypedTagFactory(PropertyReadTag::class, $parser, $descriptions);
102-
yield 'property-write' => new CommonTypedTagFactory(PropertyWriteTag::class, $parser, $descriptions);
100+
yield 'property' => new CommonTypedTagWithNameFactory(PropertyTag::class, $parser, $descriptions);
101+
yield 'property-read' => new CommonTypedTagWithNameFactory(PropertyReadTag::class, $parser, $descriptions);
102+
yield 'property-write' => new CommonTypedTagWithNameFactory(PropertyWriteTag::class, $parser, $descriptions);
103103
yield ['return', 'returns'] => new CommonTypedTagFactory(ReturnTag::class, $parser, $descriptions);
104104
yield ['throw', 'throws'] => new CommonTypedTagFactory(ThrowsTag::class, $parser, $descriptions);
105105

0 commit comments

Comments
 (0)