From 7a22fa01576eb11d41e55611127462e3e581aba7 Mon Sep 17 00:00:00 2001 From: PierreMWL Date: Fri, 25 Oct 2024 02:35:46 +0200 Subject: [PATCH 1/6] Add "force-for-construct" option for LineBreakBetweenMethodArgumentsFixer --- .../LineBreakBetweenMethodArgumentsFixer.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php index 988f750..b4d46f8 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php @@ -40,12 +40,14 @@ public function getSampleConfigurations(): array 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, + 'force-for-construct' => false, ], [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, + 'force-for-construct' => false, ], ]; } @@ -99,6 +101,9 @@ public function createConfigurationDefinition(): FixerConfigurationResolverInter (new FixerOptionBuilder('inline-attributes', 'In the case of a split, the declaration of the attributes of the arguments of the method will be on the same line as the arguments themselves')) ->setDefault(false) ->getOption(), + (new FixerOptionBuilder('force-for-construct', 'If true, the __construct method arguments will always be splitted into several lines')) + ->setDefault(false) + ->getOption(), ]); } @@ -137,6 +142,12 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void continue; } + if (true === $this->configuration['force-for-construct'] && $next->getContent() === '__construct') { + $this->splitArgs($tokens, $index); + + continue; + } + if ($this->analyze($tokens)->getSizeOfTheLine($index) > $this->configuration['max-length']) { $this->splitArgs($tokens, $index); From e8806e31c116828edaa634007a4cc288619a64ae Mon Sep 17 00:00:00 2001 From: PierreMWL Date: Fri, 25 Oct 2024 02:53:54 +0200 Subject: [PATCH 2/6] Fix grammar --- .../Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php index b4d46f8..d48af06 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php @@ -101,7 +101,7 @@ public function createConfigurationDefinition(): FixerConfigurationResolverInter (new FixerOptionBuilder('inline-attributes', 'In the case of a split, the declaration of the attributes of the arguments of the method will be on the same line as the arguments themselves')) ->setDefault(false) ->getOption(), - (new FixerOptionBuilder('force-for-construct', 'If true, the __construct method arguments will always be splitted into several lines')) + (new FixerOptionBuilder('force-for-construct', 'If true, the __construct method arguments will always be split into several lines')) ->setDefault(false) ->getOption(), ]); From cd74bc787eec8524754657d6f7ccb2dccc79f018 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 25 Oct 2024 08:54:16 +0200 Subject: [PATCH 3/6] Update documentation --- .idea/inspectionProfiles/Project_Default.xml | 6 ++++++ .idea/php-test-framework.xml | 14 ++++++++++++++ README.md | 11 +++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/php-test-framework.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..d829d01 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml new file mode 100644 index 0000000..80b13e3 --- /dev/null +++ b/.idea/php-test-framework.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 08d29ed..769643c 100644 --- a/README.md +++ b/README.md @@ -514,6 +514,9 @@ If the declaration of a method is too long, the arguments of this method MUST BE - `automatic-argument-merge` (*optional*): If both conditions are met (the line is not too long and there are not too many arguments), then the arguments are put back inline - default: `true` + - `force-for-construct` (*optional*): If true, the __construct method arguments will always be split into several lines + - default: `false` + - `inline-attributes` (*optional*): In the case of a split, the declaration of the attributes of the arguments of the method will be on the same line as the arguments themselves - default: `false` @@ -534,7 +537,7 @@ $config = new PhpCsFixer\Config(); $config->setRules( [ // ... - 'PedroTroller/line_break_between_method_arguments' => [ 'max-args' => 4, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true ], + 'PedroTroller/line_break_between_method_arguments' => [ 'max-args' => 4, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, 'force-for-construct' => false ], // ... ] ); @@ -552,7 +555,7 @@ $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/line_break_between_method_arguments', [ 'max-args' => 4, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true ]) + ->enable('PedroTroller/line_break_between_method_arguments', [ 'max-args' => 4, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, 'force-for-construct' => false ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); @@ -604,7 +607,7 @@ $config = new PhpCsFixer\Config(); $config->setRules( [ // ... - 'PedroTroller/line_break_between_method_arguments' => [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true ], + 'PedroTroller/line_break_between_method_arguments' => [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, 'force-for-construct' => false ], // ... ] ); @@ -622,7 +625,7 @@ $config = new PhpCsFixer\Config(); // ... $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() - ->enable('PedroTroller/line_break_between_method_arguments', [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true ]) + ->enable('PedroTroller/line_break_between_method_arguments', [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true, 'inline-attributes' => true, 'force-for-construct' => false ]) ->getRules() ); $config->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()); From 67807ffb88e35d3ac8de52fecdb6d636a71a6e6a Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 25 Oct 2024 08:56:53 +0200 Subject: [PATCH 4/6] Fix coding style --- .../Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php index d48af06..a632900 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php @@ -142,7 +142,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void continue; } - if (true === $this->configuration['force-for-construct'] && $next->getContent() === '__construct') { + if (true === $this->configuration['force-for-construct'] && '__construct' === $next->getContent()) { $this->splitArgs($tokens, $index); continue; From d0da53f28f88ad51490ba4c482dcd64df9f8657c Mon Sep 17 00:00:00 2001 From: PierreMWL Date: Tue, 5 Nov 2024 03:14:39 +0100 Subject: [PATCH 5/6] Delete .idea/inspectionProfiles/Project_Default.xml --- .idea/inspectionProfiles/Project_Default.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index d829d01..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file From 317aa8143605b272a90d85efc885abf57fb7ee2d Mon Sep 17 00:00:00 2001 From: PierreMWL Date: Tue, 5 Nov 2024 03:14:55 +0100 Subject: [PATCH 6/6] Delete .idea/php-test-framework.xml --- .idea/php-test-framework.xml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .idea/php-test-framework.xml diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml deleted file mode 100644 index 80b13e3..0000000 --- a/.idea/php-test-framework.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file