Author: Dariusz Rumiński (dariusz.ruminski@gmail.com)
Inheritance: implements phpcsfixer\RuleSetInterface
Beispiel #1
0
 protected function getFixersHelp()
 {
     $help = '';
     $fixerFactory = new FixerFactory();
     $fixers = $fixerFactory->registerBuiltInFixers()->getFixers();
     // sort fixers by name
     usort($fixers, function (FixerInterface $a, FixerInterface $b) {
         return strcmp($a->getName(), $b->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();
         $attributes = array();
         if ($fixer->isRisky()) {
             $attributes[] = 'risky';
         }
         if ($this->isFixerConfigurable($fixer)) {
             $attributes[] = 'configurable';
         }
         $description = wordwrap($description, 72, "\n   | ");
         if (!empty($sets)) {
             $help .= sprintf(" * <comment>%s</comment> [%s]\n   | %s\n", $fixer->getName(), implode(', ', $sets), $description);
         } else {
             $help .= sprintf(" * <comment>%s</comment>\n   | %s\n", $fixer->getName(), $description);
         }
         if (count($attributes)) {
             sort($attributes);
             $help .= sprintf("   | *Rule is: %s.*\n", implode(', ', $attributes));
         }
         if ($count !== $i) {
             $help .= "\n";
         }
     }
     return $help;
 }
Beispiel #2
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;
 }
 public function testResolveRulesWithDisabledSet()
 {
     $ruleSet = RuleSet::create(array('@PSR2' => true, '@PSR1' => false, 'encoding' => true));
     $this->assertSameRules(array('blank_line_after_namespace' => true, 'braces' => true, 'class_definition' => true, 'elseif' => true, 'encoding' => true, 'function_declaration' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'method_argument_space' => true, 'no_closing_tag' => true, 'no_spaces_after_function_name' => true, 'no_spaces_inside_parenthesis' => true, 'no_tab_indentation' => true, 'no_trailing_whitespace' => true, 'no_trailing_whitespace_in_comment' => true, 'single_blank_line_at_eof' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, 'switch_case_semicolon_to_colon' => true, 'switch_case_space' => true, 'unix_line_endings' => true, 'visibility_required' => true), $ruleSet->getRules());
 }
 /**
  * @return string[]
  */
 private function getSetNames()
 {
     if (null !== $this->setNames) {
         return $this->setNames;
     }
     $set = new RuleSet();
     $this->setNames = $set->getSetDefinitionNames();
     sort($this->setNames);
     return $this->setNames;
 }