-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
164 additions
and
34 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; | ||
|
||
use phpDocumentor\Reflection\TypeResolver; | ||
use phpDocumentor\Reflection\Types\Context; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode; | ||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; | ||
|
||
/** | ||
* @internal This class is not part of the BC promise of this library. | ||
*/ | ||
abstract class AbstractExtendsFactory implements PHPStanFactory | ||
{ | ||
private DescriptionFactory $descriptionFactory; | ||
private TypeResolver $typeResolver; | ||
protected string $tagName; | ||
|
||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) | ||
{ | ||
$this->descriptionFactory = $descriptionFactory; | ||
$this->typeResolver = $typeResolver; | ||
} | ||
|
||
public function supports(PhpDocTagNode $node, Context $context): bool | ||
{ | ||
return $node->value instanceof ExtendsTagValueNode && $node->name === $this->tagName; | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; | ||
|
||
use phpDocumentor\Reflection\TypeResolver; | ||
use phpDocumentor\Reflection\Types\Context; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; | ||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode; | ||
|
||
/** | ||
* @internal This class is not part of the BC promise of this library. | ||
*/ | ||
abstract class AbstractImplementsFactory implements PHPStanFactory | ||
{ | ||
private DescriptionFactory $descriptionFactory; | ||
private TypeResolver $typeResolver; | ||
protected string $tagName; | ||
|
||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) | ||
{ | ||
$this->descriptionFactory = $descriptionFactory; | ||
$this->typeResolver = $typeResolver; | ||
} | ||
|
||
public function supports(PhpDocTagNode $node, Context $context): bool | ||
{ | ||
return $node->value instanceof ImplementsTagValueNode && $node->name === $this->tagName; | ||
} | ||
} |
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
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,42 @@ | ||
<?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 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. | ||
*/ | ||
final class TemplateExtendsFactory extends AbstractExtendsFactory | ||
{ | ||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) | ||
{ | ||
parent::__construct($typeResolver, $descriptionFactory); | ||
$this->tagName = '@template-extends'; | ||
} | ||
|
||
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; | ||
} | ||
|
||
return new TemplateExtends( | ||
$this->typeResolver->createType($tagValue->type, $context), | ||
$this->descriptionFactory->create($description, $context) | ||
); | ||
} | ||
} |
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,42 @@ | ||
<?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\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. | ||
*/ | ||
final class TemplateImplementsFactory extends AbstractImplementsFactory | ||
{ | ||
public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) | ||
{ | ||
parent::__construct($typeResolver, $descriptionFactory); | ||
$this->tagName = '@template-implements'; | ||
} | ||
|
||
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; | ||
} | ||
|
||
return new TemplateImplements( | ||
$this->typeResolver->createType($tagValue->type, $context), | ||
$this->descriptionFactory->create($description, $context) | ||
); | ||
} | ||
} |
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