Ejemplo n.º 1
0
 /**
  * Updates the currentFileInfo object to the $value
  *
  * @param Node $node The node to update
  * @param FileInfo $newInfo The new file info
  */
 protected function updateReferenceInCurrentFileInfo(Node $node, FileInfo $newInfo)
 {
     if (isset($node->currentFileInfo)) {
         $node->currentFileInfo->reference = $newInfo->reference;
         $node->currentFileInfo->rootPath = $newInfo->rootPath;
     }
     if (Node::propertyExists($node, 'rules') && is_array($node->rules) && $node->rules) {
         foreach ($node->rules as $rule) {
             $this->updateReferenceInCurrentFileInfo($rule, $newInfo);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Visits a ruleset node
  *
  * @param RulesetNode $node The node
  * @param VisitorArguments $arguments The arguments
  * @return array|RulesetNode
  */
 public function visitRuleset(RulesetNode $node, VisitorArguments $arguments)
 {
     if ($node->firstRoot) {
         $this->checkPropertiesInRoot($node->rules);
     }
     $rulesets = [];
     if (!$node->root) {
         $paths = [];
         foreach ($node->paths as $p) {
             if ($p[0]->elements[0]->combinator->value === ' ') {
                 $p[0]->elements[0]->combinator = new CombinatorNode('');
             }
             foreach ($p as $pi) {
                 /* @var $pi SelectorNode */
                 if ($pi->getIsReferenced() && $pi->getIsOutput()) {
                     $paths[] = $p;
                     break;
                 }
             }
         }
         $node->paths = $paths;
         // Compile rules and rulesets
         for ($i = 0, $count = count($node->rules); $i < $count;) {
             $rule = $node->rules[$i];
             //if ($rule instanceof ILess\ILess\Node\RuleNode || $rule instanceof ILess\ILess\Node\RulesetNode) {
             //if ($rule instanceof ILess\ILess\Node\RulesetNode) {
             if (Node::propertyExists($rule, 'rules')) {
                 // visit because we are moving them out from being a child
                 $rulesets[] = $this->visit($rule);
                 array_splice($node->rules, $i, 1);
                 $count--;
                 continue;
             }
             $i++;
         }
         // accept the visitor to remove rules and refactor itself
         // then we can decide now whether we want it or not
         if ($count > 0) {
             $node->accept($this);
         } else {
             $node->rules = [];
         }
         $arguments->visitDeeper = false;
         // accept the visitor to remove rules and refactor itself
         // then we can decide now whether we want it or not
         if ($node->rules) {
             // passed by reference
             $this->mergeRules($node->rules);
         }
         if ($node->rules) {
             // passed by reference
             $this->removeDuplicateRules($node->rules);
         }
         // now decide whether we keep the ruleset
         if ($node->rules && $node->paths) {
             array_splice($rulesets, 0, 0, [$node]);
         }
     } else {
         $node->accept($this);
         $arguments->visitDeeper = false;
         if ($node->firstRoot || count($node->rules) > 0) {
             array_splice($rulesets, 0, 0, [$node]);
         }
     }
     if (count($rulesets) === 1) {
         return $rulesets[0];
     }
     return $rulesets;
 }