Skip to content

Commit 54bbfe4

Browse files
author
Kirill Nesmeyanov
committed
Reorganize and improve supported tags
1 parent ee0d8a5 commit 54bbfe4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+608
-225
lines changed

src/DocBlock/Tag/ApiTag.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44

55
namespace TypeLang\PhpDocParser\DocBlock\Tag;
66

7-
final class ApiTag extends Tag
7+
/**
8+
* TODO This tag doesnt support description: Should support for this
9+
* functionality be removed?
10+
*
11+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/api.html#api
12+
*/
13+
final class ApiTag extends Tag implements CreatableFromDescriptionInterface
814
{
915
public function __construct(\Stringable|string|null $description = null)
1016
{
1117
parent::__construct('api', $description);
1218
}
19+
20+
public static function createFromDescription(\Stringable|string|null $description = null): self
21+
{
22+
return new self($description);
23+
}
1324
}

src/DocBlock/Tag/AuthorTag.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44

55
namespace TypeLang\PhpDocParser\DocBlock\Tag;
66

7-
final class AuthorTag extends Tag
7+
/**
8+
* TODO Replace description to required "name" string scalar.
9+
* TODO Add email parsing support.
10+
*
11+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/author.html#author
12+
*/
13+
final class AuthorTag extends Tag implements CreatableFromDescriptionInterface
814
{
915
public function __construct(\Stringable|string|null $description = null)
1016
{
1117
parent::__construct('author', $description);
1218
}
19+
20+
public static function createFromDescription(\Stringable|string|null $description = null): self
21+
{
22+
return new self($description);
23+
}
1324
}

src/DocBlock/Tag/CategoryTag.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDocParser\DocBlock\Tag;
6+
7+
/**
8+
* TODO Replace description to simple string scalar.
9+
*
10+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/category.html#category
11+
*/
12+
final class CategoryTag extends Tag implements CreatableFromDescriptionInterface
13+
{
14+
public function __construct(\Stringable|string|null $description = null)
15+
{
16+
parent::__construct('category', $description);
17+
}
18+
19+
public static function createFromDescription(\Stringable|string|null $description = null): self
20+
{
21+
return new self($description);
22+
}
23+
}

src/DocBlock/Tag/CopyrightTag.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44

55
namespace TypeLang\PhpDocParser\DocBlock\Tag;
66

7-
final class CopyrightTag extends Tag
7+
/**
8+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/copyright.html#copyright
9+
*/
10+
final class CopyrightTag extends Tag implements CreatableFromDescriptionInterface
811
{
912
public function __construct(\Stringable|string|null $description = null)
1013
{
1114
parent::__construct('copyright', $description);
1215
}
16+
17+
public static function createFromDescription(\Stringable|string|null $description = null): self
18+
{
19+
return new self($description);
20+
}
1321
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDocParser\DocBlock\Tag;
6+
7+
interface CreatableFromDescriptionInterface extends TagInterface
8+
{
9+
/**
10+
* Creates a new tag instance from an arbitrary optional string-like argument.
11+
*/
12+
public static function createFromDescription(\Stringable|string|null $description = null): self;
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDocParser\DocBlock\Tag;
6+
7+
use TypeLang\Parser\Node\Stmt\TypeStatement;
8+
9+
interface CreatableFromNameTypeAndDescriptionInterface extends
10+
TagInterface,
11+
TypeProviderInterface,
12+
VariableNameProviderInterface
13+
{
14+
/**
15+
* Creates a new tag instance from required "name" identifier, required
16+
* {@see TypeStatement} type statement and arbitrary optional
17+
* string-like description arguments.
18+
*
19+
* @param non-empty-string $name
20+
*/
21+
public static function createFromNameTypeAndDescription(
22+
string $name,
23+
TypeStatement $type,
24+
\Stringable|string|null $description = null,
25+
): self;
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDocParser\DocBlock\Tag;
6+
7+
use TypeLang\Parser\Node\Stmt\TypeStatement;
8+
9+
interface CreatableFromTagAndDescriptionInterface extends TagInterface, TypeProviderInterface
10+
{
11+
/**
12+
* Creates a new tag instance from a required {@see TypeStatement} type
13+
* statement and arbitrary optional string-like description argument.
14+
*/
15+
public static function createFromTagAndDescription(
16+
TypeStatement $type,
17+
\Stringable|string|null $description = null,
18+
): self;
19+
}

src/DocBlock/Tag/DeprecatedTag.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
namespace TypeLang\PhpDocParser\DocBlock\Tag;
66

77
/**
8-
* TODO Add version support: {@link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/deprecated.html#deprecated}
8+
* TODO Add semantic versioning prefix support.
9+
*
10+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/deprecated.html#deprecated
911
*/
10-
final class DeprecatedTag extends Tag
12+
final class DeprecatedTag extends Tag implements CreatableFromDescriptionInterface
1113
{
1214
public function __construct(\Stringable|string|null $description = null)
1315
{
1416
parent::__construct('deprecated', $description);
1517
}
18+
19+
public static function createFromDescription(\Stringable|string|null $description = null): self
20+
{
21+
return new self($description);
22+
}
1623
}

src/DocBlock/Tag/ExampleTag.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@
55
namespace TypeLang\PhpDocParser\DocBlock\Tag;
66

77
/**
8-
* TODO Add location support: {@link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/example.html#example}
8+
* TODO Add required location support
9+
* TODO Add optional start line support
10+
* TODO Add optional number of lines support
11+
*
12+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/example.html#example
913
*/
10-
final class ExampleTag extends Tag
14+
final class ExampleTag extends Tag implements CreatableFromDescriptionInterface
1115
{
1216
public function __construct(\Stringable|string|null $description = null)
1317
{
1418
parent::__construct('example', $description);
1519
}
20+
21+
public static function createFromDescription(\Stringable|string|null $description = null): self
22+
{
23+
return new self($description);
24+
}
1625
}

src/DocBlock/Tag/FilesourceTag.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44

55
namespace TypeLang\PhpDocParser\DocBlock\Tag;
66

7-
final class FilesourceTag extends Tag
7+
/**
8+
* TODO This tag doesnt support description: Should support for this
9+
* functionality be removed?
10+
*
11+
* @link https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/filesource.html#filesource
12+
*/
13+
final class FilesourceTag extends Tag implements CreatableFromDescriptionInterface
814
{
915
public function __construct(\Stringable|string|null $description = null)
1016
{
1117
parent::__construct('filesource', $description);
1218
}
19+
20+
public static function createFromDescription(\Stringable|string|null $description = null): self
21+
{
22+
return new self($description);
23+
}
1324
}

0 commit comments

Comments
 (0)