Skip to content

Commit 6908c99

Browse files
committed
Add mixin tag
1 parent a979495 commit 6908c99

File tree

2 files changed

+84
-18
lines changed

2 files changed

+84
-18
lines changed

src/DocBlock/StandardTagFactory.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
2323
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;
2424
use phpDocumentor\Reflection\DocBlock\Tags\Method;
25+
use phpDocumentor\Reflection\DocBlock\Tags\Mixin;
2526
use phpDocumentor\Reflection\DocBlock\Tags\Param;
2627
use phpDocumentor\Reflection\DocBlock\Tags\Property;
2728
use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead;
@@ -80,25 +81,26 @@ final class StandardTagFactory implements TagFactory
8081
* FQCN to a class that handles it as an array value.
8182
*/
8283
private array $tagHandlerMappings = [
83-
'author' => Author::class,
84-
'covers' => Covers::class,
85-
'deprecated' => Deprecated::class,
86-
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
87-
'link' => LinkTag::class,
88-
'method' => Method::class,
89-
'param' => Param::class,
90-
'property-read' => PropertyRead::class,
91-
'property' => Property::class,
84+
'author' => Author::class,
85+
'covers' => Covers::class,
86+
'deprecated' => Deprecated::class,
87+
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
88+
'link' => LinkTag::class,
89+
'mixin' => Mixin::class,
90+
'method' => Method::class,
91+
'param' => Param::class,
92+
'property-read' => PropertyRead::class,
93+
'property' => Property::class,
9294
'property-write' => PropertyWrite::class,
93-
'return' => Return_::class,
94-
'see' => SeeTag::class,
95-
'since' => Since::class,
96-
'source' => Source::class,
97-
'throw' => Throws::class,
98-
'throws' => Throws::class,
99-
'uses' => Uses::class,
100-
'var' => Var_::class,
101-
'version' => Version::class,
95+
'return' => Return_::class,
96+
'see' => SeeTag::class,
97+
'since' => Since::class,
98+
'source' => Source::class,
99+
'throw' => Throws::class,
100+
'throws' => Throws::class,
101+
'uses' => Uses::class,
102+
'var' => Var_::class,
103+
'version' => Version::class,
102104
];
103105

104106
/**

src/DocBlock/Tags/Mixin.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\DocBlock\Tags;
15+
16+
use phpDocumentor\Reflection\DocBlock\Description;
17+
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
18+
use phpDocumentor\Reflection\Type;
19+
use phpDocumentor\Reflection\TypeResolver;
20+
use phpDocumentor\Reflection\Types\Context as TypeContext;
21+
use Webmozart\Assert\Assert;
22+
23+
/**
24+
* Reflection class for a {@}mixin tag in a Docblock.
25+
*/
26+
final class Mixin extends TagWithType implements Factory\StaticMethod
27+
{
28+
public function __construct(Type $type, ?Description $description = null)
29+
{
30+
$this->name = 'mixin';
31+
$this->type = $type;
32+
$this->description = $description;
33+
}
34+
35+
public static function create(
36+
string $body,
37+
?TypeResolver $typeResolver = null,
38+
?DescriptionFactory $descriptionFactory = null,
39+
?TypeContext $context = null
40+
): self {
41+
Assert::notNull($typeResolver);
42+
Assert::notNull($descriptionFactory);
43+
44+
[$type, $description] = self::extractTypeFromBody($body);
45+
46+
$type = $typeResolver->resolve($type, $context);
47+
$description = $descriptionFactory->create($description, $context);
48+
49+
return new static($type, $description);
50+
}
51+
52+
public function __toString(): string
53+
{
54+
if ($this->description) {
55+
$description = $this->description->render();
56+
} else {
57+
$description = '';
58+
}
59+
60+
$type = (string) $this->type;
61+
62+
return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : '');
63+
}
64+
}

0 commit comments

Comments
 (0)