diff --git a/README.md b/README.md index 3515eb9..d5ce29a 100644 --- a/README.md +++ b/README.md @@ -358,6 +358,77 @@ return $config; ### Fixes +```diff +--- Original // 80 chars ++++ New // +@@ @@ // + return; // + } // + // +- public function fun2($arg1, array $arg2 = [], \ArrayAccess $arg3 = null, bool $bool = true, \Iterator $thisLastArgument = null) +- { // ++ public function fun2( // ++ $arg1, // ++ array $arg2 = [], // ++ \ArrayAccess $arg3 = null, // ++ bool $bool = true, // ++ \Iterator $thisLastArgument = null // ++ ) { // + return; // + } // + // +- public function fun3( // +- $arg1, // +- array $arg2 = [] // +- ) { // ++ public function fun3($arg1, array $arg2 = []) // ++ { // + return; // + } // + } // + // +``` +### Configuration + +```php +// .php_cs.dist +setRules([ + // ... + 'PedroTroller/line_break_between_method_arguments' => [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true ], + // ... + ]) + // ... + ->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()) +; + +return $config; +``` + +**OR** using my [rule list builder](doc/rule-set-factory.md). + +```php +// .php_cs.dist +setRules(PedroTroller\CS\Fixer\RuleSetFactory::create() + ->enable('PedroTroller/line_break_between_method_arguments', [ 'max-args' => false, 'max-length' => 120, 'automatic-argument-merge' => true ]) + ->getRules() + ]) + // ... + ->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()) +; + +return $config; +``` + +### Fixes + ```diff --- Original // 80 chars +++ New // diff --git a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php index 2b8c6a9..0722c90 100644 --- a/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php +++ b/src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenMethodArgumentsFixer.php @@ -38,6 +38,11 @@ public function getSampleConfigurations() 'max-length' => 120, 'automatic-argument-merge' => true, ], + [ + 'max-args' => false, + 'max-length' => 120, + 'automatic-argument-merge' => true, + ], ]; } @@ -125,7 +130,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void continue; } - if ($this->analyze($tokens)->getNumberOfArguments($index) > $this->configuration['max-args']) { + if (false !== $this->configuration['max-args'] && $this->analyze($tokens)->getNumberOfArguments($index) > $this->configuration['max-args']) { $this->splitArgs($tokens, $index); continue; diff --git a/tests/UseCase/LineBreakBetweenMethodsWithNoSplitOnNumberOfArgs.php b/tests/UseCase/LineBreakBetweenMethodsWithNoSplitOnNumberOfArgs.php new file mode 100644 index 0000000..b35194a --- /dev/null +++ b/tests/UseCase/LineBreakBetweenMethodsWithNoSplitOnNumberOfArgs.php @@ -0,0 +1,100 @@ +configure([ + 'max-args' => false, + 'max-length' => 90, + ]); + + return $fixer; + } + + /** + * {@inheritdoc} + */ + public function getRawScript() + { + return <<<'PHP' +