Generic formatting rules for control structures.

@param IfNode|ForNode|ForeachNode|SwitchNode|DoWhileNode|WhileNode $node
343238
protected function handleControlStructure($node) {
    $this->handleParens($node);
    $colons = $node->children(Filter::isTokenType(':'));
    foreach ($colons as $colon) {
      $this->removeSpaceBefore($colon);
    }
    if ($colons->isNotEmpty()) {
      $this->newlineBefore($node->lastChild()->previous());
    }
  }
361608
protected function handleBlock(Node $node)
    {

        if (!$node->name || $node->mode === 'ignore') //Will be handled through compileBlock when the loop encounters it
            return $this;

        //Find all other blocks with that name
        foreach ($this->blocks as $block) {

            if ($block === $node || $block->name !== $node->name)
                continue;

            $mode = $block->mode;
            //detach from parent
            $block->parent->remove($block);

            switch ($mode) {
                default:
                /** @noinspection PhpMissingBreakStatementInspection */
                case 'replace':

                    $node->children = [];
                //WANTED FALLTHROUGH!
                case 'append':

                    //Append to master block
                    foreach ($block->children as $child) {

                        $block->remove($child);
                        $node->append($child);
                    }
                    break;
                case 'prepend':

                    $last = null;
                    foreach ($block->children as $child) {

                        $block->remove($child);
                        if (!$last) {

                            $node->prepend($child);
                            $last = $child;
                            continue;
                        }

                        $node->insertAfter($last, $child);
                        $last = $child;
                    }
                    break;
            }

            $block->mode = 'ignore';
        }

        return $this;
    }
27995
public function enterNode(Node $node)
    {
        if ($node instanceof Class_ || $node instanceof Trait_) {
            $this->inClass = true;
        } elseif ($node instanceof FuncCall && !$this->inClass) {
            // We'll give any args at all (besides null) a pass.
            // Technically we should be checking whether the args are objects, but this will do for now.
            //
            // @todo switch this to actually validate args when we get context-aware code cleaner passes.
            if (!empty($node->args) && !$this->isNull($node->args[0])) {
                return;
            }

            // We'll ignore name expressions as well (things like `$foo()`)
            if (!($node->name instanceof Name)) {
                return;
            }

            $name = \strtolower($node->name);
            if (\in_array($name, ['get_class', 'get_called_class'])) {
                $msg = \sprintf('%s() called without object from outside a class', $name);
                throw new ErrorException($msg, 0, E_USER_WARNING, null, $node->getLine());
            }
        }
    }
508976
public function enterNode(Node $node): void
    {
        $name = null;

        if ($node instanceof Name) {
            $name = $node->toString();
        }

        if ($name === null
            || (array_key_exists($name, $this->symbols)
                && $this->symbols[$name] === false
            )
        ) {
            return;
        }

        if (!$this->filter->__invoke($name)) {
            $this->symbols[$name] = false;
            return;
        }

        if (!array_key_exists($name, $this->symbols)) {
            $this->symbols[$name] = [];
        }

        $this->symbols[$name][] = $node;
    }
436331
public function apply(AbstractNode $node)
    {
        if (preg_match('(\\\\[^\\\\]+Controller$)', $node->getFullQualifiedName()) === 0) {
            return;
        }
        if ($node->getName() === 'AbstractController') {
            return;
        }

        /** @var \PHPMD\Node\ClassNode $node */
        foreach ($node->getMethods() as $method) {
            $this->applyPublicMethodsHaveActionSuffix($method);
        }
    }
429179
protected function interruptNode(NodeInterface $node)
    {
        // if we have an interruptNodeId, bubble up until we match a node
        // else stop propagation
        return $this->interruptNodeId ? $this->interruptNodeId !== $node->getId() : false;
    }
601043
public function apply(AbstractNode $node)
    {
        if (preg_match('#^SprykerShop\\\\Client\\\\#', $node->getFullQualifiedName()) === 0) {
            return;
        }

        if ($this->isClassDeprecated($node)) {
            return;
        }

        $this->addViolation(
            $node,
            [
                sprintf(
                    'The %s class is in Client layer which violates rule "' . static::RULE . '"',
                    $node->getFullQualifiedName()
                ),
            ]
        );
    }
773637
public function pStmt_While(Stmt\While_ $node)
    {
        return sprintf(
            "%s (%s) %s%s\n%s",
            $this->color('while', SyntaxHighlighterConfig::TYPE_KEYWORD),
            $this->p($node->cond),
            $this->color('{', SyntaxHighlighterConfig::TYPE_BRACE),
            $this->pStmts($node->stmts),
            $this->color('}', SyntaxHighlighterConfig::TYPE_BRACE)
        );
    }
475324
public function apply(AbstractNode $node): void
    {
        if (!$this->isPlugin($node)) {
            return;
        }

        $pluginMethods = $node->getMethods();

        foreach ($pluginMethods as $pluginMethod) {
            $this->applyRule($pluginMethod);
        }
    }
1360569
private static void formatElseIfClauseWithNoDependencies(
      IfThenPair<?> condition, FormattingContext ctx) {
    ctx.append(" else if (").appendOutputExpression(condition.predicate).append(") ");
    try (FormattingContext ignored = ctx.enterBlock()) {
      ctx.appendAll(condition.consequent);
    }
  }
42981
function flipNode(node) {
  var rules = node.rules || node.keyframes || [];

  rules.forEach(function (rule, i, all) {
    if (rule.declarations) {
      if (isFlippable(rule, all[i - 1])) {
        processDeclarations(rule.declarations);
      }
    } else {
      flipNode(rule);
    }
  });
}
901244
public function onDeleteNode(NodeInterface $node)
    {
        $textNode = $this->textNodeManager->findTextNodeByNode($node);

        if (null !== $textNode) {
            $this->textNodeManager->remove($textNode);
            $this->textManager->remove($textNode->getText());
        }
    }
228738
public function apply(AbstractNode $node)
    {
        if (preg_match('#[A-Za-z0-9]+Constants$#', $node->getName()) === 0 ||
            preg_match('#\\\\Shared\\\\#', $node->getNamespaceName()) !== 0) {
            return;
        }

        $message = sprintf(
            'The environment configuration is not lie in "Shared" layer. That violates the rule "%s"',
            static::RULE
        );

        $this->addViolation($node, [$message]);
    }
172912
public function apply(NodeInterface $node, array $context)
    {
        $context['node'] = $node;

        // Check if this template should be applied at all
        if (!$this->isApplicable($context)) {
            return;
        }
        $this->setProperties($node, $context);

        // Create child nodes if applicable
        /** @var Template $childNodeTemplate */
        foreach ($this->childNodes as $childNodeTemplate) {
            $childNodeTemplate->createOrFetchAndApply($node, $context);
        }

        $this->emitNodeTemplateApplied($node, $context, $this->options);
    }
551708
public function apply(AbstractNode $node): void
    {
        if (!$this->isFacade($node)) {
            return;
        }

        $this->applyRule($node);
    }
295391
public function parseXml($node)
    {
        foreach ($node->childNodes as $item) {
            if ($item->nodeName != "#text") {
                $this->set( $item->nodeName, $item->nodeValue);
            }
        }

    }
935515
private function replaceNode(Node $node)
    {
        //Looking for parent block call
        if (!empty($inner = $node->findNode($this->name))) {
            //This construction allows child block use parent content
            $inner->nodes = $this->nodes;
        }

        $this->nodes = $node->nodes;
    }