eZ\Publish\Core\MVC\Symfony\Translation\ValidationErrorFileVisitor::enterNode PHP Method

enterNode() public method

public enterNode ( PhpParser\Node $node )
$node PhpParser\Node
    public function enterNode(Node $node)
    {
        if (!$node instanceof Node\Expr\New_ || !is_string($node->class) || strtolower($node->class) !== 'validationerror') {
            $this->previousNode = $node;
            return;
        }
        $ignore = false;
        $desc = $meaning = null;
        if (null !== ($docComment = $this->getDocCommentForNode($node))) {
            if ($docComment instanceof Doc) {
                $docComment = $docComment->getText();
            }
            foreach ($this->docParser->parse($docComment, 'file ' . $this->file . ' near line ' . $node->getLine()) as $annot) {
                if ($annot instanceof Ignore) {
                    $ignore = true;
                } elseif ($annot instanceof Desc) {
                    $desc = $annot->text;
                } elseif ($annot instanceof Meaning) {
                    $meaning = $annot->text;
                }
            }
        }
        if (!$node->args[0]->value instanceof String_) {
            if ($ignore) {
                return;
            }
            $message = sprintf('Can only extract the translation id from a scalar string, but got "%s". Please refactor your code to make it extractable, or add the doc comment /** @Ignore */ to this code element (in %s on line %d).', get_class($node->args[0]->value), $this->file, $node->args[0]->value->getLine());
            if ($this->logger) {
                $this->logger->error($message);
                return;
            }
            throw new RuntimeException($message);
        }
        $message = new Message($node->args[0]->value->value, $this->defaultDomain);
        $message->setDesc($desc);
        $message->setMeaning($meaning);
        $message->addSource($this->fileSourceFactory->create($this->file, $node->getLine()));
        $this->catalogue->add($message);
        // plural
        if ($node->args[1]->value instanceof String_) {
            $message = new Message($node->args[1]->value->value, $this->defaultDomain);
            $message->setDesc($desc);
            $message->setMeaning($meaning);
            $message->addSource($this->fileSourceFactory->create($this->file, $node->getLine()));
            $this->catalogue->add($message);
        }
    }