Skip to content

PHP Form node visitor unwanted behaviour #39

@samvdb

Description

@samvdb

The form visitors stop child propagation with the check below. This means custom visitors added after the form visitors will not get the chance to evaluate the code.

I believe the fix should happen here and not in the symfony bundle for php-translation.

(Using ordering in the compiler pass could be a workaround for this issue, but it should not be the main fix)

Using this code:

// only Traverse *Type
        if ($node instanceof Stmt\Class_) {
            if (substr($node->name, -4) !== 'Type') {
                return NodeTraverser::DONT_TRAVERSE_CHILDREN;
            }
        }

Maybe using something like this could correctly solve the problem.

/**
     * @var Stmt\Class_
     */
    protected $class;

    /**
     * @inheritdoc
     */
    public function beforeTraverse(array $nodes)
    {
        foreach($nodes as $node) {
            if ($node instanceof Stmt\Class_) {
                $this->class = $node;
            }
        }
    }

if ($this->class instanceof Stmt\Class_) {
            if (substr($this->class->name, -4) !== 'Type') {
                return;
            }

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions