registerBuiltInFixers() публичный Метод

Register all built in fixers.
Пример #1
0
 /**
  * @dataProvider provideAllRulesFromSets
  */
 public function testIfAllRulesInSetsExists($rule)
 {
     $factory = new FixerFactory();
     $factory->registerBuiltInFixers();
     $fixers = array();
     foreach ($factory->getFixers() as $fixer) {
         $fixers[$fixer->getName()] = $fixer;
     }
     $this->assertArrayHasKey($rule, $fixers);
 }
Пример #2
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;
 }
Пример #3
0
 public function getFixersPriorityCases()
 {
     $factory = new FixerFactory();
     $factory->registerBuiltInFixers();
     $fixers = array();
     foreach ($factory->getFixers() as $fixer) {
         $fixers[$fixer->getName()] = $fixer;
     }
     $cases = array(array($fixers['binary_operator_spaces'], $fixers['align_double_arrow']), array($fixers['binary_operator_spaces'], $fixers['align_equals']), array($fixers['class_definition'], $fixers['no_trailing_whitespace']), array($fixers['concat_without_spaces'], $fixers['concat_with_spaces']), array($fixers['double_arrow_no_multiline_whitespace'], $fixers['align_double_arrow']), array($fixers['double_arrow_no_multiline_whitespace'], $fixers['trailing_comma_in_multiline_array']), array($fixers['elseif'], $fixers['braces']), array($fixers['method_separation'], $fixers['braces']), array($fixers['method_separation'], $fixers['no_tab_indentation']), array($fixers['no_blank_lines_between_uses'], $fixers['ordered_imports']), array($fixers['no_duplicate_semicolons'], $fixers['braces']), array($fixers['no_duplicate_semicolons'], $fixers['no_multiline_whitespace_before_semicolons']), array($fixers['no_duplicate_semicolons'], $fixers['no_singleline_whitespace_before_semicolons']), array($fixers['no_duplicate_semicolons'], $fixers['switch_case_semicolon_to_colon']), array($fixers['no_leading_import_slash'], $fixers['ordered_imports']), array($fixers['no_short_bool_cast'], $fixers['spaces_cast']), array($fixers['no_short_echo_tag'], $fixers['echo_to_print']), array($fixers['no_tab_indentation'], $fixers['phpdoc_indent']), array($fixers['no_unneeded_control_parentheses'], $fixers['no_trailing_whitespace']), array($fixers['no_unused_imports'], $fixers['blank_line_after_namespace']), array($fixers['no_unused_imports'], $fixers['no_extra_consecutive_blank_lines']), array($fixers['no_unused_imports'], $fixers['no_leading_import_slash']), array($fixers['php_unit_strict'], $fixers['php_unit_construct']), array($fixers['phpdoc_no_access'], $fixers['phpdoc_order']), array($fixers['phpdoc_no_access'], $fixers['phpdoc_separation']), array($fixers['phpdoc_no_access'], $fixers['phpdoc_trim']), array($fixers['phpdoc_no_empty_return'], $fixers['phpdoc_order']), array($fixers['phpdoc_no_empty_return'], $fixers['phpdoc_separation']), array($fixers['phpdoc_no_empty_return'], $fixers['phpdoc_trim']), array($fixers['phpdoc_no_package'], $fixers['phpdoc_order']), array($fixers['phpdoc_no_package'], $fixers['phpdoc_separation']), array($fixers['phpdoc_no_package'], $fixers['phpdoc_trim']), array($fixers['phpdoc_order'], $fixers['phpdoc_separation']), array($fixers['phpdoc_order'], $fixers['phpdoc_trim']), array($fixers['phpdoc_separation'], $fixers['phpdoc_trim']), array($fixers['phpdoc_summary'], $fixers['phpdoc_trim']), array($fixers['phpdoc_var_without_name'], $fixers['phpdoc_trim']), array($fixers['single_import_per_statement'], $fixers['no_leading_import_slash']), array($fixers['single_import_per_statement'], $fixers['no_unused_imports']), array($fixers['unary_operator_spaces'], $fixers['not_operator_with_space']), array($fixers['unary_operator_spaces'], $fixers['not_operator_with_successor_space']), array($fixers['unix_line_endings'], $fixers['single_blank_line_at_eof']), array($fixers['simplified_null_return'], $fixers['no_useless_return']), array($fixers['no_duplicate_semicolons'], $fixers['no_useless_return']), array($fixers['no_useless_return'], $fixers['no_whitespace_in_blank_lines']), array($fixers['no_useless_return'], $fixers['no_extra_consecutive_blank_lines']), array($fixers['no_useless_return'], $fixers['blank_line_before_return']));
     // prepare bulk tests for phpdoc fixers to test that:
     // * `phpdoc_to_comment` is first
     // * `phpdoc_indent` is second
     // * `phpdoc_types` is third
     // * `phpdoc_scalar` is fourth
     // * `phpdoc_align` is last
     $cases[] = array($fixers['phpdoc_to_comment'], $fixers['phpdoc_indent']);
     $cases[] = array($fixers['phpdoc_indent'], $fixers['phpdoc_types']);
     $cases[] = array($fixers['phpdoc_types'], $fixers['phpdoc_scalar']);
     $docFixerNames = array_filter(array_keys($fixers), function ($name) {
         return false !== strpos($name, 'phpdoc');
     });
     foreach ($docFixerNames as $docFixerName) {
         if (!in_array($docFixerName, array('phpdoc_to_comment', 'phpdoc_indent', 'phpdoc_types', 'phpdoc_scalar'), true)) {
             $cases[] = array($fixers['phpdoc_to_comment'], $fixers[$docFixerName]);
             $cases[] = array($fixers['phpdoc_indent'], $fixers[$docFixerName]);
             $cases[] = array($fixers['phpdoc_types'], $fixers[$docFixerName]);
             $cases[] = array($fixers['phpdoc_scalar'], $fixers[$docFixerName]);
         }
         if ('phpdoc_align' !== $docFixerName) {
             $cases[] = array($fixers[$docFixerName], $fixers['phpdoc_align']);
         }
     }
     return $cases;
 }
 public function __construct()
 {
     $this->fixerFactory = new FixerFactory();
     $this->fixerFactory->registerBuiltInFixers();
 }
Пример #5
0
 /**
  * Returns fixers.
  *
  * @return FixerInterface[] An array of FixerInterface
  */
 public function getFixers()
 {
     if (null === $this->fixers) {
         $fixerFactory = new FixerFactory();
         $fixerFactory->registerBuiltInFixers();
         $fixerFactory->registerCustomFixers($this->getConfig()->getCustomFixers());
         $this->fixers = $fixerFactory->useRuleSet($this->getRuleSet())->setWhitespacesConfig(new WhitespacesFixerConfig($this->config->getIndent(), $this->config->getLineEnding()))->getFixers();
         if (false === $this->getRiskyAllowed()) {
             $riskyFixers = array_map(function (FixerInterface $fixer) {
                 return $fixer->getName();
             }, array_filter($this->fixers, function (FixerInterface $fixer) {
                 return $fixer->isRisky();
             }));
             if (count($riskyFixers)) {
                 throw new InvalidConfigurationException(sprintf('The rules contain risky fixers (%s), but they are not allowed to run. Perhaps you forget to use --allow-risky option?', implode(', ', $riskyFixers)));
             }
         }
     }
     return $this->fixers;
 }
Пример #6
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;
 }
Пример #7
0
 private function getAllFixers()
 {
     $factory = new FixerFactory();
     return $factory->registerBuiltInFixers()->getFixers();
 }
Пример #8
0
 /**
  * @return array<string, FixerInterface>
  */
 private function getFixers()
 {
     if (null !== $this->fixers) {
         return $this->fixers;
     }
     $fixerFactory = new FixerFactory();
     $fixers = array();
     foreach ($fixerFactory->registerBuiltInFixers()->getFixers() as $fixer) {
         $fixers[$fixer->getName()] = $fixer;
     }
     $this->fixers = $fixers;
     ksort($this->fixers);
     return $this->fixers;
 }