Get all directives of a certain type that are associated with an AST node.

@param  \GraphQL\Language\AST\Node  $node
@param  string  $directiveClass
@return \Illuminate\Support\Collection <$directiveClass>
186966
protected function createAssociatedDirectivesOfType(Node $node, string $directiveClass): Collection
    {
        return (new Collection($node->directives))
            ->map(function (DirectiveNode $directive) use ($node) {
                return $this->create($directive->name->value, $node);
            })
            ->filter(function (Directive $directive) use ($directiveClass) {
                return $directive instanceof $directiveClass;
            });
    }
1345820
public function getTypeForDOMNode( $node )
	{
		$ns = $node->namespaceURI;
		if ( ! $ns )
		{
			if ( $node instanceof \DOMElement )
			{
				// Get the default namespace for the DOMNode
				$doc = $node->ownerDocument;
				/**
				 * @var DOMNode $firstChild
				 */
				$firstChild = $doc->documentElement;
				$ns = $firstChild->getAttributeNode('xmlns')
					? $firstChild->getAttributeNode('xmlns')->nodeValue
					: "";
			}
			else if ( $node instanceof \DOMAttr )
			{
				$parent = $node->parentNode;
				if ( $parent )
				{
					$ns = $parent->namespaceURI;
				}
			}
		}

		$prefix = $this->getPrefixForNamespace( $ns );
		$types;

		if ( is_a( $node, "DOMElement" ) )
		{
			$el = $this->getElement( $node->localName, $prefix );
			if ( $el === false ) throw new SchemaException( "Unable to locate element '{$node->localName}' in the schema types" );
			$types = isset( $el['types'] ) ? $el['types'] : array();
		}
		else if ( is_a( $node, "DOMAttr" ) )
		{
			$attr = $this->getAttribute( $node->localName, $prefix );
			if ( $attr === false ) throw new SchemaException( "Unable to locate attribute '{$node->localName}' in the schema types" );
			$types = isset( $attr['types'] ) ? $attr['types'] : array();
		}
		else if ( is_a( $node, "DOMDocument" ) )
		{
			throw new SchemaException("Getting the type for a Document node is not supported");
		}
		else if ( is_a( $node, "DOMComment" ) )
		{
			// BMS 2018-04-09 Test candidates changed.
			return "xs:string";
		}
		else if ( is_a( $node, "DOMProcessingInstruction" ) )
		{
			throw new SchemaException("Getting the type for a Processing Instruction node is not supported");
		}
		else if ( is_a( $node, "DOMText" ) )
		{
			// BMS 2018-04-09 Test candidates changed.
			return "xs:string";
		}
		else if ( is_a( $node, "DOMNameSpaceNode" ) )
		{
			throw new SchemaException("Getting the type for a Namespace node is not supported");
		}

		// Get the first simple type
		$type = null;
		foreach ( $types as $xmlType )
		{
			if ( is_array( $xmlType ) )
			{
				if ( isset( $xmlType['class'] ) && $xmlType['class'] == "complex" )
				{
					continue;
				}

				if ( isset( $xmlType['contentType'] ) && $xmlType['contentType'] == "extension" && isset( $xmlType['base'] ) )
				{
					return $xmlType['parent'];
				}

				if ( isset( $xmlType['contentType'] ) && $xmlType['contentType'] == "restriction" && isset( $xmlType['base'] ) )
				{
					return $xmlType['parent'];
				}
			}

			return $xmlType;
		}

		return false;
	}
748280
protected function pStmt_ClassMethod(Stmt\ClassMethod $node)
    {
        $classMethod = parent::pStmt_ClassMethod($node);

        if ($node->returnType) {
            $classMethod = str_replace(') :', '):', $classMethod);
        }

        return $classMethod;
    }
957228
public function getInternalLinks( \DOMNode $node ) : array
	{
		$this->guardHasOwnerDocument( $node );

		$internalLinks = [];
		$xpath         = new \DOMXPath( $node->ownerDocument );
		$aTags         = $xpath->query( '*//a[@href]' );

		/** @var \DOMElement $aTag */
		foreach ( $aTags as $aTag )
		{
			$href = $aTag->getAttribute( 'href' );
			if ( !$this->isHyperRefIgnored( $href ) )
			{
				$internalLinks[] = $aTag;
			}
		}

		return $internalLinks;
	}
810313
public function getChildrenOfClass($class)
    {
        // Check for namespace alias
        if (strpos($class, ':') !== false) {
            list($namespaceAlias, $simpleClassName) = explode(':', $class);
            $class = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
        }
        $result = array();
        $children = $this->getChildren();
        foreach ($children as $child) {
            if ($child->getPage() instanceof $class) {
                $result[] = $child;
            }
        }

        return $result;
    }
1327163
private function getNodes($node)
    {
        $this->logger->info('[Get Nodes] Retrieving nodes...');

        $stripUnlikelyCandidates = $this->configuration->getStripUnlikelyCandidates();

        $elementsToScore = [];

        /*
         * First, node prepping. Trash nodes that look cruddy (like ones with the
         * class name "comment", etc), and turn divs into P tags where they have been
         * used inappropriately (as in, where they contain no other block level elements.)
         */

        while ($node) {
            // Remove DOMComments nodes as we don't need them and mess up children counting
            if ($node->nodeType === XML_COMMENT_NODE) {
                $this->logger->debug(sprintf('[Get Nodes] Found comment node, removing... Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            $matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id');

            if (!$node->isProbablyVisible()) {
                $this->logger->debug(sprintf('[Get Nodes] Removing hidden node... Match string was: \'%s\'', $matchString));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            // Check to see if this node is a byline, and remove it if it is.
            if ($this->checkByline($node, $matchString)) {
                $this->logger->debug(sprintf('[Get Nodes] Found byline, removing... Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            // Remove unlikely candidates
            if ($stripUnlikelyCandidates) {
                if (
                    preg_match(NodeUtility::$regexps['unlikelyCandidates'], $matchString) &&
                    !preg_match(NodeUtility::$regexps['okMaybeItsACandidate'], $matchString) &&
                    $node->nodeName !== 'body' &&
                    $node->nodeName !== 'a'
                ) {
                    $this->logger->debug(sprintf('[Get Nodes] Removing unlikely candidate. Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $node = NodeUtility::removeAndGetNext($node);
                    continue;
                }
            }

            // Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe).
            if (($node->nodeName === 'div' || $node->nodeName === 'section' || $node->nodeName === 'header' ||
                    $node->nodeName === 'h1' || $node->nodeName === 'h2' || $node->nodeName === 'h3' ||
                    $node->nodeName === 'h4' || $node->nodeName === 'h5' || $node->nodeName === 'h6' ||
                    $node->nodeName === 'p') &&
                $node->isElementWithoutContent()) {
                $this->logger->debug(sprintf('[Get Nodes] Removing empty \'%s\' node.', $node->nodeName));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            if (in_array(strtolower($node->nodeName), $this->defaultTagsToScore)) {
                $this->logger->debug(sprintf('[Get Nodes] Adding node to score list, node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                $elementsToScore[] = $node;
            }

            // Turn all divs that don't have children block level elements into p's
            if ($node->nodeName === 'div') {
                // Put phrasing content into paragraphs.
                $p = null;
                $childNode = $node->firstChild;
                while ($childNode) {
                    $nextSibling = $childNode->nextSibling;
                    if ($childNode->isPhrasingContent()) {
                        if ($p !== null) {
                            $p->appendChild($childNode);
                        } elseif (!$childNode->isWhitespace()) {
                            $p = $this->dom->createElement('p');
                            $node->replaceChild($p, $childNode);
                            $p->appendChild($childNode);
                        }
                    } elseif ($p !== null) {
                        while ($p->lastChild && $p->lastChild->isWhitespace()) {
                            $p->removeChild($p->lastChild);
                        }
                        $p = null;
                    }
                    $childNode = $nextSibling;
                }

                /*
                 * Sites like http://mobile.slate.com encloses each paragraph with a DIV
                 * element. DIVs with only a P element inside and no text content can be
                 * safely converted into plain P elements to avoid confusing the scoring
                 * algorithm with DIVs with are, in practice, paragraphs.
                 */
                if ($node->hasSingleTagInsideElement('p') && $node->getLinkDensity() < 0.25) {
                    $this->logger->debug(sprintf('[Get Nodes] Found DIV with a single P node, removing DIV. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $pNode = $node->getChildren(true)[0];
                    $node->parentNode->replaceChild($pNode, $node);
                    $node = $pNode;
                    $elementsToScore[] = $node;
                } elseif (!$node->hasSingleChildBlockElement()) {
                    $this->logger->debug(sprintf('[Get Nodes] Found DIV with a single child block element, converting to a P node. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $node = NodeUtility::setNodeTag($node, 'p');
                    $elementsToScore[] = $node;
                }
            }

            $node = NodeUtility::getNextNode($node);
        }

        return $elementsToScore;
    }
1118103
protected function openNode( Node$node ):self
	{
		array_push($this->openedNodes,$node);

		$node->scope and $this->setScope($node);

		return $this;
	}
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);
                }
            }
        }
    }
453535
private static <D extends Directive> List<D> listFilter(Iterable<? extends Directive> directives,
                                                          DirectiveKind directiveKind,
                                                          Class<D> clazz) {
        List<D> list = new ArrayList<>();
        for (Directive d : directives) {
            if (d.getKind() == directiveKind)
                list.add(clazz.cast(d));
        }
        return list;
    }
727915
protected function getSingleArgumentDefinition(): InputValueDefinitionNode
    {
        if (count($this->definitionNode->arguments) !== 1) {
            throw new DirectiveException(
                "The @delete directive requires the field {$this->definitionNode->name->value} to only contain a single argument."
            );
        }

        return $this->definitionNode->arguments[0];
    }
12151
protected function getChildren(NodeBuilder $node)
    {
        $node = $this->getOptionsNodes($node);
        $node = $this->getConnectionsNodes($node);
        $node = $this->getOverridesNodes($node);

        return $node;
    }
882236
protected function transpileDirectiveNode(Node $node) : string
    {
        $children = $node->getChildren();

        if (count($children) === 0) {
            return '';
        }

        $directiveName = $children[0]->getValue();
        $expression = count($children) === 2 ? $children[1]->getValue() : '';

        if (!isset($this->directiveTranspilers[$directiveName])) {
            throw new RuntimeException(
                sprintf(
                    'No transpiler registered for directive "%s"',
                    $directiveName
                )
            );
        }

        return $this->directiveTranspilers[$directiveName]($expression);
    }
385658
private static function getContainingClassFqn(Node $node)
    {
        $classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
        if ($classNode === null) {
            return null;
        }
        return (string)$classNode->getNamespacedName();
    }
612458
protected function setNode($node)
    {
        $allowedClasses = ['DOMElement', 'DOMText', 'DOMComment', 'DOMCdataSection'];

        if (!is_object($node) || !in_array(get_class($node), $allowedClasses, true)) {
            throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of DOMElement, DOMText, DOMComment or DOMCdataSection, %s given', __METHOD__, (is_object($node) ? get_class($node) : gettype($node))));
        }

        $this->node = $node;

        return $this;
    }
1331195
protected static function DOMNodeAttributes(DOMNode $node)
    {
        $attributes = array();

        foreach ($node->attributes as $attribute) {
            $attributes[$attribute->name] = $attribute->value;
        }

        return $attributes;
    }
373656
public function getCollectionByDocumentClass($documentClass): Collection
    {
        $metadata = $this->metadataFactory->getClassMetadata($documentClass);

        return $this->getCollection($metadata->getCollectionName(), $metadata->getCollectionOptions());
    }
1280066
public function processNode(Node $node, Scope $scope): array
    {
        $returnType = $node->getReturnType();

        if (!$returnType instanceof Node\NullableType) {
            return [];
        }

        /** @var Reflection\ClassReflection $classReflection */
        $classReflection = $scope->getClassReflection();

        if ($classReflection->isAnonymous()) {
            return [
                \sprintf(
                    'Method %s() in anonymous class has a nullable return type declaration.',
                    $node->name->name
                ),
            ];
        }

        return [
            \sprintf(
                'Method %s::%s() has a nullable return type declaration.',
                $classReflection->getName(),
                $node->name->name
            ),
        ];
    }