-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new tags #373
Merged
Merged
Add new tags #373
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bbb6a02
Add implements
ahjdev a979495
add doc
ahjdev 6908c99
Add mixin tag
ahjdev a46da81
Add Template tag
ahjdev f387e8f
Add Extends tags
ahjdev 3acbe24
Add Implements tags
ahjdev 19b5535
Clean up
ahjdev cca538e
Add TemplateCovariant tag
ahjdev f93a6b7
Register tags
ahjdev f17d984
Seprate template-* tags
ahjdev 47fea84
Add description
ahjdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection\DocBlock\Tags; | ||
|
||
use Doctrine\Deprecations\Deprecation; | ||
use phpDocumentor\Reflection\Type; | ||
use phpDocumentor\Reflection\DocBlock\Description; | ||
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType; | ||
|
||
/** | ||
* Reflection class for a {@}extends tag in a Docblock. | ||
*/ | ||
class Extends_ extends TagWithType | ||
{ | ||
public function __construct(Type $type, ?Description $description = null) | ||
{ | ||
$this->name = 'extends'; | ||
$this->type = $type; | ||
$this->description = $description; | ||
} | ||
|
||
/** | ||
* @deprecated Create using static factory is deprecated, | ||
* this method should not be called directly by library consumers | ||
*/ | ||
public static function create(string $body) | ||
{ | ||
Deprecation::trigger( | ||
'phpdocumentor/reflection-docblock', | ||
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361', | ||
'Create using static factory is deprecated, this method should not be called directly | ||
by library consumers', | ||
); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; | ||
|
||
use Webmozart\Assert\Assert; | ||
use phpDocumentor\Reflection\DocBlock\Tag; | ||
use phpDocumentor\Reflection\TypeResolver; | ||
use phpDocumentor\Reflection\Types\Context; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; | ||
use phpDocumentor\Reflection\DocBlock\Tags\Extends_; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode; | ||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; | ||
use phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends; | ||
|
||
/** | ||
* @internal This class is not part of the BC promise of this library. | ||
*/ | ||
class ExtendsFactory implements PHPStanFactory | ||
{ | ||
private DescriptionFactory $descriptionFactory; | ||
private TypeResolver $typeResolver; | ||
|
||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) | ||
{ | ||
$this->descriptionFactory = $descriptionFactory; | ||
$this->typeResolver = $typeResolver; | ||
} | ||
|
||
public function create(PhpDocTagNode $node, Context $context): Tag | ||
{ | ||
$tagValue = $node->value; | ||
Assert::isInstanceOf($tagValue, ExtendsTagValueNode::class); | ||
|
||
$description = $tagValue->getAttribute('description'); | ||
if (is_string($description) === false) { | ||
$description = $tagValue->description; | ||
} | ||
|
||
$class = $node->name === '@extends' ? Extends_::class : TemplateExtends::class; | ||
|
||
return new $class( | ||
$this->typeResolver->createType($tagValue->type, $context), | ||
$this->descriptionFactory->create($tagValue->description, $context) | ||
); | ||
} | ||
|
||
public function supports(PhpDocTagNode $node, Context $context): bool | ||
{ | ||
return $node->value instanceof ExtendsTagValueNode && ($node->name === '@extends' || $node->name === '@template-extends'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; | ||
|
||
use Webmozart\Assert\Assert; | ||
use phpDocumentor\Reflection\DocBlock\Tag; | ||
use phpDocumentor\Reflection\TypeResolver; | ||
use phpDocumentor\Reflection\Types\Context; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; | ||
use phpDocumentor\Reflection\DocBlock\Tags\Implements_; | ||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode; | ||
use phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements; | ||
|
||
/** | ||
* @internal This class is not part of the BC promise of this library. | ||
*/ | ||
class ImplementsFactory implements PHPStanFactory | ||
{ | ||
private DescriptionFactory $descriptionFactory; | ||
private TypeResolver $typeResolver; | ||
|
||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) | ||
{ | ||
$this->descriptionFactory = $descriptionFactory; | ||
$this->typeResolver = $typeResolver; | ||
} | ||
|
||
public function create(PhpDocTagNode $node, Context $context): Tag | ||
{ | ||
$tagValue = $node->value; | ||
Assert::isInstanceOf($tagValue, ImplementsTagValueNode::class); | ||
|
||
$description = $tagValue->getAttribute('description'); | ||
if (is_string($description) === false) { | ||
$description = $tagValue->description; | ||
} | ||
|
||
$class = $node->name === '@implements' ? Implements_::class : TemplateImplements::class; | ||
|
||
return new $class( | ||
$this->typeResolver->createType($tagValue->type, $context), | ||
$this->descriptionFactory->create($tagValue->description, $context) | ||
); | ||
} | ||
|
||
public function supports(PhpDocTagNode $node, Context $context): bool | ||
{ | ||
return $node->value instanceof ImplementsTagValueNode && ($node->name === '@implements' || $node->name === '@template-implements'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; | ||
|
||
use Webmozart\Assert\Assert; | ||
use phpDocumentor\Reflection\DocBlock\Tag; | ||
use phpDocumentor\Reflection\TypeResolver; | ||
use phpDocumentor\Reflection\Types\Context; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; | ||
use phpDocumentor\Reflection\DocBlock\Tags\Template; | ||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; | ||
|
||
/** | ||
* @internal This class is not part of the BC promise of this library. | ||
*/ | ||
final class TemplateFactory implements PHPStanFactory | ||
{ | ||
private DescriptionFactory $descriptionFactory; | ||
private TypeResolver $typeResolver; | ||
|
||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) | ||
{ | ||
$this->descriptionFactory = $descriptionFactory; | ||
$this->typeResolver = $typeResolver; | ||
} | ||
|
||
public function create(PhpDocTagNode $node, Context $context): Tag | ||
{ | ||
$tagValue = $node->value; | ||
Assert::isInstanceOf($tagValue, TemplateTagValueNode::class); | ||
|
||
$description = $tagValue->getAttribute('description'); | ||
if (is_string($description) === false) { | ||
$description = $tagValue->description; | ||
} | ||
|
||
return new Template( | ||
$tagValue->name, | ||
$this->typeResolver->createType($tagValue->bound, $context), | ||
$this->typeResolver->createType($tagValue->default, $context), | ||
$this->descriptionFactory->create($tagValue->description, $context) | ||
); | ||
} | ||
|
||
public function supports(PhpDocTagNode $node, Context $context): bool | ||
{ | ||
return $node->value instanceof TemplateTagValueNode && $node->name === '@template'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of phpDocumentor. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection\DocBlock\Tags; | ||
|
||
use Doctrine\Deprecations\Deprecation; | ||
use phpDocumentor\Reflection\Type; | ||
use phpDocumentor\Reflection\DocBlock\Description; | ||
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType; | ||
|
||
/** | ||
* Reflection class for a {@}implements tag in a Docblock. | ||
*/ | ||
class Implements_ extends TagWithType | ||
{ | ||
public function __construct(Type $type, ?Description $description = null) | ||
{ | ||
$this->name = 'implements'; | ||
$this->type = $type; | ||
$this->description = $description; | ||
} | ||
|
||
/** | ||
* @deprecated Create using static factory is deprecated, | ||
* this method should not be called directly by library consumers | ||
*/ | ||
public static function create(string $body) | ||
{ | ||
Deprecation::trigger( | ||
'phpdocumentor/reflection-docblock', | ||
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361', | ||
'Create using static factory is deprecated, this method should not be called directly | ||
by library consumers', | ||
); | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you combine these tags in 1 factory? I think it's wise to keep them separate. Maybe with a base class. A factory should always return a single type in my opinion. Otherwise this is an abstract factory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I just think avoid duplicate codes.
it will be easy for me to seprate them