/** * @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); }
public function getFixersPriorityCases() { $factory = new FixerFactory(); $factory->registerBuiltInFixers(); $fixers = array(); foreach ($factory->getFixers() as $fixer) { $fixers[$fixer->getName()] = $fixer; } $cases = array(array($fixers['php_closing_tag'], $fixers['short_tag']), array($fixers['unused_use'], $fixers['extra_empty_lines']), array($fixers['multiple_use'], $fixers['unused_use']), array($fixers['multiple_use'], $fixers['ordered_use']), array($fixers['remove_leading_slash_use'], $fixers['ordered_use']), array($fixers['remove_lines_between_uses'], $fixers['ordered_use']), array($fixers['unused_use'], $fixers['remove_leading_slash_use']), array($fixers['multiple_use'], $fixers['remove_leading_slash_use']), array($fixers['concat_without_spaces'], $fixers['concat_with_spaces']), array($fixers['elseif'], $fixers['braces']), array($fixers['duplicate_semicolon'], $fixers['braces']), array($fixers['duplicate_semicolon'], $fixers['spaces_before_semicolon']), array($fixers['duplicate_semicolon'], $fixers['multiline_spaces_before_semicolon']), array($fixers['standardize_not_equal'], $fixers['strict']), array($fixers['double_arrow_multiline_whitespaces'], $fixers['multiline_array_trailing_comma']), array($fixers['double_arrow_multiline_whitespaces'], $fixers['align_double_arrow']), array($fixers['operators_spaces'], $fixers['align_double_arrow']), array($fixers['operators_spaces'], $fixers['align_equals']), array($fixers['indentation'], $fixers['phpdoc_indent']), array($fixers['phpdoc_order'], $fixers['phpdoc_separation']), array($fixers['phpdoc_no_access'], $fixers['phpdoc_separation']), array($fixers['phpdoc_no_access'], $fixers['phpdoc_order']), array($fixers['phpdoc_no_empty_return'], $fixers['phpdoc_separation']), array($fixers['phpdoc_no_empty_return'], $fixers['phpdoc_order']), array($fixers['phpdoc_no_package'], $fixers['phpdoc_separation']), array($fixers['phpdoc_no_package'], $fixers['phpdoc_order']), array($fixers['phpdoc_no_access'], $fixers['phpdoc_trim']), array($fixers['phpdoc_no_empty_return'], $fixers['phpdoc_trim']), array($fixers['phpdoc_no_package'], $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['phpdoc_order'], $fixers['phpdoc_trim']), array($fixers['unused_use'], $fixers['line_after_namespace']), array($fixers['linefeed'], $fixers['eof_ending']), array($fixers['php_unit_strict'], $fixers['php_unit_construct']), array($fixers['unary_operators_spaces'], $fixers['logical_not_operators_with_spaces']), array($fixers['unary_operators_spaces'], $fixers['logical_not_operators_with_successor_space']), array($fixers['method_separation'], $fixers['braces']), array($fixers['method_separation'], $fixers['indentation']), array($fixers['short_echo_tag'], $fixers['echo_to_print']), array($fixers['short_bool_cast'], $fixers['spaces_cast']), array($fixers['unneeded_control_parentheses'], $fixers['trailing_spaces'])); // 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(); }
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; }
private function getAllFixers() { $factory = new FixerFactory(); return $factory->registerBuiltInFixers()->getFixers(); }
public function testHasRuleWithChangedRuleSet() { $factory = new FixerFactory(); $factory->registerBuiltInFixers(); $f1 = $this->getMock('Symfony\\CS\\FixerInterface'); $f1->expects($this->any())->method('getName')->willReturn('f1'); $f2 = $this->getMock('Symfony\\CS\\FixerInterface'); $f2->expects($this->any())->method('getName')->willReturn('f2'); $factory->registerFixer($f1); $factory->registerFixer($f2); $this->assertTrue($factory->hasRule('f1'), 'Should have f1 fixer'); $this->assertTrue($factory->hasRule('f2'), 'Should have f2 fixer'); $factory->useRuleSet(new RuleSet(array('f2' => true))); $this->assertFalse($factory->hasRule('f1'), 'Should not have f1 fixer'); $this->assertTrue($factory->hasRule('f2'), 'Should have f2 fixer'); }