Passed
Push — dependabot/composer/doctrine/d... ( bc1a80...bcc5a8 )
by
unknown
41:27 queued 36:06
created

src/Frontend/Core/Engine/FormFieldTokenParser.php (2 issues)

1
<?php
2
3
namespace Frontend\Core\Engine;
4
5
/**
6
 * Twig token parser for form fields.
7
 */
8
class FormFieldTokenParser extends \Twig_TokenParser
0 ignored issues
show
Deprecated Code introduced by
The class Twig_TokenParser has been deprecated: since Twig 2.7, use "Twig\TokenParser\AbstractTokenParser" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

8
class FormFieldTokenParser extends /** @scrutinizer ignore-deprecated */ \Twig_TokenParser
Loading history...
9
{
10
    /**
11
     * @param \Twig_Token $token consumed token by the lexer.
12
     *
13
     * @throws \Twig_Error_Syntax
14
     *
15
     * @return \Twig_Node
16
     */
17
    public function parse(\Twig_Token $token): \Twig_Node
18
    {
19
        $stream = $this->parser->getStream();
20
        $field = $stream->expect(\Twig_Token::NAME_TYPE)->getValue();
21
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
22
        if (FormState::$current === null) {
23
            throw new \Twig_Error_Syntax(
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Error_Syntax has been deprecated: since Twig 2.7, use "Twig\Error\SyntaxError" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

23
            throw /** @scrutinizer ignore-deprecated */ new \Twig_Error_Syntax(
Loading history...
24
                sprintf('Cannot render form field [%s] outside a form element', $field),
25
                $token->getLine(),
26
                $this->parser->getStream()->getSourceContext()->getPath()
27
            );
28
        }
29
30
        return new FormFieldNode(FormState::$current, $field, $token->getLine(), $this->getTag());
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getTag(): string
37
    {
38
        return 'form_field';
39
    }
40
}
41