@throws RuntimeException if the node is a class that extends a final class

@param Node $node
552701
public function enterNode(Node $node)
    {
        if ($node instanceof Class_) {
            if ($node->extends) {
                $extends = (string) $node->extends;
                if ($this->isFinalClass($extends)) {
                    $msg = \sprintf('Class %s may not inherit from final class (%s)', $node->name, $extends);
                    throw new FatalErrorException($msg, 0, E_ERROR, null, $node->getLine());
                }
            }

            if ($node->isFinal()) {
                $this->finalClasses[\strtolower($node->name)] = true;
            }
        }
    }
1135277
public function execute(NodeData $node)
    {
        $nodeType = $this->nodeTypeManager->getNodeType($this->newType);
        $node->setNodeType($nodeType);
    }
1015322
public function leaveNode(Node $node)
    {
        if (!$node instanceof ClassLikeNode) {
            return null;
        }

        // not in class context
        if ($this->currentClass === null) {
            $this->tempDependencies = new DependencySet();
            return;
        }

        // by now the class should have been parsed so replace the
        // temporary class with the parsed class name

        $this->dependencies = $this->dependencies->addSet(
            $this->currentClass,
            $this->tempDependencies
        );
        $this->tempDependencies = new DependencySet();
        $this->currentClass = null;
    }
1158208
final public function setNode(Node $node)
    {
        $this->node = $node;
        foreach ($node->getParams() as $key => $value) {
            $this->$key = $value;
        }
    }
299896
public function invoke($node, NodeInterface $parent): void
    {
        if (! $node instanceof Node\Param || ! $parent instanceof FunctionModelInterface) {
            throw new Exception('ParameterNodeParser is made to parse a function parameter node');
        }

        $parameter = new ParameterModel();
        $parameter->setParentNode($parent);
        $parameter->setName($node->var->name);
        $parameter->setIsVariadic($node->variadic);

        if ($node->type !== null) {
            $this->typeNodeParser->invoke($node->type, $parameter);
        }
        if ($node->default !== null) {
            $this->valueNodeParser->invoke($node->default, $parameter);
        }

        $parent->addParameter($parameter);
    }
263440
public function enterNode(Node $node)
    {
        parent::enterNode($node);

        if (self::isConditional($node)) {
            $this->conditionalScopes++;
        } else {
            // @todo add an "else" here which adds a runtime check for instances where we can't tell
            // whether a class is being redefined by static analysis alone.
            if ($this->conditionalScopes === 0) {
                if ($node instanceof Class_) {
                    $this->validateClassStatement($node);
                } elseif ($node instanceof Interface_) {
                    $this->validateInterfaceStatement($node);
                } elseif ($node instanceof Trait_) {
                    $this->validateTraitStatement($node);
                }
            }
        }
    }
1298484
public function enterNode(Node $node)
    {
        // @todo support MethodCall and StaticCall as well.
        if ($node instanceof FuncCall) {
            // if function name is an expression or a variable, give it a pass for now.
            if ($node->name instanceof Expr || $node->name instanceof Variable) {
                return;
            }

            $name = (string) $node->name;

            if ($name === 'array_multisort') {
                return $this->validateArrayMultisort($node);
            }

            try {
                $refl = new \ReflectionFunction($name);
            } catch (\ReflectionException $e) {
                // Well, we gave it a shot!
                return;
            }

            foreach ($refl->getParameters() as $key => $param) {
                if (\array_key_exists($key, $node->args)) {
                    $arg = $node->args[$key];
                    if ($param->isPassedByReference() && !$this->isPassableByReference($arg)) {
                        throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
                    }
                }
            }
        }
    }
943425
private function validateTypeFieldIsPresent($node)
    {
        if (empty($node['_type'])) {
            throw new Exception("Element: {$this->currentNode} has no compulsory field: _type", ValidatorResult::ERROR_NODE_HAS_NO_FIELD_TYPE);
        }

        $this->getLogger()->info("Element: {$this->currentNode} has field: _type");
    }
1314771
protected function verifyClass(AbstractNode $node, array $namespaceParts): void
    {
        $expectedBridgeNameRegexp = '#^' . $namespaceParts['moduleName'] . 'To[\w]+' . $namespaceParts['layerName'] . 'Bridge$#';

        if (preg_match($expectedBridgeNameRegexp, $node->getName()) !== 0) {
            return;
        }

        $message = sprintf(
            'The bridge name is not \'%sTo{target_module_name}%sBridge\'. That violates the rule "%s"',
            $namespaceParts['moduleName'],
            $namespaceParts['layerName'],
            static::CLASS_RULE
        );

        $this->addViolation($node, [$message]);
    }
603965
public function addChildAsLast(Node $node)
    {
        if(null === $this->children)
        {
            $this->children = array();
        }

        $this->children[] = $node;
    }
932550
protected function finish(NodeInterface $node)
    {
        $removeNode = new RemoveNode();
        $removeNode->setNode($node);

        $this->feedbackCollection->add($removeNode);

        // $this->getSubject() is the moved node at the NEW location!
        parent::finish($this->getSubject());
    }
851685
public function apply(AbstractNode $node)
    {
        $patterns = $this->collectPatterns($node);

        $this->applyPatterns($node, $patterns);

        /** @var \PHPMD\Node\AbstractTypeNode $node */
        foreach ($node->getMethods() as $method) {
            $this->applyPatterns(
                $method,
                $patterns
            );
        }
    }
167479
public function execute(NodeData $node)
    {
        $currentPropertyValue = $node->getProperty($this->propertyName);
        $newPropertyValue = strtolower($currentPropertyValue);
        $node->setProperty($this->propertyName, $newPropertyValue);
    }
1254966
public function createRoot(Node $node)
    {
        if($node instanceof NodeWrapper)
        {
            throw new \InvalidArgumentException('Can\'t create a root node from a NodeWrapper node');
        }

        $node->setLeftValue(1);
        $node->setRightValue(2);

        if($this->getConfiguration()->hasManyRoots())
        {
            $rootValue = $node->getId();
            if($rootValue === null)
            {
                // Set a temporary value in case wrapped node requires root value to be set
                $node->setRootValue(0);
                $this->getEntityManager()->persist($node);
                $this->getEntityManager()->flush();
                $rootValue = $node->getId();
            }

            if($rootValue === null)
            {
                // @codeCoverageIgnoreStart
                throw new \RuntimeException('Node must have an identifier available via getId()');
                // @codeCoverageIgnoreEnd
            }

            $node->setRootValue($rootValue);
        }


        $this->getEntityManager()->persist($node);
        $this->getEntityManager()->flush();

        return $this->wrapNode($node);
    }
1358477
public function invoke($node, NodeInterface $parent): void
    {
        if (! $parent instanceof TypeInterface) {
            throw new Exception('TypeNodeParser is made to parse a type node');
        }

        // If it is a nullable type
        if ($node instanceof Node\NullableType) {
            $parent->setNullable(true);

            $this->invoke($node->type, $parent);
            return;
        }
        // Handle scalar type in identifier
        if ($node instanceof Node\Identifier
            && Validator::contains($node->name)->validate(TypeInterface::RESERVED_TYPE_IDENTIFIERS)
        ) {
            $node = $node->name;
        }
        // If it is a class like type
        if ($node instanceof Node\Name || $node instanceof Node\Identifier) {
            $parent->setType(TypeInterface::CUSTOM);
            $parent->setCustomType($this->getClassType($node, $parent));
            return;
        }
        // If it is a scalar type
        if (Validator::stringType()->validate($node)) {
            $parent->setType(constant(TypeInterface::class . '::' . strtoupper($node)));
            return;
        }

        throw new Exception('TypeNodeParser is made to parse a type node');
    }
551708
public function apply(AbstractNode $node): void
    {
        if (!$this->isFacade($node)) {
            return;
        }

        $this->applyRule($node);
    }
562948
protected function applyRule(ClassNode $node)
    {
        foreach ($node->getMethods() as $method) {
            $this->checkVisibility($method);
        }
    }