If the parent node has child restrictions, ensure that the given
class name is within them.

@param NodeInterface $parentNode
@param string        $classFqn
179160
private function validateChildClass(NodeInterface $parentNode, ClassMetadata $class)
    {
        $parentClass = $this->documentClassMapper->getClassName($this->dm, $parentNode);

        if (null === $parentClass) {
            return;
        }

        $metadata = $this->dm->getClassMetadata($parentClass);
        $metadata->assertValidChildClass($class);
    }
1322435
private function collectDefinitionsAndReferences(Node $node)
    {
        $fqn = ($this->definitionResolver)::getDefinedFqn($node);
        // Only index definitions with an FQN (no variables)
        if ($fqn !== null) {
            $this->definitionNodes[$fqn] = $node;
            $this->definitions[$fqn] = $this->definitionResolver->createDefinitionFromNode($node, $fqn);
        } else {

            $parent = $node->parent;
            if (
                (
                    // $node->parent instanceof Node\Expression\ScopedPropertyAccessExpression ||
                    ($node instanceof Node\Expression\ScopedPropertyAccessExpression ||
                    $node instanceof Node\Expression\MemberAccessExpression)
                    && !(
                        $node->parent instanceof Node\Expression\CallExpression ||
                        $node->memberName instanceof PhpParser\Token
                    ))
                || ($parent instanceof Node\Statement\NamespaceDefinition && $parent->name !== null && $parent->name->getStart() === $node->getStart())
            ) {
                return;
            }

            $fqn = $this->definitionResolver->resolveReferenceNodeToFqn($node);
            if (!$fqn) {
                return;
            }

            if ($fqn === 'self' || $fqn === 'static') {
                // Resolve self and static keywords to the containing class
                // (This is not 100% correct for static but better than nothing)
                $classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
                if (!$classNode) {
                    return;
                }
                $fqn = (string)$classNode->getNamespacedName();
                if (!$fqn) {
                    return;
                }
            } else if ($fqn === 'parent') {
                // Resolve parent keyword to the base class FQN
                $classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
                if (!$classNode || !$classNode->classBaseClause || !$classNode->classBaseClause->baseClass) {
                    return;
                }
                $fqn = (string)$classNode->classBaseClause->baseClass->getResolvedName();
                if (!$fqn) {
                    return;
                }
            }

            $this->addReference($fqn, $node);

            if (
                $node instanceof Node\QualifiedName
                && ($node->isQualifiedName() || $node->parent instanceof Node\NamespaceUseClause)
                && !($parent instanceof Node\Statement\NamespaceDefinition && $parent->name->getStart() === $node->getStart()
                )
            ) {
                // Add references for each referenced namespace
                $ns = $fqn;
                while (($pos = strrpos($ns, '\\')) !== false) {
                    $ns = substr($ns, 0, $pos);
                    $this->addReference($ns, $node);
                }
            }

            // Namespaced constant access and function calls also need to register a reference
            // to the global version because PHP falls back to global at runtime
            // http://php.net/manual/en/language.namespaces.fallback.php
            if (ParserHelpers\isConstantFetch($node) ||
                ($parent instanceof Node\Expression\CallExpression
                    && !(
                        $node instanceof Node\Expression\ScopedPropertyAccessExpression ||
                        $node instanceof Node\Expression\MemberAccessExpression
                    ))) {
                $parts = explode('\\', $fqn);
                if (count($parts) > 1) {
                    $globalFqn = end($parts);
                    $this->addReference($globalFqn, $node);
                }
            }
        }
    }
453137
protected function applyRule(MethodNode $node)
    {
        $comment = $node->getComment();
        if ($this->hasInvalidReturnType($comment)) {
            $class = $node->getParentName();
            $method = $node->getName();
            $fullClassName = $node->getFullQualifiedName();

            $message = sprintf(
                '%s (%s) returns a concrete class which violates the rule "%s"',
                "{$class}::{$method}()",
                $fullClassName,
                static::RULE
            );

            $this->addViolation($node, [$message]);
        }
    }
287117
public function moveAsLastChildOf(NodeInterface $parentNode)
	{
		$this->validateAddingChildren($parentNode);

		$pos = $parentNode->getRightValue();
		$level = $parentNode->getLevel() + 1;
		$this->move($pos, $level);

		return $this;
	}
3934
public function addChild(TreeNodeInterface $node): void
    {
        $this->children[] = $node;
        $this->isLeaf = false;
    }
900536
public function enterNode(NodeInterface $node): VisitorResult
    {
        $schema = $this->typeInfo->getSchema();

        if ($node instanceof SelectionSetNode) {
            $namedType = getNamedType($this->typeInfo->getType());
            $this->typeInfo->pushParentType($namedType instanceof CompositeTypeInterface ? $namedType : null);
        } elseif ($node instanceof FieldNode) {
            $parentType      = $this->typeInfo->getParentType();
            $fieldDefinition = null;
            $fieldType       = null;
            if (null !== $parentType) {
                $fieldDefinition = $this->typeInfo->resolveFieldDefinition($schema, $parentType, $node);
                if (null !== $fieldDefinition) {
                    $fieldType = $fieldDefinition->getType();
                }
            }
            $this->typeInfo->pushFieldDefinition($fieldDefinition);
            $this->typeInfo->pushType(isOutputType($fieldType) ? $fieldType : null);
        } elseif ($node instanceof DirectiveNode) {
            $this->typeInfo->setDirective($schema->getDirective($node->getNameValue()));
        } elseif ($node instanceof OperationDefinitionNode) {
            $type      = null;
            $operation = $node->getOperation();
            if ($operation === 'query') {
                $type = $schema->getQueryType();
            } elseif ($operation === 'mutation') {
                $type = $schema->getMutationType();
            } elseif ($operation === 'subscription') {
                $type = $schema->getSubscriptionType();
            }
            $this->typeInfo->pushType($type instanceof ObjectType ? $type : null);
        } elseif ($node instanceof InlineFragmentNode || $node instanceof FragmentDefinitionNode) {
            $typeCondition = $node->getTypeCondition();
            $outputType    = null !== $typeCondition
                ? TypeASTConverter::convert($schema, $typeCondition)
                : getNamedType($this->typeInfo->getType());
            $this->typeInfo->pushType(isOutputType($outputType) ? $outputType : null);
        } elseif ($node instanceof VariableDefinitionNode) {
            $inputType = TypeASTConverter::convert($schema, $node->getType());
            /** @noinspection PhpParamsInspection */
            $this->typeInfo->pushInputType(isInputType($inputType) ? $inputType : null);
        } elseif ($node instanceof ArgumentNode) {
            $argumentType       = null;
            $argumentDefinition = null;
            $fieldOrDirective   = $this->typeInfo->getDirective() ?: $this->typeInfo->getFieldDefinition();
            if (null !== $fieldOrDirective) {
                $argumentDefinition = find(
                    $fieldOrDirective->getArguments(),
                    function (Argument $argument) use ($node) {
                        return $argument->getName() === $node->getNameValue();
                    }
                );
                if (null !== $argumentDefinition) {
                    $argumentType = $argumentDefinition->getType();
                }
            }
            $this->typeInfo->setArgument($argumentDefinition);
            $this->typeInfo->pushInputType(isInputType($argumentType) ? $argumentType : null);
        } elseif ($node instanceof ListValueNode) {
            $listType = getNullableType($this->typeInfo->getInputType());
            $itemType = $listType instanceof ListType ? $listType->getOfType() : $listType;
            $this->typeInfo->pushInputType(isInputType($itemType) ? $itemType : null);
        } elseif ($node instanceof ObjectFieldNode) {
            $objectType     = getNamedType($this->typeInfo->getInputType());
            $inputFieldType = null;
            if ($objectType instanceof InputObjectType) {
                $fields     = $objectType->getFields();
                $inputField = $fields[$node->getNameValue()] ?? null;
                if (null !== $inputField) {
                    $inputFieldType = $inputField->getType();
                }
            }
            /** @noinspection PhpParamsInspection */
            $this->typeInfo->pushInputType(isInputType($inputFieldType) ? $inputFieldType : null);
        } elseif ($node instanceof EnumValueNode) {
            $enumType  = getNamedType($this->typeInfo->getInputType());
            $enumValue = null;
            if ($enumType instanceof EnumType) {
                $enumValue = $enumType->getValue($node->getValue());
            }
            $this->typeInfo->setEnumValue($enumValue);
        }

        return $this->visitor->enterNode($node);
    }
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);
                }
            }
        }
    }
831004
public function createChildNodes(NodeInterface $node)
    {
        $nodeType = $node->getNodeType();
        foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeType) {
            try {
                $node->createNode($childNodeName, $childNodeType);
            } catch (NodeExistsException $exception) {
                // If you have a node that has been marked as removed, but is needed again
                // the old node is recovered
                $childNodePath = NodePaths::addNodePathSegment($node->getPath(), $childNodeName);
                $contextProperties = $node->getContext()->getProperties();
                $contextProperties['removedContentShown'] = true;
                $context = $this->contextFactory->create($contextProperties);
                $childNode = $context->getNode($childNodePath);
                if ($childNode->isRemoved()) {
                    $childNode->setRemoved(false);
                }
            }
        }
    }
1274728
protected function isExcludedModule(ClassNode $classNode): bool
    {
        $moduleName = $this->getModuleName($classNode->getNamespaceName());

        foreach ($this->getExcludedModuleNamePatterns() as $excludedModuleNamePattern) {
            if (preg_match($excludedModuleNamePattern, $moduleName)) {
                return true;
            }
        }

        return false;
    }
876175
protected function verifyInterface(ClassNode $node, ReflectionClass $interfaceReflection): void
    {
        $className = $node->getFullQualifiedName();
        $interfaceName = $interfaceReflection->getNamespaceName();

        $classModuleName = $this->getModuleName($className);

        if (!$classModuleName) {
            return;
        }

        $interfaceModuleName = $this->getModuleName($interfaceName);

        if ($classModuleName === $interfaceModuleName) {
            return;
        }

        if (preg_match('#Extension$#', $interfaceModuleName) !== 0) {
            return;
        }

        $this->addViolation(
            $node,
            [
                sprintf(
                    'The plugin class implements %s interface without participation of Extension module which violates rule "%s"',
                    $interfaceName,
                    static::RULE
                ),
            ]
        );
    }
458207
public function addChildNode(NodeInterface $childNode){
        $this->childNodes[] = $childNode;
        $childNode->setParentNode($this);
        return $this;
    }
1248368
protected function isRepository(ClassNode $classNode): bool
    {
        $className = $this->getClassName($classNode);

        if (preg_match(self::PATTERN_REPOSITORY, $className)) {
            return true;
        }

        return false;
    }
841462
public function add_children(& $node, $parentidnumber) {
        foreach ($this->flat as $competency) {
            if ($competency->parentidnumber == $parentidnumber) {
                $this->progress->increment_progress();
                $node->children[] = $competency;
                $this->add_children($competency, $competency->idnumber);
            }
        }
    }
1070875
protected function updateNodeParent($nodeId, $parent)
    {
        $config = $this->config;
        $this->getFluent()
                ->update($config['table'])
                ->set($config['prt'], $parent)
                ->where($config['id'], $nodeId)
                ->execute();
    }
219461
public function apply(AbstractNode $node)
    {
        /** @var \PDepend\Source\AST\ASTClass $node */
        if ($node->isAbstract()) {
            return;
        }

        if (empty($this->classRegex) || preg_match($this->classRegex, $node->getFullQualifiedName()) === 0) {
            return;
        }

        /** @var \PHPMD\Node\ClassNode $node */
        $this->applyImplementsInterfaceWithSameNameAndSuffix($node);
    }
997084
private function addSkipped(ParentNode $parent) {
    $parent->addChildren($this->getSkipNodes($this->skipped));
    $this->skipped = [];
    $this->matchDocComment($this->skipParent ?: $parent, NULL);
    $this->skipParent = NULL;
  }
584277
public function setParentNode(ElementtypeStructureNode $parentNode = null)
    {
        if ($parentNode) {
            $this->parentDsId = $parentNode->getDsId();
        }

        $this->parentNode = $parentNode;

        return $this;
    }