for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace MewesK\TwigExcelBundle\Twig\TokenParser\Traits;
use MewesK\TwigExcelBundle\Twig\Node\XlsCellNode;
use MewesK\TwigExcelBundle\Twig\Node\XlsCenterNode;
use MewesK\TwigExcelBundle\Twig\Node\XlsLeftNode;
use MewesK\TwigExcelBundle\Twig\Node\XlsNode;
use MewesK\TwigExcelBundle\Twig\Node\XlsRightNode;
use Twig_Node;
use Twig_Node_Block;
use Twig_Node_BlockReference;
use Twig_Node_Text;
/**
* Class RemoveTextNodeTrait
*
* @package MewesK\TwigExcelBundle\Twig\TokenParser
*/
trait RemoveTextNodeTrait
{
* @param Twig_Node $node
protected function removeTextNodesRecursively(Twig_Node $node)
foreach ($node->getIterator() as $key => $subNode) {
if ($subNode instanceof Twig_Node_Text) {
// Never delete a block body
if ($key === 'body' && $node instanceof Twig_Node_Block) {
continue;
}
$node->removeNode($key);
} elseif ($subNode instanceof Twig_Node_BlockReference) {
$this->removeTextNodesRecursively($this->parser->getBlock($subNode->getAttribute('name')));
parser
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
} elseif ($subNode instanceof Twig_Node && $subNode->count() > 0) {
if ($subNode instanceof XlsNode && $subNode->canContainText()) {
$this->removeTextNodesRecursively($subNode);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: