Example #1
0
 protected function getFixersHelp()
 {
     $help = '';
     $maxName = 0;
     $fixerFactory = new FixerFactory();
     $fixers = $fixerFactory->registerBuiltInFixers()->getFixers();
     // sort fixers by name
     usort($fixers, function (FixerInterface $a, FixerInterface $b) {
         return strcmp($a->getName(), $b->getName());
     });
     foreach ($fixers as $fixer) {
         if (strlen($fixer->getName()) > $maxName) {
             $maxName = strlen($fixer->getName());
         }
     }
     $ruleSets = array();
     foreach (RuleSet::create()->getSetDefinitionNames() as $setName) {
         $ruleSets[$setName] = new RuleSet(array($setName => true));
     }
     $getSetsWithRule = function ($rule) use($ruleSets) {
         $sets = array();
         foreach ($ruleSets as $setName => $ruleSet) {
             if ($ruleSet->hasRule($rule)) {
                 $sets[] = $setName;
             }
         }
         return $sets;
     };
     $count = count($fixers) - 1;
     foreach ($fixers as $i => $fixer) {
         $sets = $getSetsWithRule($fixer->getName());
         $description = $fixer->getDescription();
         if ($fixer->isRisky()) {
             $description .= ' (Risky fixer!)';
         }
         if (!empty($sets)) {
             $chunks = explode("\n", wordwrap(sprintf("[%s]\n%s", implode(', ', $sets), $description), 72 - $maxName, "\n"));
             $help .= sprintf(" * <comment>%s</comment>%s %s\n", $fixer->getName(), str_repeat(' ', $maxName - strlen($fixer->getName())), array_shift($chunks));
         } else {
             $chunks = explode("\n", wordwrap(sprintf("\n%s", $description), 72 - $maxName, "\n"));
             $help .= sprintf(" * <comment>%s</comment>%s\n", $fixer->getName(), array_shift($chunks));
         }
         while ($c = array_shift($chunks)) {
             $help .= str_repeat(' ', $maxName + 4) . $c . "\n";
         }
         if ($count !== $i) {
             $help .= "\n";
         }
     }
     return $help;
 }
Example #2
0
 public function testResolveRulesWithDisabledSet()
 {
     $ruleSet = RuleSet::create(array('@PSR2' => true, '@PSR1' => false, 'encoding' => true));
     $this->assertSameRules(array('encoding' => true, 'linefeed' => true, 'indentation' => true, 'trailing_spaces' => true, 'php_closing_tag' => true, 'elseif' => true, 'visibility' => true, 'lowercase_keywords' => true, 'single_line_after_imports' => true, 'parenthesis' => true, 'multiple_use' => true, 'function_call_space' => true, 'method_argument_space' => true, 'function_declaration' => true, 'lowercase_constants' => true, 'line_after_namespace' => true, 'braces' => true, 'class_definition' => true, 'eof_ending' => true), $ruleSet->getRules());
 }