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()); diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php index 988f750..a632900 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 split 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'] && '__construct' === $next->getContent()) { + $this->splitArgs($tokens, $index); + + continue; + } + if ($this->analyze($tokens)->getSizeOfTheLine($index) > $this->configuration['max-length']) { $this->splitArgs($tokens, $index);