erickskrauch / php-cs-fixer-custom-fixers Goto Github PK
View Code? Open in Web Editor NEWA set of custom fixers for PHP-CS-Fixer
License: MIT License
A set of custom fixers for PHP-CS-Fixer
License: MIT License
The current logic for calculating the length of a type does not consider php8 union types. Could you please let know if you plan to include similar logic?
At first, thanks for publishing this extension.
With
'ErickSkrauch/align_multiline_parameters' => ['variables' => false, 'defaults' => false],
and
public function bar(
string ...$zxc,
) {
}
I get
public function bar(
string ... $zxc,
) {
}
as a result, which is not expected.
I can solve this issue by reusing logic from ErickSkrauch/align_multiline_parameters
. It shouldn't be too difficult :clueless:
If you add a dev
keyword, Composer magically knows your package should be --dev
requirement.
See https://php.watch/articles/composer-prompt-require-dev-dev-packages
Here is a bug:
function test(
string $string = "string",
int |
(
JsonSerializable
&
Stringable
)|
null $int = 0
) {}
}
This is a weird but the correct way to write a type. Right now the AlignMultilineParametersFixer
will calculate the length of the type with all those tabulation spaces and put the names of the parameters really far away to the left.
The PHP-CS-Fixer's TypesSpacesFixer
doesn't fix such multiline type declarations and I didn't find any other fixer suited for this task, so it seems that this code was left on the user's side.
It seems that I can calculate the length of each line and take the longest line as the type length:
function test(
string $string = "string",
int |
(
JsonSerializable
&
Stringable
)|
null $int = 0
) {}
}
But I'm not sure about this solution at this moment. So I'll leave this issue open until somebody also occurs this in a real code and gives me some feedback about expected behavior.
Hi @erickskrauch,
thanks for a great project, exactly what I'm looking for.
I think I might have encountered an issue, though.
I'd like to use ErickSkrauch/align_multiline_parameters
, but it seems to be irritated when type hints are nullable, as in ?string
or ?RequestStack
.
This is the change it proposed, for a function declaration that already adheres to the align_multiline_parameters rules:
public function __construct(
EntityManagerInterface $entityManager,
LoggerInterface $logger,
- ?RequestStack $requestStack,
+ ?RequestStack $requestStack,
WebDeveloperToolsHelperService $webDeveloperToolsHelperService
When using 'ErickSkrauch/align_multiline_parameters' => ['variables' => true]
we get an unexpected style fixing for classes with promoted properties without a type:
/**
* @template T
*/
class Diff
{
/**
* @param T $was
* @param T $expected
*/
public function __construct(
public $was,
public $expected,
) {
}
}
/**
* @template T
*/
class Diff
{
/**
* @param T $was
* @param T $expected
*/
public function __construct(
public
$was,
public
$expected,
) {
}
}
/**
* @template T
*/
class Diff
{
/**
* @param T $was
* @param T $expected
*/
public function __construct(
public $was,
public $expected,
) {
}
}
During the review, I encountered that the developer added the implementation of new methods to the end of the class, while in the interface these methods were described above. I remarked and asked to fix it for code consistency, but I realized that this is a stylistic remark, which means that it either shouldn't be made at all or should be implemented as an automatic tool.
interface Basic {
public function firstMethod();
public function secondMethod();
public function thirdMethod();
}
final class BasicImplementation implements Basic {
public function firstMethod() {
// Code
}
public function thirdMethod() { // Out of order!
// Code
}
public function secondMethod() {
// Code
}
}
final class BasicImplementation implements Basic {
public function firstMethod() {
// Code
}
public function secondMethod() {
// Code
}
public function thirdMethod() { // Now on its place
// Code
}
}
Notes:
ordered_class_elements
.try {
} catch {
}
$a = '123';
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.