|
16 | 16 | use phpDocumentor\Reflection\DocBlockFactoryInterface;
|
17 | 17 | use phpDocumentor\Reflection\Location;
|
18 | 18 | use phpDocumentor\Reflection\Php\Class_;
|
| 19 | +use phpDocumentor\Reflection\Php\Factory\Reducer\Reducer; |
19 | 20 | use phpDocumentor\Reflection\Php\Property as PropertyDescriptor;
|
20 | 21 | use phpDocumentor\Reflection\Php\StrategyContainer;
|
21 | 22 | use phpDocumentor\Reflection\Php\Trait_;
|
|
32 | 33 | */
|
33 | 34 | final class Property extends AbstractFactory
|
34 | 35 | {
|
35 |
| - /** |
36 |
| - * Initializes the object. |
37 |
| - */ |
38 |
| - public function __construct(DocBlockFactoryInterface $docBlockFactory, private readonly PrettyPrinter $valueConverter) |
39 |
| - { |
40 |
| - parent::__construct($docBlockFactory); |
| 36 | + /** @param iterable<Reducer> $reducers */ |
| 37 | + public function __construct( |
| 38 | + DocBlockFactoryInterface $docBlockFactory, |
| 39 | + private readonly PrettyPrinter $valueConverter, |
| 40 | + iterable $reducers = [], |
| 41 | + ) { |
| 42 | + parent::__construct($docBlockFactory, $reducers); |
41 | 43 | }
|
42 | 44 |
|
43 | 45 | public function matches(ContextStack $context, object $object): bool
|
@@ -75,19 +77,27 @@ protected function doCreate(
|
75 | 77 | $default = $this->valueConverter->prettyPrintExpr($default);
|
76 | 78 | }
|
77 | 79 |
|
78 |
| - $propertyContainer->addProperty( |
79 |
| - new PropertyDescriptor( |
80 |
| - $stmt->getFqsen(), |
81 |
| - $this->buildVisibility($stmt), |
82 |
| - $this->createDocBlock($stmt->getDocComment(), $context->getTypeContext()), |
83 |
| - $default, |
84 |
| - $stmt->isStatic(), |
85 |
| - new Location($stmt->getLine()), |
86 |
| - new Location($stmt->getEndLine()), |
87 |
| - (new Type())->fromPhpParser($stmt->getType()), |
88 |
| - $stmt->isReadonly(), |
89 |
| - ), |
| 80 | + $property = new PropertyDescriptor( |
| 81 | + $stmt->getFqsen(), |
| 82 | + $this->buildVisibility($stmt), |
| 83 | + $this->createDocBlock($stmt->getDocComment(), $context->getTypeContext()), |
| 84 | + $default, |
| 85 | + $stmt->isStatic(), |
| 86 | + new Location($stmt->getLine()), |
| 87 | + new Location($stmt->getEndLine()), |
| 88 | + (new Type())->fromPhpParser($stmt->getType()), |
| 89 | + $stmt->isReadonly(), |
90 | 90 | );
|
| 91 | + |
| 92 | + foreach ($this->reducers as $reducer) { |
| 93 | + $property = $reducer->reduce($context, $object, $strategies, $property); |
| 94 | + } |
| 95 | + |
| 96 | + if ($property === null) { |
| 97 | + continue; |
| 98 | + } |
| 99 | + |
| 100 | + $propertyContainer->addProperty($property); |
91 | 101 | }
|
92 | 102 |
|
93 | 103 | return null;
|
|
0 commit comments