Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "force-for-construct" option for LineBreakBetweenMethodArgumentFixer #216

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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 ],
// ...
]
);
Expand All @@ -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());
Expand Down Expand Up @@ -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 ],
// ...
]
);
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];
}
Expand Down Expand Up @@ -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(),
]);
}

Expand Down Expand Up @@ -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);

Expand Down