Skip to content

Commit a54f0bd

Browse files
committed
Use phpdocumentor/reflection-docblock for filtering constructor params phpdoc instead of regex symfony#30056
1 parent c3cc49e commit a54f0bd

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,30 @@ private function getDocBlockFromConstructor($class, $property)
212212
if (!$reflectionConstructor) {
213213
return null;
214214
}
215-
if (!preg_match('/\@param.+?\$'.$property.'/', $reflectionConstructor->getDocComment(), $matches)) {
216-
return null;
217-
}
218-
list($docComment) = $matches;
219215

220216
try {
221-
return $this->docBlockFactory->create($docComment, $this->contextFactory->createFromReflector($reflectionConstructor));
217+
$docBlock = $this->docBlockFactory->create($reflectionConstructor, $this->contextFactory->createFromReflector($reflectionConstructor));
218+
return $this->filterDocBlockParams($docBlock, $property);
222219
} catch (\InvalidArgumentException $e) {
223220
return null;
224221
}
225222
}
226223

224+
/**
225+
* @param DocBlock $docBlock
226+
* @param string $allowedParam
227+
* @return DocBlock
228+
*/
229+
private function filterDocBlockParams(DocBlock $docBlock, $allowedParam)
230+
{
231+
$tags = array_values(array_filter($docBlock->getTagsByName('param'), function($tag) use ($allowedParam) {
232+
return $tag instanceof DocBlock\Tags\Param && $allowedParam === $tag->getVariableName();
233+
}));
234+
235+
return new DocBlock($docBlock->getSummary(), $docBlock->getDescription(), $tags, $docBlock->getContext(),
236+
$docBlock->getLocation(), $docBlock->isTemplateStart(), $docBlock->isTemplateEnd());
237+
}
238+
227239
/**
228240
* Gets the DocBlock from a property.
229241
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy