Twig icon indicating copy to clipboard operation
Twig copied to clipboard

(Partly) remove internal annotation for ExpressionParser

Open iquito opened this issue 5 years ago • 2 comments

The Twig\ExpressionParser class is marked as internal (@internal in the DocBlock for the class), which came to my attention because Psalm reported uses of ExpressionParser::OPERATOR_LEFT and ExpressionParser::OPERATOR_RIGHT in one of my components even though the ExpressionParser class is marked as internal, so these usages seemed to be breaking boundaries.

These constants are used in the documentation (see https://twig.symfony.com/doc/3.x/advanced.html#operators , where they are used when showing how to add additional operators to Twig), so it might make sense to at least reduce the usage of @internal to some of the public methods of ExpressionParser. The way Twig is being extended by custom plugins it seems to me that the parseExpression method should also not be internal, as it is often used when creating additional TokenParser classes. About the other methods I am not sure, but clarifying some of the Twig boundaries (what to use of ExpressionParser and what not) might help both applications and plugins to better know what is safe to use.

iquito avatar Nov 17 '20 18:11 iquito

An easy solution would be something like

<?php
     /**
     * local version of ExpressionParser::OPERATOR_LEFT
     */
    protected const OPERATOR_LEFT = 1;
//.....
// later use
self::OPERATOR_LEFT

JBlond avatar Nov 20 '20 10:11 JBlond

This does not help when using the expression parser such as noted in the documentation: $parser->getExpressionParser()->parseExpression();

Would be really nice to avoid this psalm error for each use of it.

othercorey avatar Dec 12 '20 04:12 othercorey