Example of set: ["@PSR2" => true, "@PSR1" => false, "strict" => true].
Author: Dariusz Rumiński (dariusz.ruminski@gmail.com)
Ejemplo n.º 1
0
 /**
  * Apply RuleSet on fixers to filter out all unwanted fixers.
  *
  * @param RuleSetInterface $ruleSet
  *
  * @return $this
  */
 public function useRuleSet(RuleSetInterface $ruleSet)
 {
     $fixers = array();
     $fixersByName = array();
     foreach (array_keys($ruleSet->getRules()) as $name) {
         if (!array_key_exists($name, $this->fixersByName)) {
             throw new \UnexpectedValueException(sprintf('Rule "%s" does not exist.', $name));
         }
         $fixer = $this->fixersByName[$name];
         $fixer->configure($ruleSet->getRuleConfiguration($name));
         $fixers[] = $fixer;
         $fixersByName[$name] = $fixer;
     }
     $this->fixers = $fixers;
     $this->fixersByName = $fixersByName;
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Apply RuleSet on fixers to filter out all unwanted fixers.
  *
  * @param RuleSetInterface $ruleSet
  *
  * @return $this
  */
 public function useRuleSet(RuleSetInterface $ruleSet)
 {
     $fixers = array();
     $fixersByName = array();
     $fixerConflicts = array();
     $fixerNames = array_keys($ruleSet->getRules());
     foreach ($fixerNames as $name) {
         if (!array_key_exists($name, $this->fixersByName)) {
             throw new \UnexpectedValueException(sprintf('Rule "%s" does not exist.', $name));
         }
         $fixer = $this->fixersByName[$name];
         $fixer->configure($ruleSet->getRuleConfiguration($name));
         $fixers[] = $fixer;
         $fixersByName[$name] = $fixer;
         $conflicts = array_intersect($this->getFixersConflicts($fixer), $fixerNames);
         if (count($conflicts) > 0) {
             $fixerConflicts[$name] = $conflicts;
         }
     }
     if (count($fixerConflicts) > 0) {
         throw new \UnexpectedValueException($this->generateConflictMessage($fixerConflicts));
     }
     $this->fixers = $fixers;
     $this->fixersByName = $fixersByName;
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Apply RuleSet on fixers to filter out all unwanted fixers.
  *
  * @param RuleSetInterface $ruleSet
  *
  * @return $this
  */
 public function useRuleSet(RuleSetInterface $ruleSet)
 {
     $fixers = array();
     $fixersByName = array();
     $fixerConflicts = array();
     $fixerNames = array_keys($ruleSet->getRules());
     foreach ($fixerNames as $name) {
         if (!array_key_exists($name, $this->fixersByName)) {
             throw new \UnexpectedValueException(sprintf('Rule "%s" does not exist.', $name));
         }
         $fixer = $this->fixersByName[$name];
         $config = $ruleSet->getRuleConfiguration($name);
         if (null !== $config) {
             if ($fixer instanceof ConfigurableFixerInterface) {
                 if (!is_array($config) || !count($config)) {
                     throw new InvalidFixerConfigurationException($fixer->getName(), 'Configuration must be an array and may not be empty.');
                 }
                 $fixer->configure($config);
             } else {
                 throw new InvalidFixerConfigurationException($fixer->getName(), 'Is not configurable.');
             }
         }
         $fixers[] = $fixer;
         $fixersByName[$name] = $fixer;
         $conflicts = array_intersect($this->getFixersConflicts($fixer), $fixerNames);
         if (count($conflicts) > 0) {
             $fixerConflicts[$name] = $conflicts;
         }
     }
     if (count($fixerConflicts) > 0) {
         throw new \UnexpectedValueException($this->generateConflictMessage($fixerConflicts));
     }
     $this->fixers = $fixers;
     $this->fixersByName = $fixersByName;
     return $this;
 }