Template -check- tag handler
@return string
@param $node array
347565
protected function _check(array $node) {
		$attrib=$node['@attrib'];
		unset($node['@attrib']);
		// Grab <true> and <false> blocks
		foreach ($node as $pos=>$block)
			if (isset($block['true']))
				$true=[$pos,$block];
			elseif (isset($block['false']))
				$false=[$pos,$block];
		if (isset($true,$false) && $true[0]>$false[0])
			// Reverse <true> and <false> blocks
			list($node[$true[0]],$node[$false[0]])=[$false[1],$true[1]];
		return
			'<?php if ('.$this->token($attrib['if']).'): ?>'.
				$this->build($node).
			'<?php endif; ?>';
	}
743145
public function markingFilterMatches($node) {
        if(!$this->markingFilter) {
            return true;
        }
    
        if(isset($this->markingFilter['parameter']) && $parameterName=$this->markingFilter['parameter']) {
            if(is_array($this->markingFilter['value'])){
                $ret=false;
                foreach($this->markingFilter['value'] as $value) {
                    $ret=$ret||$node->$parameterName==$value;
                    if($ret == true) {
                        break;
                    }
                }
                return $ret;
            } else {
                return ($node->$parameterName == $this->markingFilter['value']);
            }
        } else if ($func=$this->markingFilter['func']) {
            return call_user_func($func, $node);
        }
    }
1344824
public function getDocumentationFromNode($node)
    {
        // Any NamespaceDefinition comments likely apply to the file, not the declaration itself.
        if ($node instanceof Node\Statement\NamespaceDefinition) {
            return null;
        }

        // For properties and constants, set the node to the declaration node, rather than the individual property.
        // This is because they get defined as part of a list.
        $constOrPropertyDeclaration = ParserHelpers\tryGetPropertyDeclaration($node) ?? ParserHelpers\tryGetConstOrClassConstDeclaration($node);
        if ($constOrPropertyDeclaration !== null) {
            $node = $constOrPropertyDeclaration;
        }

        // For parameters, parse the function-like declaration to get documentation for a parameter
        if ($node instanceof Node\Parameter) {
            $variableName = $node->getName();

            $functionLikeDeclaration = ParserHelpers\getFunctionLikeDeclarationFromParameter($node);
            $docBlock = $this->getDocBlock($functionLikeDeclaration);

            $parameterDocBlockTag = $this->tryGetDocBlockTagForParameter($docBlock, $variableName);
            return $parameterDocBlockTag !== null ? $parameterDocBlockTag->getDescription()->render() : null;
        }

        // For everything else, get the doc block summary corresponding to the current node.
        $docBlock = $this->getDocBlock($node);
        if ($docBlock !== null) {
            // check whether we have a description, when true, add a new paragraph
            // with the description
            $description = $docBlock->getDescription()->render();

            if (empty($description)) {
                return $docBlock->getSummary();
            }

            return $docBlock->getSummary() . "\n\n" . $description;
        }
        return null;
    }
472556
protected function _switch(array $node) {
		$attrib=$node['@attrib'];
		unset($node['@attrib']);
		foreach ($node as $pos=>$block)
			if (is_string($block) && !preg_replace('/\s+/','',$block))
				unset($node[$pos]);
		return
			'<?php switch ('.$this->token($attrib['expr']).'): ?>'.
				$this->build($node).
			'<?php endswitch; ?>';
	}
818974
public function filter($node)
    {
        $ret = array();
        $items = $this->_combinator->filter($node, $this->_element->getTagName());

        // filters items by element
        foreach ($items as $item) {
            if ($this->_element->match($item)) {
                array_push($ret, $item);
            }
        }

        // filter items by element filters
        $filters = $this->_element->getFilters();
        foreach ($filters as $filter) {
            $items = array();
            foreach ($ret as $i => $item) {
                if ($filter->match($item, $i, $ret)) {
                    array_push($items, $item);
                }
            }
            $ret = $items;
        }

        return $ret;
    }
398501
public function getDeclarationLineFromNode($node): string
    {
        // If node is part of a declaration list, build a declaration line that discludes other elements in the list
        //  - [PropertyDeclaration] // public $a, [$b = 3], $c; => public $b = 3;
        //  - [ConstDeclaration|ClassConstDeclaration] // "const A = 3, [B = 4];" => "const B = 4;"
        if (
            ($declaration = ParserHelpers\tryGetPropertyDeclaration($node)) && ($elements = $declaration->propertyElements) ||
            ($declaration = ParserHelpers\tryGetConstOrClassConstDeclaration($node)) && ($elements = $declaration->constElements)
        ) {
            $defLine = $declaration->getText();
            $defLineStart = $declaration->getStart();

            $defLine = \substr_replace(
                $defLine,
                $node->getFullText(),
                $elements->getFullStart() - $defLineStart,
                $elements->getFullWidth()
            );
        } else {
            $defLine = $node->getText();
        }

        // Trim string to only include first line
        $defLine = \rtrim(\strtok($defLine, "\n"), "\r");

        // TODO - pretty print rather than getting text

        return $defLine;
    }
835154
protected function getRelevantNodeText($node)
    {
        if (!$node->hasChildNodes()) {
            return $node->innertext();
        }

        $output = '';
        foreach ($node->nodes as $child) {
            /* @var $child \simple_html_dom_node */
            if (!$child->hasChildNodes()) {
                $output .= $child->outertext();
            } elseif (in_array($child->nodeName(), static::$listContentTags, true)) {
                $output .= sprintf('<%1$s>%2$s</%1$s>', $child->nodeName(), $this->getRelevantNodeText($child));
            }
        }

        return $output;
    }
976523
protected function compileConditional(Node $node)
    {

        $type = $node->conditionType;
        $subject = $node->subject;

        if ($subject === 'block')
            $subject = '$__block';

        if ($this->isVariable($subject))
            $subject = "isset($subject) ? $subject : false";

        if ($type === 'unless') {

            $type = 'if';
            $subject = "!($subject)";
        }

        $isPrevConditional = $node->prev() && $node->prev()->type === 'conditional' && $type !== 'if';
        $isNextConditional = $node->next()
            && $node->next()->type === 'conditional'
            && $node->next()->conditionType !== 'if'
            && $node->next()->conditionType !== 'unless';
        $prefix = $isPrevConditional ? '' : '<?php ';
        $suffix = $isNextConditional ? '' : '?>';
        $phtml = $type === 'else'
            ? $this->createCode(' else {', $prefix)
            : $this->createCode("$type ($subject) {", $prefix);
        $phtml .= $this->compileChildren($node->children);
        $phtml .= $this->newLine().$this->indent().$this->createCode("}", '<?php ', $suffix);

        return $phtml;
    }
1116133
public static function checkModuleLink($node)
    {
        $module = Module::getModuleByClassname(Module::className());
        $langHelper = $module->langHelper;

        $contentAction = "{$module->uniqueId}/main/view"; // route to reject

        $nodeLink = static::getNodePath($node);

        $moduleInfo = false;
        
        // find such route 
        $resultRule = false;
        foreach (Yii::$app->urlManager->rules as $nextRule) {
            if (RoutesBuilder::properRule($nextRule, $nodeLink)) {
                if (isset($nextRule->route) && $nextRule->route == $contentAction) {
                    continue;
                }
                $resultRule = $nextRule;
                break;
            }
        }
        $moduleInfo = false;
        if ($resultRule) {
            if (isset($resultRule->route)) {
                $route = $resultRule->route;
            } else if (isset($resultRule->rules[0])) { // yii\web\GroupUrlRule
                $route = $resultRule->rules[count($resultRule->rules) - 1]->route; // get latest route from group
            } else {
                $route = false; // unsupported route type
            }
            $hrefs = false; // unknown link to module's backend 
            if ($route) {
                $hrefs = [];
                foreach ($langHelper::activeLanguages($all = true) as $langCode => $lang) {
                    $hrefs[$langCode] = Url::toRoute(["/{$route}", 'lang' => $langCode]);
                }
            }
            $moduleInfo = [
                'text' => Yii::t($module->tcModule, 'module'),
                'hrefs' => $hrefs,
            ];
        }
        return $moduleInfo;
    }
883352
protected function collapseTokenTree($node)
    {
        $text = '';
        foreach ($node['children'] as $c) {
            if (is_string($c)) {
                $text .= Utils::escapeString($c);
            } else {
                $text .= $this->collapseTokenTree($c);
            }
        }
        $tokenName = $node['token_name'];
        $token = array($node['token_name'], $text, true);

        $token_ = $this->ruleMapperFilter(array($token));
        $token = $token_[0];

        if (isset($this->filters[$tokenName])) {
            foreach ($this->filters[$tokenName] as $filter) {
                $token = call_user_func($filter[1], $token);
            }
        }
        list($tokenName, $text,) = $token;
        return ($tokenName === null) ? $text : Utils::tagBlock($tokenName, $text);
    }
27615
private function getSearchTerm(SearchNode $node)
    {
        $fullTerm = $node->getSearchQuery();

        foreach ($this->fullTermPatterns as $pattern) {
            if (preg_match($pattern, $fullTerm, $matches) === 1) {
                return '"'.$fullTerm.'"';
            }
        }

        if ($this->andifyTerms) {
            $glue = 'AND';
        } else {
            $glue = '';
        }


        $i = 0;
        $hasPreviousOperator = false;
        $fullSearchElements = [];

        foreach (explode(' ', $node->getSearchQuery()) as $term) {
            $i++;

            // is this an operator?
            if (array_search($term, $this->queryOperators) !== false) {
                $fullSearchElements[] = $term;
                $hasPreviousOperator = true;
                continue;
            }

            $singleTerm = $this->getSingleTerm($term);

            if ($i > 1 && $hasPreviousOperator == false && !empty($glue)) {
                $fullSearchElements[] = $glue;
            } else {
                $hasPreviousOperator = false;
            }

            $fullSearchElements[] = $singleTerm;
        }

        return implode(' ', $fullSearchElements);
    }
1367902
public static function dom2str($node)
    {
        $doc = $node instanceof DOMDocument? $node : $node->ownerDocument;
        return $doc->saveXML($node);
    }
851899
protected function getDisplayText(Node $node) {
    if ($this->isRootTypeNode($node->getOID())) {
      $mapper = $node->getMapper();
      return $mapper->getTypeDisplayName($this->getMessage());
    }
    else {
      return strip_tags(preg_replace("/[\r\n']/", " ", NodeUtil::getDisplayValue($node)));
    }
  }
940786
protected function _case(array $node) {
		$attrib=$node['@attrib'];
		unset($node['@attrib']);
		return
			'<?php case '.(preg_match('/\{\{(.+?)\}\}/',$attrib['value'])?
				$this->token($attrib['value']):
				Base::instance()->stringify($attrib['value'])).': ?>'.
				$this->build($node).
			'<?php '.(isset($attrib['break'])?
				'if ('.$this->token($attrib['break']).') ':'').
				'break; ?>';
	}
251088
protected function checkNode(DOMNode $node, Tag $tag)
	{
		if ($node instanceof DOMAttr)
		{
			$this->checkAttributeNode($node, $tag);
		}
		elseif ($node instanceof DOMElement)
		{
			if ($node->namespaceURI === self::XMLNS_XSL && $node->localName === 'copy-of')
			{
				$this->checkCopyOfNode($node, $tag);
			}
			else
			{
				$this->checkElementNode($node, $tag);
			}
		}
	}
162013
public static function get_block_parent_name( \DOMNode $node ) {
		$parent = self::get_block_parent( $node );

		if ( ! empty( $parent ) ) {
			return $parent->tagName;
		} else {
			return '';
		}
	}
618171
public function refactor(Node $node): ?Node
    {
        if (! $this->isName($node, 'parse')) {
            return null;
        }

        if (! $this->isType($node->class, 'Symfony\Component\Yaml\Yaml')) {
            return null;
        }

        if (! $this->isArgumentYamlFile($node)) {
            return null;
        }

        $fileGetContentsFunCallNode = $this->createFunction('file_get_contents', [$node->args[0]]);
        $node->args[0] = new Arg($fileGetContentsFunCallNode);

        return $node;
    }