private function spliceTree($envs, Block $block, $without)
{
$newBlock = null;
foreach ($envs as $e) {
if (!isset($e->block)) {
continue;
}
if ($e->block === $block) {
continue;
}
if (isset($e->block->type) && $e->block->type === Type::T_AT_ROOT) {
continue;
}
if ($e->block && $this->isWithout($without, $e->block)) {
continue;
}
$b = new Block();
$b->sourceIndex = $e->block->sourceIndex;
$b->sourceLine = $e->block->sourceLine;
$b->sourceColumn = $e->block->sourceColumn;
$b->selectors = [];
$b->comments = $e->block->comments;
$b->parent = null;
if ($newBlock) {
$type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK;
$b->children = [[$type, $newBlock]];
$newBlock->parent = $b;
} elseif (count($block->children)) {
foreach ($block->children as $child) {
if ($child[0] === Type::T_BLOCK) {
$child[1]->parent = $b;
}
}
$b->children = $block->children;
}
if (isset($e->block->type)) {
$b->type = $e->block->type;
}
if (isset($e->block->name)) {
$b->name = $e->block->name;
}
if (isset($e->block->queryList)) {
$b->queryList = $e->block->queryList;
}
if (isset($e->block->value)) {
$b->value = $e->block->value;
}
$newBlock = $b;
}
$type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK;
return [$type, $newBlock];
}