GithubHelp home page GithubHelp logo

erickskrauch / php-cs-fixer-custom-fixers Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 1.0 128 KB

A set of custom fixers for PHP-CS-Fixer

License: MIT License

PHP 100.00%
php-cs-fixer php-cs-fixer-custom-fixers

php-cs-fixer-custom-fixers's People

Contributors

alamirault avatar erickskrauch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

alamirault

php-cs-fixer-custom-fixers's Issues

`AlignMultilineParametersFixer`: how to handle multiline type declaration?

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.

ErickSkrauch/align_multiline_parameters not working correctly with nullable type hints

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

align_multiline_parameters produces new line for promoted properties without any types.

When using 'ErickSkrauch/align_multiline_parameters' => ['variables' => true] we get an unexpected style fixing for classes with promoted properties without a type:

Before:

/**
 * @template T
 */
class Diff
{
    /**
     * @param T $was
     * @param T $expected
     */
    public function __construct(
        public $was,
        public $expected,
    ) {
    }
}

After:

/**
 * @template T
 */
class Diff
{
    /**
     * @param T $was
     * @param T $expected
     */
    public function __construct(
        public
        $was,
        public
        $expected,
    ) {
    }
}

Expected (No change):

/**
 * @template T
 */
class Diff
{
    /**
     * @param T $was
     * @param T $expected
     */
    public function __construct(
        public $was,
        public $expected,
    ) {
    }
}

Sort overridden methods in parent-defined order

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.

Example

Before fix:

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
    }

}

After fix:

final class BasicImplementation implements Basic {

    public function firstMethod() {
        // Code
    }

    public function secondMethod() {
        // Code
    }

    public function thirdMethod() { // Now on its place
        // Code
    }

}

Notes:

  • The implementation should work correctly with php-doc and attributes.
  • The fixer must run before ordered_class_elements.
  • The fixer should work for interfaces, extended interfaces, abstract classes, and non-final classes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.