Check whether a variable declaration is safe in context

@param  DOMNode $node  Context node
@param  Tag     $tag   Source tag
@param  string  $query XPath query
@return void
338941
protected function checkVariableDeclaration(DOMNode $node, $tag, $query)
	{
		$query = 'ancestor-or-self::*/preceding-sibling::' . $query . '[@select]';
		$xpath = new DOMXPath($node->ownerDocument);
		foreach ($xpath->query($query, $node) as $varNode)
		{
			// Intercept the UnsafeTemplateException and change the node to the one we're
			// really checking before rethrowing it
			try
			{
				$this->checkExpression($varNode, $varNode->getAttribute('select'), $tag);
			}
			catch (UnsafeTemplateException $e)
			{
				$e->setNode($node);

				throw $e;
			}
		}
	}
1114586
public function scopeByTagNames($query, $tag_names)
	{
		$normalize_tag_names = [];
		foreach ($tag_names as $tag_name) {
			// mormalize string
			$normalize_tag_names[] = app(TaggingUtility::class)->normalizeTagName(trim($tag_name));
		}
		return $query->whereIn('name', $normalize_tag_names);
	}
112364
protected static function evaluate($query, DOMElement $element)
	{
		$xpath = new DOMXPath($element->ownerDocument);

		return $xpath->evaluate('boolean(' . $query . ')', $element);
	}
737203
public function scopeWithAnyTags(Builder $query, $tags)
    {
        $tags = static::convertToTags($tags);

        return $query->whereHas('tags', function (Builder $query) use ($tags) {
            $tagIds = $tags->pluck('id')->toArray();

            $query->whereIn('taggables.tag_id', $tagIds);
        });
    }
768006
protected function checkElementNode(DOMElement $element, Tag $tag)
	{
		$xpath = new DOMXPath($element->ownerDocument);

		// If current node is not an <xsl:attribute/> element, we exclude descendants
		// with an <xsl:attribute/> ancestor so that content such as:
		//   <script><xsl:attribute name="id"><xsl:value-of/></xsl:attribute></script>
		// would not trigger a false-positive due to the presence of an <xsl:value-of/>
		// element in a <script>
		$predicate = ($element->localName === 'attribute') ? '' : '[not(ancestor::xsl:attribute)]';

		// Test the select expression of <xsl:value-of/> nodes
		$query = './/xsl:value-of' . $predicate;
		foreach ($xpath->query($query, $element) as $valueOf)
		{
			$this->checkSelectNode($valueOf->getAttributeNode('select'), $tag);
		}

		// Reject all <xsl:apply-templates/> nodes
		$query = './/xsl:apply-templates' . $predicate;
		foreach ($xpath->query($query, $element) as $applyTemplates)
		{
			throw new UnsafeTemplateException('Cannot allow unfiltered data in this context', $applyTemplates);
		}
	}
1364045
protected function replaceMarkerWithContent($node, $tag)
    {
        $content = $this->getShortcodeReplacementText($tag);

        if ($content) {
            /** @var HTMLValue $parsed */
            $parsed = HTMLValue::create($content);
            $body = $parsed->getBody();
            if ($body) {
                $this->insertListAfter($body->childNodes, $node);
            }
        }

        $this->removeNode($node);
    }
51104
public function check(DOMElement $template, Tag $tag)
	{
		$node = $template->getElementsByTagNameNS($this->namespaceURI, $this->elName)->item(0);

		if ($node)
		{
			throw new UnsafeTemplateException("Element '" . $node->nodeName . "' is disallowed", $node);
		}
	}
941804
public function scopeByTagName($query, $tag_name)
	{
		// mormalize string
		$tag_name = app(TaggingUtility::class)->normalizeTagName(trim($tag_name));
		return $query->where('name', $tag_name);
	}
1270792
public static function scopeWithTag(Builder $query, $tags, $type = 'slug')
    {
        $tags = (new static())->prepareTags($tags);

        return $query->whereHas('tags', function ($query) use ($type, $tags) {
            $query->whereIn($type, $tags);
        });
    }
1290528
protected function isValidTag(string $tag, Message $message = null): void
    {
        $allowedTag = $this->getAllowedTag();
        if (!\in_array($tag, $allowedTag, true)) {
            throw new InvalidKeyException(sprintf(
                'tag must be either "%s".',
                implode(', ', $allowedTag)
            ));
        }

        if ($tag === SendInterface::TAG_ISSUE_RESOLUTION && $message !== null && !$message instanceof GenericTemplate) {
            throw new InvalidClassException(sprintf(
                'message must be an instance of %s if tag is set to %s.',
                GenericTemplate::class,
                SendInterface::TAG_ISSUE_RESOLUTION
            ));
        }
    }
124620
function(name, nodes) {
          if (name !== 'declaration') {
            return false;
          }

          if (
              nodes.content[0] &&
              nodes.content[0].content &&
              nodes.content[0].content[0] &&
              nodes.content[0].content[0].type &&
              nodes.content[0].content[0].type === 'variable'
            ) {
            return true;
          }

        }
1159606
private function xpathQuery(string $query, DOMNode $element = null): DOMNodeList
    {
        if (null === $element) {
            $element = $this->dom()->documentElement;
        }
        if (null === $element->ownerDocument) {
            throw new \LogicException('Cannot create a XPath query on an element without document');
        }
        /** @var DOMNodeList|false $nodelist phpstan does not know that query can return false */
        $nodelist = (new DOMXPath($element->ownerDocument))->query($query, $element);
        if (false === $nodelist) {
            $nodelist = new DOMNodeList();
        }
        return $nodelist;
    }
942726
public function scopeWithTags($query, $tags)
    {
        $tags = $this->makeTagsArray($tags);

        foreach ($tags as $tag)
            $this->scopeWithTag($query, $tag);

        return $query;
    }
175421
function containsString(query, node) {
  var value = node[query.name]
  return typeof value === 'string' && value.indexOf(query.value) !== -1
}
375685
public function scopeWithAnyTag(Builder $query, $tagNames): Builder
    {
        if(!is_array($tagNames)) {
            $tagNames = func_get_args();
            array_shift($tagNames);
        }

        $tagNames = static::$taggingUtility->makeTagArray($tagNames);

        $normalizer = config('tagging.normalizer');
        $normalizer = $normalizer ?: [static::$taggingUtility, 'slug'];

        $tagNames = array_map($normalizer, $tagNames);
        $className = $query->getModel()->getMorphClass();

        $tags = Tagged::query()
            ->whereIn('tag_slug', $tagNames)
            ->where('taggable_type', $className)
            ->get()
            ->pluck('taggable_id');

        $primaryKey = $this->getKeyName();
        return $query->whereIn($this->getTable().'.'.$primaryKey, $tags);
    }
535770
private static function logQuery(string $query): void
  {
    $query = trim($query);

    if (strpos($query, "\n")!==false)
    {
      // Query is a multi line query.
      self::$io->logVeryVerbose('Executing query:');
      self::$io->logVeryVerbose('<sql>%s</sql>', $query);
    }
    else
    {
      // Query is a single line query.
      self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
    }
  }
1256290
public function visit($query, $node, string $context)
    {
        if ($node instanceof $this->node) {
            $bindings = [];
            $sql = [];

            $child0 = $node->getChildByIndex(0);
            $child1 = $node->getChildByIndex(1);

            if ($child0 instanceof Nodes\KeyNode) {
                $context === Nodes\OrNode::class && $query->orWhereNotNull($this->parseKey($child0->getValue()));
                $context === Nodes\AndNode::class && $query->whereNotNull($this->parseKey($child0->getValue()));
            }
        }
    }