12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\AutoReview;
- use PhpCsFixer\Fixer\FixerInterface;
- use PhpCsFixer\FixerFactory;
- use PhpCsFixer\Tests\Test\IntegrationCaseFactory;
- use PhpCsFixer\Tests\TestCase;
- use Symfony\Component\Finder\SplFileInfo;
- /**
- * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * @internal
- *
- * @coversNothing
- *
- * @group auto-review
- * @group covers-nothing
- */
- final class FixerFactoryTest extends TestCase
- {
- public function testFixersPriorityEdgeFixers(): void
- {
- $factory = new FixerFactory();
- $factory->registerBuiltInFixers();
- $fixers = $factory->getFixers();
- foreach (self::getFixerWithFixedPosition() as $fixerName => $offset) {
- if ($offset < 0) {
- self::assertSame($fixerName, $fixers[\count($fixers) + $offset]->getName(), $fixerName);
- } else {
- self::assertSame($fixerName, $fixers[$offset]->getName(), $fixerName);
- }
- }
- }
- public function testFixersPriority(): void
- {
- $fixers = self::getAllFixers();
- $graphs = [
- self::getFixersPriorityGraph(),
- self::getPhpDocFixersPriorityGraph(),
- ];
- foreach ($graphs as $graph) {
- foreach ($graph as $fixerName => $edges) {
- $first = $fixers[$fixerName];
- foreach ($edges as $edge) {
- $second = $fixers[$edge];
- self::assertLessThan($first->getPriority(), $second->getPriority(), \sprintf('"%s" should have less priority than "%s"', $edge, $fixerName));
- }
- }
- }
- }
- /**
- * @param list<string> $edges
- *
- * @dataProvider provideFixersPriorityCasesHaveIntegrationTestCases
- */
- public function testFixersPriorityCasesHaveIntegrationTest(string $fixerName, array $edges): void
- {
- static $forPerformanceEdgesOnly = [
- 'function_to_constant' => [
- 'native_function_casing' => true,
- ],
- 'no_unused_imports' => [
- 'no_leading_import_slash' => true,
- ],
- 'no_useless_sprintf' => [
- 'native_function_casing' => true,
- ],
- 'pow_to_exponentiation' => [
- 'method_argument_space' => true,
- 'native_function_casing' => true,
- 'no_spaces_after_function_name' => true,
- 'no_spaces_inside_parenthesis' => true,
- 'spaces_inside_parentheses' => true,
- ],
- ];
- $missingIntegrationsTests = [];
- foreach ($edges as $edge) {
- if (isset($forPerformanceEdgesOnly[$fixerName][$edge])) {
- continue;
- }
- $file = self::getIntegrationPriorityDirectory().$fixerName.','.$edge.'.test';
- if (!is_file($file)) {
- $missingIntegrationsTests[] = $file;
- continue;
- }
- $file = realpath($file);
- $factory = new IntegrationCaseFactory();
- $test = $factory->create(new SplFileInfo($file, './', __DIR__));
- $rules = $test->getRuleset()->getRules();
- $expected = [$fixerName, $edge];
- $actual = array_keys($rules);
- sort($expected);
- sort($actual);
- self::assertSame(
- \sprintf('Integration of fixers: %s,%s.', $fixerName, $edge),
- $test->getTitle(),
- \sprintf('Please fix the title in "%s".', $file)
- );
- self::assertCount(2, $rules, \sprintf('Only the two rules that are tested for priority should be in the ruleset of "%s".', $file));
- foreach ($rules as $name => $config) {
- self::assertNotFalse($config, \sprintf('The rule "%s" in "%s" may not be disabled for the test.', $name, $file));
- }
- self::assertSame($expected, $actual, \sprintf('The ruleset of "%s" must contain the rules for the priority test.', $file));
- }
- self::assertCount(0, $missingIntegrationsTests, \sprintf("There shall be an integration test. How do you know that priority set up is good, if there is no integration test to check it?\nMissing:\n- %s", implode("\n- ", $missingIntegrationsTests)));
- }
- public static function provideFixersPriorityCasesHaveIntegrationTestCases(): iterable
- {
- foreach (self::getFixersPriorityGraph() as $fixerName => $edges) {
- yield $fixerName => [$fixerName, $edges];
- }
- }
- /**
- * @dataProvider providePriorityIntegrationTestFilesAreListedInPriorityGraphCases
- */
- public function testPriorityIntegrationTestFilesAreListedInPriorityGraph(\SplFileInfo $file): void
- {
- $fileName = $file->getFilename();
- self::assertTrue($file->isFile(), \sprintf('Expected only files in the priority integration test directory, got "%s".', $fileName));
- self::assertFalse($file->isLink(), \sprintf('No (sym)links expected the priority integration test directory, got "%s".', $fileName));
- self::assertSame(
- 1,
- preg_match('#^([a-z][a-z0-9_]*),([a-z][a-z_]*)(?:_\d{1,3})?\.test(-(in|out)\.php)?$#', $fileName, $matches),
- \sprintf('File with unexpected name "%s" in the priority integration test directory.', $fileName)
- );
- [, $fixerName1, $fixerName2] = $matches;
- $graph = self::getFixersPriorityGraph();
- self::assertTrue(
- isset($graph[$fixerName1]) && \in_array($fixerName2, $graph[$fixerName1], true),
- \sprintf('Missing priority test entry for file "%s".', $fileName)
- );
- }
- /**
- * @return iterable<array{\DirectoryIterator}>
- */
- public static function providePriorityIntegrationTestFilesAreListedInPriorityGraphCases(): iterable
- {
- foreach (new \DirectoryIterator(self::getIntegrationPriorityDirectory()) as $candidate) {
- if (!$candidate->isDot()) {
- yield [clone $candidate];
- }
- }
- }
- public function testFixersPriorityGraphIsSorted(): void
- {
- $previous = '';
- foreach (self::getFixersPriorityGraph() as $fixerName => $edges) {
- self::assertLessThan(0, $previous <=> $fixerName, \sprintf('Not sorted "%s" "%s".', $previous, $fixerName));
- $edgesSorted = $edges;
- sort($edgesSorted);
- self::assertSame($edgesSorted, $edges, \sprintf('Fixer "%s" edges are not sorted', $fixerName));
- $previous = $fixerName;
- }
- }
- public function testFixersPriorityComment(): void
- {
- $fixersPhpDocIssues = [];
- $fixers = self::getAllFixers();
- foreach ($fixers as $name => $fixer) {
- $reflection = new \ReflectionObject($fixer);
- $fixers[$name] = ['reflection' => $reflection, 'short_classname' => $reflection->getShortName()];
- }
- $mergedGraph = array_merge_recursive(
- self::getFixersPriorityGraph(),
- self::getPhpDocFixersPriorityGraph()
- );
- // expend $graph
- $graph = [];
- foreach ($mergedGraph as $fixerName => $edges) {
- if (!isset($graph[$fixerName]['before'])) {
- $graph[$fixerName] = ['before' => []];
- }
- foreach ($mergedGraph as $candidateFixer => $candidateEdges) {
- if (\in_array($fixerName, $candidateEdges, true)) {
- $graph[$fixerName]['after'][$candidateFixer] = true;
- }
- }
- foreach ($edges as $edge) {
- if (!isset($graph[$edge]['after'])) {
- $graph[$edge] = ['after' => []];
- }
- $graph[$edge]['after'][$fixerName] = true;
- $graph[$fixerName]['before'][$edge] = true;
- }
- }
- foreach ($graph as $fixerName => $edges) {
- $expectedMessage = "/**\n * {@inheritdoc}\n *";
- foreach ($edges as $label => $others) {
- if (\count($others) > 0) {
- $shortClassNames = [];
- foreach ($others as $other => $foo) {
- $shortClassNames[$other] = $fixers[$other]['short_classname'];
- }
- sort($shortClassNames);
- $expectedMessage .= \sprintf("\n * Must run %s %s.", $label, implode(', ', $shortClassNames));
- }
- }
- $expectedMessage .= "\n */";
- $method = $fixers[$fixerName]['reflection']->getMethod('getPriority');
- $phpDoc = $method->getDocComment();
- if (false === $phpDoc) {
- $fixersPhpDocIssues[$fixerName] = \sprintf("PHPDoc for %s::getPriority is missing.\nExpected:\n%s", $fixers[$fixerName]['short_classname'], $expectedMessage);
- } elseif ($expectedMessage !== $phpDoc) {
- $fixersPhpDocIssues[$fixerName] = \sprintf("PHPDoc for %s::getPriority is not as expected.\nExpected:\n%s", $fixers[$fixerName]['short_classname'], $expectedMessage);
- }
- }
- if (0 === \count($fixersPhpDocIssues)) {
- $this->addToAssertionCount(1);
- } else {
- $message = \sprintf("There are %d priority PHPDoc issues found.\n", \count($fixersPhpDocIssues));
- ksort($fixersPhpDocIssues);
- foreach ($fixersPhpDocIssues as $fixerName => $issue) {
- $message .= \sprintf("\n--------------------------------------------------\n[%s] %s", $fixerName, $issue);
- }
- self::fail($message);
- }
- }
- public function testFixerWithNoneDefaultPriorityIsTested(): void
- {
- $knownIssues = [ // should only shrink
- 'no_trailing_comma_in_singleline_function_call' => true, // had prio case but no longer, left prio the same for BC reasons, rule has been deprecated
- 'simple_to_complex_string_variable' => true, // had prio case but no longer, left prio the same for BC reasons
- ];
- $factory = new FixerFactory();
- $factory->registerBuiltInFixers();
- $fixers = $factory->getFixers();
- $fixerNamesWithTests = [];
- foreach (self::getFixerWithFixedPosition() as $fixerName => $priority) {
- $fixerNamesWithTests[$fixerName] = true;
- }
- foreach ([
- self::getFixersPriorityGraph(),
- self::getPhpDocFixersPriorityGraph(),
- ] as $set) {
- foreach ($set as $fixerName => $edges) {
- $fixerNamesWithTests[$fixerName] = true;
- foreach ($edges as $edge) {
- $fixerNamesWithTests[$edge] = true;
- }
- }
- }
- $missing = [];
- foreach ($fixers as $fixer) {
- $fixerName = $fixer->getName();
- if (0 !== $fixer->getPriority() && !isset($fixerNamesWithTests[$fixerName])) {
- $missing[$fixerName] = true;
- }
- }
- foreach ($knownIssues as $knownIssue => $true) {
- if (isset($missing[$knownIssue])) {
- unset($missing[$knownIssue]);
- } else {
- self::fail(\sprintf('No longer found known issue "%s", please update the set.', $knownIssue));
- }
- }
- self::assertEmpty($missing, 'Fixers with non-default priority and yet without priority unit tests [vide "getFixersPriorityGraph()" and "getPhpDocFixersPriorityGraph()"]: "'.implode('", "', array_keys($missing)).'."');
- }
- /**
- * @return array<string, list<string>>
- */
- private static function getFixersPriorityGraph(): array
- {
- return [
- 'align_multiline_comment' => [
- 'phpdoc_trim_consecutive_blank_line_separation',
- ],
- 'array_indentation' => [
- 'align_multiline_comment',
- 'binary_operator_spaces',
- ],
- 'array_syntax' => [
- 'binary_operator_spaces',
- 'single_space_after_construct',
- 'single_space_around_construct',
- 'ternary_operator_spaces',
- ],
- 'assign_null_coalescing_to_coalesce_equal' => [
- 'binary_operator_spaces',
- 'no_whitespace_in_blank_line',
- ],
- 'backtick_to_shell_exec' => [
- 'explicit_string_variable',
- 'native_function_invocation',
- 'single_quote',
- ],
- 'blank_line_after_opening_tag' => [
- 'blank_lines_before_namespace',
- 'no_blank_lines_before_namespace',
- ],
- 'braces' => [
- 'heredoc_indentation',
- ],
- 'braces_position' => [
- 'single_line_empty_body',
- 'statement_indentation',
- ],
- 'class_attributes_separation' => [
- 'braces',
- 'indentation_type',
- 'no_extra_blank_lines',
- 'statement_indentation',
- ],
- 'class_definition' => [
- 'braces',
- 'single_line_empty_body',
- ],
- 'class_keyword' => [
- 'fully_qualified_strict_types',
- ],
- 'class_keyword_remove' => [
- 'no_unused_imports',
- ],
- 'clean_namespace' => [
- 'php_unit_data_provider_return_type',
- ],
- 'combine_consecutive_issets' => [
- 'multiline_whitespace_before_semicolons',
- 'no_singleline_whitespace_before_semicolons',
- 'no_spaces_inside_parenthesis',
- 'no_trailing_whitespace',
- 'no_whitespace_in_blank_line',
- 'spaces_inside_parentheses',
- ],
- 'combine_consecutive_unsets' => [
- 'no_extra_blank_lines',
- 'no_trailing_whitespace',
- 'no_whitespace_in_blank_line',
- 'space_after_semicolon',
- ],
- 'combine_nested_dirname' => [
- 'method_argument_space',
- 'no_spaces_inside_parenthesis',
- 'spaces_inside_parentheses',
- ],
- 'control_structure_braces' => [
- 'braces_position',
- 'control_structure_continuation_position',
- 'curly_braces_position',
- 'no_multiple_statements_per_line',
- ],
- 'curly_braces_position' => [
- 'single_line_empty_body',
- 'statement_indentation',
- ],
- 'declare_strict_types' => [
- 'blank_line_after_opening_tag',
- 'declare_equal_normalize',
- 'header_comment',
- ],
- 'dir_constant' => [
- 'combine_nested_dirname',
- ],
- 'doctrine_annotation_array_assignment' => [
- 'doctrine_annotation_spaces',
- ],
- 'echo_tag_syntax' => [
- 'no_mixed_echo_print',
- ],
- 'empty_loop_body' => [
- 'braces',
- 'no_extra_blank_lines',
- 'no_trailing_whitespace',
- ],
- 'empty_loop_condition' => [
- 'no_extra_blank_lines',
- 'no_trailing_whitespace',
- ],
- 'escape_implicit_backslashes' => [
- 'heredoc_to_nowdoc',
- 'single_quote',
- ],
- 'explicit_string_variable' => [
- 'no_useless_concat_operator',
- ],
- 'final_class' => [
- 'protected_to_private',
- 'self_static_accessor',
- ],
- 'final_internal_class' => [
- 'protected_to_private',
- 'self_static_accessor',
- ],
- 'fully_qualified_strict_types' => [
- 'no_superfluous_phpdoc_tags',
- 'ordered_attributes',
- 'ordered_imports',
- 'ordered_interfaces',
- 'statement_indentation',
- ],
- 'function_declaration' => [
- 'method_argument_space',
- ],
- 'function_to_constant' => [
- 'native_constant_invocation',
- 'native_function_casing',
- 'no_extra_blank_lines',
- 'no_singleline_whitespace_before_semicolons',
- 'no_trailing_whitespace',
- 'no_whitespace_in_blank_line',
- 'self_static_accessor',
- ],
- 'general_phpdoc_annotation_remove' => [
- 'no_empty_phpdoc',
- 'phpdoc_line_span',
- 'phpdoc_separation',
- 'phpdoc_trim',
- ],
- 'general_phpdoc_tag_rename' => [
- 'phpdoc_add_missing_param_annotation',
- ],
- 'get_class_to_class_keyword' => [
- 'multiline_whitespace_before_semicolons',
- ],
- 'global_namespace_import' => [
- 'no_unused_imports',
- 'ordered_imports',
- 'statement_indentation',
- ],
- 'header_comment' => [
- 'blank_lines_before_namespace',
- 'single_blank_line_before_namespace',
- 'single_line_comment_style',
- ],
- 'implode_call' => [
- 'method_argument_space',
- ],
- 'increment_style' => [
- 'no_spaces_inside_parenthesis',
- 'spaces_inside_parentheses',
- ],
- 'indentation_type' => [
- 'phpdoc_indent',
- ],
- 'is_null' => [
- 'yoda_style',
- ],
- 'lambda_not_used_import' => [
- 'method_argument_space',
- 'no_spaces_inside_parenthesis',
- 'spaces_inside_parentheses',
- ],
- 'list_syntax' => [
- 'binary_operator_spaces',
- 'ternary_operator_spaces',
- ],
- 'long_to_shorthand_operator' => [
- 'binary_operator_spaces',
- 'no_extra_blank_lines',
- 'no_singleline_whitespace_before_semicolons',
- 'standardize_increment',
- ],
- 'method_argument_space' => [
- 'array_indentation',
- 'statement_indentation',
- ],
- 'modernize_strpos' => [
- 'binary_operator_spaces',
- 'no_extra_blank_lines',
- 'no_spaces_inside_parenthesis',
- 'no_trailing_whitespace',
- 'not_operator_with_space',
- 'not_operator_with_successor_space',
- 'php_unit_dedicate_assert',
- 'single_space_after_construct',
- 'single_space_around_construct',
- 'spaces_inside_parentheses',
- ],
- 'modernize_types_casting' => [
- 'no_unneeded_control_parentheses',
- ],
- 'multiline_string_to_heredoc' => [
- 'escape_implicit_backslashes',
- 'heredoc_indentation',
- 'string_implicit_backslashes',
- ],
- 'multiline_whitespace_before_semicolons' => [
- 'space_after_semicolon',
- ],
- 'native_constant_invocation' => [
- 'global_namespace_import',
- ],
- 'native_function_invocation' => [
- 'global_namespace_import',
- ],
- 'new_with_braces' => [
- 'class_definition',
- ],
- 'new_with_parentheses' => [
- 'class_definition',
- ],
- 'no_alias_functions' => [
- 'implode_call',
- 'php_unit_dedicate_assert',
- ],
- 'no_alternative_syntax' => [
- 'braces',
- 'elseif',
- 'no_superfluous_elseif',
- 'no_unneeded_control_parentheses',
- 'no_useless_else',
- 'switch_continue_to_break',
- ],
- 'no_binary_string' => [
- 'no_useless_concat_operator',
- 'php_unit_dedicate_assert_internal_type',
- 'regular_callable_call',
- 'set_type_to_cast',
- ],
- 'no_blank_lines_after_phpdoc' => [
- 'header_comment',
- ],
- 'no_empty_comment' => [
- 'no_extra_blank_lines',
- 'no_trailing_whitespace',
- 'no_whitespace_in_blank_line',
- ],
- 'no_empty_phpdoc' => [
- 'no_extra_blank_lines',
- 'no_trailing_whitespace',
- ],
- 'no_empty_statement' => [
- 'braces',
- 'combine_consecutive_unsets',
- 'empty_loop_body',
- 'multiline_whitespace_before_semicolons',
- 'no_extra_blank_lines',
- 'no_multiple_statements_per_line',
- 'no_singleline_whitespace_before_semicolons',
- 'no_trailing_whitespace',
- 'no_useless_else',
- 'no_useless_return',
- 'no_whitespace_in_blank_line',
- 'return_assignment',
- 'space_after_semicolon',
- 'switch_case_semicolon_to_colon',
- ],
- 'no_extra_blank_lines' => [
- 'blank_line_before_statement',
- ],
- 'no_leading_import_slash' => [
- 'ordered_imports',
- ],
- 'no_multiline_whitespace_around_double_arrow' => [
- 'binary_operator_spaces',
- 'method_argument_space',
- ],
- 'no_multiple_statements_per_line' => [
- 'braces_position',
- 'curly_braces_position',
- ],
- 'no_php4_constructor' => [
- 'ordered_class_elements',
- ],
- 'no_short_bool_cast' => [
- 'cast_spaces',
- ],
- 'no_space_around_double_colon' => [
- 'method_chaining_indentation',
- ],
- 'no_spaces_after_function_name' => [
- 'function_to_constant',
- 'get_class_to_class_keyword',
- ],
- 'no_spaces_inside_parenthesis' => [
- 'function_to_constant',
- 'get_class_to_class_keyword',
- 'string_length_to_empty',
- ],
- 'no_superfluous_elseif' => [
- 'simplified_if_return',
- ],
- 'no_superfluous_phpdoc_tags' => [
- 'no_empty_phpdoc',
- 'void_return',
- ],
- 'no_unneeded_braces' => [
- 'no_useless_else',
- 'no_useless_return',
- 'return_assignment',
- 'simplified_if_return',
- ],
- 'no_unneeded_control_parentheses' => [
- 'concat_space',
- 'no_trailing_whitespace',
- ],
- 'no_unneeded_curly_braces' => [
- 'no_useless_else',
- 'no_useless_return',
- 'return_assignment',
- 'simplified_if_return',
- ],
- 'no_unneeded_import_alias' => [
- 'no_singleline_whitespace_before_semicolons',
- ],
- 'no_unset_cast' => [
- 'binary_operator_spaces',
- ],
- 'no_unset_on_property' => [
- 'combine_consecutive_unsets',
- ],
- 'no_unused_imports' => [
- 'blank_line_after_namespace',
- 'no_extra_blank_lines',
- 'no_leading_import_slash',
- 'single_line_after_imports',
- ],
- 'no_useless_concat_operator' => [
- 'date_time_create_from_format_call',
- 'ereg_to_preg',
- 'php_unit_dedicate_assert_internal_type',
- 'regular_callable_call',
- 'set_type_to_cast',
- ],
- 'no_useless_else' => [
- 'blank_line_before_statement',
- 'braces',
- 'combine_consecutive_unsets',
- 'no_break_comment',
- 'no_extra_blank_lines',
- 'no_trailing_whitespace',
- 'no_useless_return',
- 'no_whitespace_in_blank_line',
- 'simplified_if_return',
- 'statement_indentation',
- ],
- 'no_useless_return' => [
- 'blank_line_before_statement',
- 'no_extra_blank_lines',
- 'no_whitespace_in_blank_line',
- 'single_line_comment_style',
- 'single_line_empty_body',
- ],
- 'no_useless_sprintf' => [
- 'method_argument_space',
- 'native_function_casing',
- 'no_empty_statement',
- 'no_extra_blank_lines',
- 'no_spaces_inside_parenthesis',
- 'spaces_inside_parentheses',
- ],
- 'nullable_type_declaration' => [
- 'ordered_types',
- 'types_spaces',
- ],
- 'nullable_type_declaration_for_default_null_value' => [
- 'no_unreachable_default_argument_value',
- 'nullable_type_declaration',
- 'ordered_types',
- ],
- 'ordered_class_elements' => [
- 'class_attributes_separation',
- 'no_blank_lines_after_class_opening',
- 'space_after_semicolon',
- ],
- 'ordered_imports' => [
- 'blank_line_between_import_groups',
- ],
- 'ordered_types' => [
- 'types_spaces',
- ],
- 'php_unit_attributes' => [
- 'fully_qualified_strict_types',
- 'phpdoc_separation',
- 'phpdoc_trim',
- 'phpdoc_trim_consecutive_blank_line_separation',
- ],
- 'php_unit_construct' => [
- 'php_unit_dedicate_assert',
- ],
- 'php_unit_data_provider_name' => [
- 'php_unit_attributes',
- ],
- 'php_unit_data_provider_return_type' => [
- 'php_unit_attributes',
- 'return_to_yield_from',
- 'return_type_declaration',
- ],
- 'php_unit_data_provider_static' => [
- 'php_unit_attributes',
- ],
- 'php_unit_dedicate_assert' => [
- 'no_unused_imports',
- 'php_unit_assert_new_names',
- 'php_unit_dedicate_assert_internal_type',
- ],
- 'php_unit_fqcn_annotation' => [
- 'no_unused_imports',
- 'phpdoc_order_by_value',
- ],
- 'php_unit_internal_class' => [
- 'final_internal_class',
- 'phpdoc_separation',
- ],
- 'php_unit_no_expectation_annotation' => [
- 'no_empty_phpdoc',
- 'php_unit_expectation',
- ],
- 'php_unit_size_class' => [
- 'phpdoc_separation',
- ],
- 'php_unit_test_annotation' => [
- 'no_empty_phpdoc',
- 'php_unit_method_casing',
- 'phpdoc_trim',
- ],
- 'php_unit_test_case_static_method_calls' => [
- 'self_static_accessor',
- ],
- 'php_unit_test_class_requires_covers' => [
- 'phpdoc_separation',
- ],
- 'phpdoc_add_missing_param_annotation' => [
- 'no_empty_phpdoc',
- 'no_superfluous_phpdoc_tags',
- 'phpdoc_align',
- 'phpdoc_order',
- ],
- 'phpdoc_array_type' => [
- 'phpdoc_list_type',
- 'phpdoc_types_order',
- ],
- 'phpdoc_line_span' => [
- 'no_superfluous_phpdoc_tags',
- ],
- 'phpdoc_list_type' => [
- 'phpdoc_types_order',
- ],
- 'phpdoc_no_access' => [
- 'no_empty_phpdoc',
- 'phpdoc_separation',
- 'phpdoc_trim',
- ],
- 'phpdoc_no_alias_tag' => [
- 'phpdoc_add_missing_param_annotation',
- 'phpdoc_single_line_var_spacing',
- ],
- 'phpdoc_no_empty_return' => [
- 'no_empty_phpdoc',
- 'phpdoc_order',
- 'phpdoc_separation',
- 'phpdoc_trim',
- ],
- 'phpdoc_no_package' => [
- 'no_empty_phpdoc',
- 'phpdoc_separation',
- 'phpdoc_trim',
- ],
- 'phpdoc_no_useless_inheritdoc' => [
- 'no_empty_phpdoc',
- 'no_trailing_whitespace_in_comment',
- ],
- 'phpdoc_order' => [
- 'phpdoc_separation',
- 'phpdoc_trim',
- ],
- 'phpdoc_readonly_class_comment_to_keyword' => [
- 'no_empty_phpdoc',
- 'no_extra_blank_lines',
- 'phpdoc_align',
- ],
- 'phpdoc_return_self_reference' => [
- 'no_superfluous_phpdoc_tags',
- ],
- 'phpdoc_scalar' => [
- 'phpdoc_to_return_type',
- ],
- 'phpdoc_to_comment' => [
- 'no_empty_comment',
- 'phpdoc_no_useless_inheritdoc',
- 'single_line_comment_spacing',
- 'single_line_comment_style',
- ],
- 'phpdoc_to_param_type' => [
- 'no_superfluous_phpdoc_tags',
- ],
- 'phpdoc_to_property_type' => [
- 'fully_qualified_strict_types',
- 'no_superfluous_phpdoc_tags',
- ],
- 'phpdoc_to_return_type' => [
- 'fully_qualified_strict_types',
- 'no_superfluous_phpdoc_tags',
- 'return_to_yield_from',
- 'return_type_declaration',
- ],
- 'phpdoc_types' => [
- 'phpdoc_to_return_type',
- ],
- 'pow_to_exponentiation' => [
- 'binary_operator_spaces',
- 'method_argument_space',
- 'native_function_casing',
- 'no_spaces_after_function_name',
- 'no_spaces_inside_parenthesis',
- 'spaces_inside_parentheses',
- ],
- 'protected_to_private' => [
- 'ordered_class_elements',
- ],
- 'psr_autoloading' => [
- 'self_accessor',
- ],
- 'regular_callable_call' => [
- 'native_function_invocation',
- ],
- 'return_assignment' => [
- 'blank_line_before_statement',
- ],
- 'return_to_yield_from' => [
- 'yield_from_array_to_yields',
- ],
- 'semicolon_after_instruction' => [
- 'simplified_if_return',
- ],
- 'simplified_if_return' => [
- 'multiline_whitespace_before_semicolons',
- 'no_singleline_whitespace_before_semicolons',
- ],
- 'simplified_null_return' => [
- 'no_useless_return',
- 'void_return',
- ],
- 'single_class_element_per_statement' => [
- 'class_attributes_separation',
- ],
- 'single_import_per_statement' => [
- 'multiline_whitespace_before_semicolons',
- 'no_leading_import_slash',
- 'no_singleline_whitespace_before_semicolons',
- 'space_after_semicolon',
- ],
- 'single_line_throw' => [
- 'braces',
- 'concat_space',
- ],
- 'single_quote' => [
- 'no_useless_concat_operator',
- ],
- 'single_space_after_construct' => [
- 'braces',
- 'function_declaration',
- ],
- 'single_space_around_construct' => [
- 'braces',
- 'function_declaration',
- ],
- 'single_trait_insert_per_statement' => [
- 'braces',
- 'space_after_semicolon',
- ],
- 'spaces_inside_parentheses' => [
- 'function_to_constant',
- 'get_class_to_class_keyword',
- 'string_length_to_empty',
- ],
- 'standardize_increment' => [
- 'increment_style',
- ],
- 'standardize_not_equals' => [
- 'binary_operator_spaces',
- ],
- 'statement_indentation' => [
- 'heredoc_indentation',
- ],
- 'strict_comparison' => [
- 'binary_operator_spaces',
- 'modernize_strpos',
- ],
- 'strict_param' => [
- 'method_argument_space',
- 'native_function_invocation',
- ],
- 'string_implicit_backslashes' => [
- 'heredoc_to_nowdoc',
- 'single_quote',
- ],
- 'string_length_to_empty' => [
- 'no_extra_blank_lines',
- 'no_trailing_whitespace',
- ],
- 'ternary_to_elvis_operator' => [
- 'no_trailing_whitespace',
- 'ternary_operator_spaces',
- ],
- 'ternary_to_null_coalescing' => [
- 'assign_null_coalescing_to_coalesce_equal',
- ],
- 'unary_operator_spaces' => [
- 'not_operator_with_space',
- 'not_operator_with_successor_space',
- ],
- 'use_arrow_functions' => [
- 'function_declaration',
- ],
- 'visibility_required' => [
- 'class_attributes_separation',
- ],
- 'void_return' => [
- 'phpdoc_no_empty_return',
- 'return_type_declaration',
- ],
- 'yield_from_array_to_yields' => [
- 'blank_line_before_statement',
- 'no_extra_blank_lines',
- 'no_multiple_statements_per_line',
- 'no_whitespace_in_blank_line',
- 'statement_indentation',
- ],
- ];
- }
- /**
- * @return array<string, list<string>>
- */
- private static function getPhpDocFixersPriorityGraph(): array
- {
- // Prepare bulk tests for phpdoc fixers to test that:
- // * `align_multiline_comment` is first
- // * `comment_to_phpdoc` is second
- // * `phpdoc_to_comment` is third
- // * `phpdoc_indent` is fourth
- // * `phpdoc_types` is fifth
- // * `phpdoc_scalar` is sixth
- // * `phpdoc_align` is last
- $cases = [
- 'align_multiline_comment' => ['comment_to_phpdoc'],
- 'comment_to_phpdoc' => ['phpdoc_to_comment'],
- 'phpdoc_to_comment' => ['phpdoc_indent'],
- 'phpdoc_indent' => ['phpdoc_types'],
- 'phpdoc_types' => ['phpdoc_scalar'],
- 'phpdoc_scalar' => [],
- ];
- $docFixerNames = array_filter(
- array_keys(self::getAllFixers()),
- static fn (string $name): bool => str_contains($name, 'phpdoc')
- );
- foreach ($docFixerNames as $docFixerName) {
- if (!\in_array($docFixerName, ['comment_to_phpdoc', 'phpdoc_to_comment', 'phpdoc_indent', 'phpdoc_types', 'phpdoc_scalar'], true)) {
- $cases['align_multiline_comment'][] = $docFixerName;
- $cases['comment_to_phpdoc'][] = $docFixerName;
- $cases['phpdoc_indent'][] = $docFixerName;
- $cases['phpdoc_to_comment'][] = $docFixerName;
- if ('phpdoc_annotation_without_dot' !== $docFixerName) {
- $cases['phpdoc_scalar'][] = $docFixerName;
- $cases['phpdoc_types'][] = $docFixerName;
- }
- }
- if ('phpdoc_align' !== $docFixerName) {
- $cases[$docFixerName][] = 'phpdoc_align';
- }
- }
- return $cases;
- }
- /**
- * @return array<string, int>
- */
- private static function getFixerWithFixedPosition(): array
- {
- return [
- 'encoding' => 0, // Expected "encoding" fixer to have the highest priority.
- 'full_opening_tag' => 1, // Expected "full_opening_tag" fixer has second-highest priority.
- 'single_blank_line_at_eof' => -1, // Expected "single_blank_line_at_eof" to have the lowest priority.
- ];
- }
- /**
- * @return array<string, FixerInterface>
- */
- private static function getAllFixers(): array
- {
- $factory = new FixerFactory();
- $factory->registerBuiltInFixers();
- $fixers = [];
- foreach ($factory->getFixers() as $fixer) {
- $fixers[$fixer->getName()] = $fixer;
- }
- return $fixers;
- }
- private static function getIntegrationPriorityDirectory(): string
- {
- return __DIR__.'/../Fixtures/Integration/priority/';
- }
- }
|