Skip to content

[PropertyInfo] Add PhpStan extractor to PropertyInfo available extractors (with promoted property) #16954

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion components/property_info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,38 @@ library is present::
$phpDocExtractor->getShortDescription($class, $property);
$phpDocExtractor->getLongDescription($class, $property);

PhpStanExtractor
~~~~~~~~~~~~~~~

.. note::

This extractor depends on the `phpstan/phpdoc-parser`_ and
`phpdocumentor/reflection-docblock`_ libraries.

This extractor fetches informations thanks to the PHPStan parser. This
extractor gather information from annotations of the comment section
of properties and methods, such as ``@var``, ``@param`` or ``@return``.
Like ``PhpDocExtractor``, this extractor is also compatible with promoted
constructor properties introduced in PHP 8.0::

// Foo.php
class Foo
{
/**
* @param string $bar
*/
public function __construct(
private string $bar = 'baz'
) {
}
}

// Extraction.php
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;

$phpStanExtractor = new PhpStanExtractor();
$phpStanExtractor->getTypesFromConstructor(Foo::class, 'bar');

SerializerExtractor
~~~~~~~~~~~~~~~~~~~

Expand All @@ -436,7 +468,7 @@ with the ``property_info`` service in the Symfony Framework::

// the `serializer_groups` option must be configured (may be set to null)
$serializerExtractor->getProperties($class, ['serializer_groups' => ['mygroup']]);

If ``serializer_groups`` is set to ``null``, serializer groups metadata won't be
checked but you will get only the properties considered by the Serializer
Component (notably the ``@Ignore`` annotation is taken into account).
Expand Down Expand Up @@ -497,6 +529,7 @@ service by defining it as a service with one or more of the following

.. _`phpDocumentor Reflection`: https://github.com/phpDocumentor/ReflectionDocBlock
.. _`phpdocumentor/reflection-docblock`: https://packagist.org/packages/phpdocumentor/reflection-docblock
.. _`phpstan/phpdoc-parser`: https://packagist.org/packages/phpstan/phpdoc-parser
.. _`Doctrine ORM`: https://www.doctrine-project.org/projects/orm.html
.. _`symfony/serializer`: https://packagist.org/packages/symfony/serializer
.. _`symfony/doctrine-bridge`: https://packagist.org/packages/symfony/doctrine-bridge
Expand Down