/** * Pops a style from the stack. * * @param OutputFormatterStyleInterface $style * * @return OutputFormatterStyleInterface * * @throws \InvalidArgumentException When style tags incorrectly nested */ public function pop(OutputFormatterStyleInterface $style = null) { if (empty($this->styles)) { return $this->emptyStyle; } if (null === $style) { return array_pop($this->styles); } foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { if ($style->apply('') === $stackedStyle->apply('')) { $this->styles = array_slice($this->styles, 0, $index); return $stackedStyle; } } throw new \InvalidArgumentException('Incorrectly nested style tag found.'); }
/** * Applies style to text if must be applied. * * @param OutputFormatterStyleInterface $style Style to apply * @param string $text Input text * * @return string string Styled text */ private function applyStyle(OutputFormatterStyleInterface $style, $text) { return $this->isDecorated() && strlen($text) > 0 ? $style->apply($text) : $text; }