Giter Site home page Giter Site logo

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

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar gharlan avatar ktomk avatar kubawerlos avatar phpeek avatar rodnaph avatar sforward avatar shakaran avatar svenluijten avatar szepeviktor avatar weshooper avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

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

Why aren't these part of the main repository?

Most of these should be part of the upstream repository as they should be useful to most projects. Why are they not being accepted/submitted upstream? Referring to fixers with names like PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer::name() is quite noisy. Also there doesn't seem to be any way to batch include all of them.

ConstructorEmptyBracesFixer no longer works on 3.19.2 version

On 3.19.1 the ConstructorEmptyBracesFixer fixer works as expected. Updating CS fixer to 3.19.2 causes our CI pipeline to fail as it tries to update all constructor single lines back to the multi line syntax which is not expected behavior.

 <?php
 class Foo {
     public function __construct(
         $param1,
         $param2
-    ) {}
+    ) {
+    }
 }

Use of mutation testing in php-cs-fixer-custom-fixers - Help needed

Hello there!

My name is Ana. I noted that you use the mutation testing tool infection in the project.
I am a postdoctoral researcher at the University of Seville (Spain), and my colleagues and I are studying how mutation testing tools are used in practice. With this aim in mind, we have analysed over 3,500 public GitHub repositories using mutation testing tools, including yours! This work has recently been published in a journal paper available at https://link.springer.com/content/pdf/10.1007/s10664-022-10177-8.pdf.

To complete this study, we are asking for your help to understand better how mutation testing is used in practice, please! We would be extremely grateful if you could contribute to this study by answering a brief survey of 21 simple questions (no more than 6 minutes). This is the link to the questionnaire https://forms.gle/FvXNrimWAsJYC1zB9.

Drop me an e-mail if you have any questions or comments ([email protected]). Thank you very much in advance!!

NoCommentedOutCodeFixer removes urls

In the following example, the first line is removed by NoCommentedOutCodeFixer:

// http://edmondscommerce.github.io/php/barcode/ean13-barcode-check-digit-with-php.html
public static function checkDigit(string $barcode): int

Ordered PHPDoc params

PHPDoc params should be ordered to match params order.

 /**
+ * @param int $foo
  * @param int $bar
- * @param int $foo
  */
function baz($foo, $bar)
 {
     return true;
 }

Removing usage of preg_quote broke PHP 7.2

This commit causes php 7.2.* to choke (tested on 7.2.19 and 7.2.23). Here's a simple bit of code i put together to reproduce:

use PhpCsFixerCustomFixers\Fixer\PhpdocSelfAccessorFixer;

include_once('./vendor/autoload.php');

$reflection = new ReflectionClass(PhpdocSelfAccessorFixer::class);
$method = $reflection->getMethod('getNewContent');
$method->setAccessible(true);

$fixer = new PhpdocSelfAccessorFixer();
$method->invoke($fixer, '/**
     * @param string $message Error message.
     */', 'Nicolas\ErrorCatalogue', 'PublicException');

The error is: PHP Warning: preg_replace(): Compilation failed: unknown property name after \P or \p at offset 72. Seems to come from the fact the quoting doesn't work properly, as the \E in \ErrorCatalogue is wrongly interpreted as the end of the quoting. This is fixed in PHP 7.3, but it might be easier to bring back preg_quote rather than releasing a new bugfix version of PHP 7.2.

Fixer promoted_constructor_property modifies nullability of property

Rule PhpCsFixerCustomFixers/promoted_constructor_property is incorrectly modifying my code, as presented in the following example. The nullable $bar property is modified into a non-nullable constructor property.

<?php
class Foo
{
    private ?Bar $bar = null;

    public function __construct(
        Bar $bar,
        private Baz $baz,
    ) {
        if ($bar->isPublished()) {
            $this->bar = $bar;
        }
    }

    public function getBar(): ?Bar
    {
        return $this->bar;
    }
    
    public function getBaz(): Baz
    {
        return $this->baz;
    }
}
<?php

class Foo
{
    public function __construct(
        private Bar $bar,
        private Baz $baz,
    ) {
        if ($bar->isPublished()) {
        }
    }

    public function getBar(): ?Bar
    {
        return $this->bar;
    }

    public function getBaz(): Baz
    {
        return $this->baz;
    }
}
root@ff0b5b9f5437:/app# fix src/Demo.php --dry-run --diff -vvv
PHP CS Fixer 3.3.2 Trinacria by Fabien Potencier and Dariusz Ruminski
Runtime: PHP 8.0.13
Loaded config default from "/app/.php-cs-fixer.dist.php".
Using cache file ".php-cs-fixer.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
F                                                                                                                                                                                                                                                                                                                        1 / 1 (100%)
Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error
   1) src/Demo.php (PhpCsFixerCustomFixers/promoted_constructor_property, class_attributes_separation, blank_line_after_opening_tag, single_blank_line_at_eof)
      ---------- begin diff ----------
--- /app/src/Demo.php
+++ /app/src/Demo.php
@@ -1,14 +1,12 @@
 <?php
+
 class Foo
 {
-    private ?Bar $bar = null;
-
     public function __construct(
-        Bar $bar,
+        private Bar $bar,
         private Baz $baz,
     ) {
         if ($bar->isPublished()) {
-            $this->bar = $bar;
         }
     }

@@ -21,4 +19,4 @@
     {
         return $this->baz;
     }
-}
\ No newline at end of file
+}

      ----------- end diff -----------


Checked all files in 0.010 seconds, 18.000 MB memory used

In Fixer class, DirectoryIterator does not work correctly in getIterator method, it gets only part of files.

In the phpcsfixer configuration file I tried to include
PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer::name() => true
But it gave me an error that there was no such rule.

The rules contain unknown fixers: "PhpCsFixerCustomFixers/multiline_promoted_properties" (did you mean "PhpCsFixerCustomFixers/readonly_promoted_properties"?). 

I started to figure out why and finally found a problem with this block of code

foreach (new \DirectoryIterator(__DIR__ . '/Fixer') as $fileInfo) {
            $fileName = $fileInfo->getBasename('.php');
            if (\in_array($fileName, ['.', '..', 'AbstractFixer', 'AbstractTypesFixer', 'DeprecatingFixerInterface'], true)) {
                continue;
            }
            $classNames[] = __NAMESPACE__ . '\\Fixer\\' . $fileName;
        }

I printed all the files that it passes through and there were only 14 files. dump($fileName);

  0 => "PhpCsFixerCustomFixers\Fixer\PhpdocParamTypeFixer"
  1 => "PhpCsFixerCustomFixers\Fixer\PhpdocSelfAccessorFixer"
  2 => "PhpCsFixerCustomFixers\Fixer\PhpdocSingleLineVarFixer"
  3 => "PhpCsFixerCustomFixers\Fixer\PhpdocTypesCommaSpacesFixer"
  4 => "PhpCsFixerCustomFixers\Fixer\PhpdocTypesTrimFixer"
  5 => "PhpCsFixerCustomFixers\Fixer\PhpdocVarAnnotationToAssertFixer"
  6 => "PhpCsFixerCustomFixers\Fixer\PhpUnitAssertArgumentsOrderFixer"
  7 => "PhpCsFixerCustomFixers\Fixer\PhpUnitDedicatedAssertFixer"
  8 => "PhpCsFixerCustomFixers\Fixer\PhpUnitNoUselessReturnFixer"
  9 => "PhpCsFixerCustomFixers\Fixer\PromotedConstructorPropertyFixer"
  10 => "PhpCsFixerCustomFixers\Fixer\ReadonlyPromotedPropertiesFixer"
  11 => "PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer"
  12 => "PhpCsFixerCustomFixers\Fixer\SingleSpaceBeforeStatementFixer"
  13 => "PhpCsFixerCustomFixers\Fixer\StringableInterfaceFixer"

By adding the file I needed manually, it all worked
$classNames[] = __NAMESPACE__ . '\\Fixer\\' . 'MultilinePromotedPropertiesFixer';
I'm not sure what the problem is, maybe you can tell me.

No nullable booleans

No nullable booleans types should be in code:

-function foo(?bool $bar) : ?bool
+function foo(bool $bar) : bool
 {
     return $bar;
 }

PromotedConstructorPropertyFixer suggestions

If the existing class property has a doc block, then the positioning of it when it gets moved to the __constructor is a little whack

Adding the following to the bottom of updateParameterSignature resulted in perfect positioning

foreach ($tokensToInsert as $key => $token) {
    if ($token->isGivenKind(\T_DOC_COMMENT)) {
        $tokensToInsert[$key] = new Token([\T_DOC_COMMENT, PHP_EOL.'    '.preg_replace('/^/m', '    ', $token->getContent())]);
    }
}

$this->tokensToInsert[$propertyStartIndex] = $tokensToInsert;

A few additional options would be nice:

  • keep_class_property_docblocks defaults to true
  • padding defaults to 4spaces

Currently you only put 1 whitespace in front of the promoted property which doesn't follow standards I believe.

`PhpdocArrayStyleFixer` breaks PHPStorm-friendly traversable info

Imagine scenario:

/**
 * @template T
 * @implements IteratorAggregate<int, T>
 */
class TypedCollection implements IteratorAggregate {}

/**
 * @extends TypedCollection<Foo>
 */
class FooCollection extends TypedCollection {}

Then, if we use FooCollection|Foo[] somewhere (because without |Foo[] PHPStorm's autocompletion does not work), PhpdocArrayStyleFixer breaks the static analysis because it changes type to FooCollection|array<Foo> which is wrong. It is described in PHPStan's documentation:

If PHPStan encounters Collection|Foo[], two possible paths are taken:

  • Collection implements Traversable so Collection|Foo[] is interpreted as a Collection object that iterates over Foo. The array part isn’t applied.
  • Collection does not implement Traversable so Collection|Foo[] is interpreted as a Collection object or an array of Foo objects.

Expected behavior:

PhpdocArrayStyleFixer should change smth[] into array<smth> only if it's not helper type for traversable objects.

Request: empty method to single line

Hello,

I have a request.

I'd like to make the following code.

    public function test()
    {
    }

to

    public function test() {}

,similar to ConstructorEmptyBracesFixer, as the former takes too much space. Would be appreciated if you could create one for such a case.

Thank you for your consideration.

Self accessor in PHPDoc

Inside PHPDoc self should be preferred over the class name itself.

 class Foo
 {
     /**
-     * @return Foo
+     * @return self
      */
     function bar()
     {
         return $this;
     }
 }

Don't allow use of empty()

It helps make the intention clearer as you instantly know the type of the variable without needing to guess or look it up. Based on related discussion at PHP-CS-Fixer/PHP-CS-Fixer#4087, a fixer would be a nice fit here perhaps? i.e. swap to mb_strlen() if a string, count() if an array.

`NoImportFromGlobalNamespaceFixer` bug

Hi,

This code:

<?php

use Psl;
use Psl\Iter;

final class Foo;
{
    public function foo(): void
    {
        Psl\invariant(...);

        if (Iter\contains(...)) {
            return;
        }
    }
}

is being fixed to:

<?php

use Psl\Iter;

final class Foo;
{
    public function foo(): void
    {
        \Psl\invariant(...);

        if (Iter\contains(...)) {
            return;
        }
    }
}

This looks incorrect to me?
Is there a way to prevent this

Thanks

StringableInterfaceFixer rule adds unnecessary Stringable to implements list

I have Interface A:

use App\PhpExtension\EqualityInterface;
use JsonSerializable;
use Stringable;

interface Money extends JsonSerializable, Stringable, EqualityInterface
{
}

and class that implements it:

class MoneyWrapper implements Money
{
}

and php-cs-fixer with config:

    ->setRules([
        ...
        PhpCsFixerCustomFixers\Fixer\StringableInterfaceFixer::name() => true,
    ])

Now when I run php-cs-fixer fix it changes my class to this:

use Stringable;

class MoneyWrapper implements Money, Stringable
{
}

This is wrong behaivor, it must not add Stringable to the class since interface it implements already extends from Stringable.

White line between promoted properties with attributes

Would it be possible to adapt MultilinePromotedPropertiesFixer in such way that white lines are added between promoted properties with PHP attributes? I think the first code block is much more readable than the second.

    public function __construct(
        #[ORM\Column]
        #[Assert\NotBlank]
        private string $name,

        #[ORM\Column]
        #[Assert\NotBlank]
        private string $organisation,

        #[ORM\Column(type: 'boolean')]
        private bool $idRequired,

        private bool $profilePossible,
        private bool $isInternal
    ) {
    }
    public function __construct(
        #[ORM\Column]
        #[Assert\NotBlank]
        private string $name,
        #[ORM\Column]
        #[Assert\NotBlank]
        private string $organisation,
        #[ORM\Column(type: 'boolean')]
        private bool $idRequired,
        private bool $profilePossible,
        private bool $isInternal
    ) {
    }

Help in the installation of "php-cs-fixer-custom-fixers".

Hello everyone,
I'm a bit of a novice at this and I wish you could help me, I want to install the "php-cs-fixer-custom-fixers" package in VSCODE, the problem is that I don't know how to do it.
I don't know if I should install it in a particular directory or how I should configure it to make use of its rules.
I am in a "Windows 10" operating system, I have "Git bash version 2.35", "Composer version 2.2.7" and "junstyle.php-cs-fixer-0.2.10" installed, the latter configured as follows:

<?php
// ...
    return (new PhpCsFixer\Config())
    ->setRules([
        '@PSR2'                   => true,
        'align_multiline_comment' => ['comment_type' => 'all_multiline'],
        'array_indentation'       => true,
        'array_syntax'            => ['syntax' => 'short'],
        'binary_operator_spaces'  => [
        .
        .

From already thank you very much!

PromotedConstructorPropertyFixer doesn't understand inheritance

I was excited to use PromotedConstructorPropertyFixer but unfortunately it is incomplete as it does not support or understand object inheritance.

class A {
    protected $foo;
}
class B extends A {
    public function __construct($foo) {
        $this->foo = $foo;
    }
}
 class B extends A {
-    public function __construct($foo) {
+    public function __construct(public $foo) {
-        $this->foo = $foo;
     }
 }

Please provide readonly flag to promoted constructor properties

Hey,
I like the PromotedConstructorPropertyFixer and MultilinePromotedPropertiesFixer very much, thank you for that!
But after that I still have a small task to make all properties readonly. Can you create a fixer for that?

Before:

public function __construct(
    private ProjectExtensionCreator $creator
) {}

After:

public function __construct(
    private readonly ProjectExtensionCreator $creator
) {}

Thanks,
Alex

NoSuperfluousConcatenationFixer replaces double quotes w single quotes

On a code base I work on, I have this line:

printf('"%s";"%s";"%s"'."\r\n", ...$line);

When I enable NoSuperfluousConcatenationFixer, this is the resulting code:

printf("\"%s\";\"%s\";\"%s\"\r\n", ...$line);

So the fixer concatenated the strings, but as a side effect introduced ugly escaping due to the double quotes now being used. I can work around this in my codebase, but it would be even better to have a setting for the fixer which controls if concatenations are retained if the type of quotes would have to be changed. In this case, such a setting would leave the code as-is.

(Apart from that: great tool.)

BC-break in DataProviderStaticFixer

Since version 3.8.0, when I don't modify my configuration file, I get the following exception. As far as I can see, this modification in isRisky() always sets 'risky' to true and can not be changed.

In ConfigurationResolver.php line 349:

  [PhpCsFixer\ConfigurationException\InvalidConfigurationException (16)]
  The rules contain risky fixers ("PhpCsFixerCustomFixers/data_provider_static"), but they are not allowed to run. Perhaps you forget to use --allow-risky=yes option?

StringableInterfaceFixer keeps spawn one more \Stringable every run if Stringable is imported from global namespace

Good day!

As state in the caption, "StringableInterfaceFixer keeps spawn one more \Stringable every run if Stringable is imported from global namespace".

You can reproduce the problem by running the rule against such code:

namespace FooNamespace;

use Stringable;

class A implements Stringable {
     public function __toString() { return ''; }
}

It will be converted to class A implements Stringable, \Stringable {, class A implements Stringable, \Stringable, \Stringable {, etc with each run. (You shouldn't use cache to see that in action more than one time.)

You can test the failures with following test-cases for StringableInterfaceFixerTest:

// If Stringable is mentioned in "use" section, it should be respected
yield [
    '<?php namespace FooNamespace;
    use Stringable;
    class Foo1 implements Stringable { public function __toString() { return "Foo"; } }
    ',
];

// If Stringable has an alias, it should be respected
yield [
    '<?php namespace FooNamespace;
    use Stringable as Stringy;
    class Foo1 implements Stringy { public function __toString() { return "Foo"; } }
    ',
];

// ... including global namespace
yield [
    '<?php use Stringable as Stringy;
    class Foo1 implements Stringy { public function __toString() { return "Foo"; } }
    ',
];

// If Stringable is defined in different namespace, it should be handled properly
yield [
    '<?php namespace FooNamespace { use Stringable as Stringy; class Foo {} };
    namespace BarNamespace;
    class Bar implements Stringy, \Stringable { public function __toString() { return "Bar"; } }
    ',
    '<?php namespace FooNamespace { use Stringable as Stringy; class Foo {} };
    namespace BarNamespace;
    class Bar implements Stringy { public function __toString() { return "Bar"; } }
    ',
];

Best regards.

PromotedConstructorPropertyFixer should check variable names

I've encountered a strange problem with PromotedConstructorPropertyFixer. I have a class extending another class with a field named $data. Child class has overwritten constructor:

    protected array $fullData = [];

    public function __construct(array $data)
    {
        if (isset($data[Main::FIELDS])) {
            $this->data = $data[Main::FIELDS];
            $this->fullData = $data;
        } else {
            $this->throwException(Main::FIELDS);
        }
    }

Probably it should be written as this:

    protected array $fullData = [];

    public function __construct(array $data)
    {
        if (isset($data[Main::FIELDS])) {
            parent::__construct($data[Main::FIELDS])
            $this->fullData = $data;
        } else {
            $this->throwException(Main::FIELDS);
        }
    }

PHP-CS-Fixer is wrongly renaming my parameter, because probably it thinks it should be transformed into promoted constructor parameter:

 class RequestExtractor extends BaseExtractor
 {
-    protected array $fullData = [];
-
     /**
      * @throws BaseExtractorException
      * @throws JsonException
      */
-    public function __construct(array $data)
-    {
+    public function __construct(
+        protected array $fullData,
+    ) {
         if (isset($data[Main::FIELDS])) {
             $this->data = $data[Main::FIELDS];
-            $this->fullData = $data;
         } else {
             $this->throwException(Main::FIELDS);
         }

I omitted problem with little hack, but this is not how it should be done:

    public function __construct(array $data)
    {
        if (isset($data[Main::FIELDS])) {
            parent::__construct($data[Main::FIELDS]);
            $this->fullData = $data ?? [];
        } else {
            $this->throwException(Main::FIELDS);
        }
    }

I think that maybe - just maybe! - checking if the field in question and constructor parameter name are the same would solve problems like this.

Option to strip underscore prefix with DataProviderNameFixer

Is it possible to exclude the underscore when the prefix is empty?

Config:

['prefix' => '', 'suffix' => '_data_provider']

Outcome:

<?php
 class FooTest extends TestCase {
     /**
-     * @dataProvider dataProvider
+     * @dataProvider happy_path_data_provider
      */
     public function test_happy_path() {}
-    public function dataProvider() {}
+    public function _happy_path_data_provider() {}
 }

Expected:

<?php
 class FooTest extends TestCase {
     /**
-     * @dataProvider dataProvider
+     * @dataProvider happy_path_data_provider
      */
     public function test_happy_path() {}
-    public function dataProvider() {}
+    public function happy_path_data_provider() {}
 }

consider moving some to PHP-CS-Fixer itself

Awesome custom fixers, lot of good stuff :)
I was wondering NoTwoConsecutiveEmptyLinesFixer, is there something different than no_extra_blank_lines with config extra? Like to know if I missed something there.

PhpdocVarAnnotationCorrectOrderFixer please consider bringing this to PHP-CS-Fixer as well, love to have it in there :)

`MultilinePromotedPropertiesFixer`: keep blank lines between properties

I have some classes with long descriptions on each property:

class Foo
{
    public function __construct(
        /**
         * Here long
         * description
         */
        public string $a,

        /**
         * Here long
         * description
         */
        public string $b,

        /**
         * Here long
         * description
         */
        public string $c,
    ) {}
}

The MultilinePromotedPropertiesFixer removes the blank lines between these properties.

What do you prefer?

  1. Keep it as it is
  2. never remove blank lines, only ensure that there is at least one line break between promoted properties
  3. add a new config for this

How do I configure these fixers?

This is probably something extremely obvious but I can't seem to figure this out

I want to use the NumericLiteralSeparatorFixer but I do not know where I can enter the configuration options? binary for example.

I can't see any example of how to use this. I tried the following to no effect (I was guessing at how to enter the configuration values):

<?php
// ...
$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php80(), [
// ... other config removed
    // NumericLiteralSeparatorFixer
    'numeric_literal_separator' => [
    'binary' => true,
    'decimal' => true,
    'float' => true,
    'hexadecimal' => true,
    'octal' => true,
    ],

    'numeric_literal' => [
        'binary' => true,
        'decimal' => true,
        'float' => true,
        'hexadecimal' => true,
        'octal' => true,
    ],

    'numeric_literal_separator_fixer' => [
        'binary' => true,
        'decimal' => true,
        'float' => true,
        'hexadecimal' => true,
        'octal' => true,
    ],

    'binary' => true,
    'decimal' => true,
    'float' => true,
    'hexadecimal' => true,
    'octal' => true,
]);

// ...


$config->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers())
    ->setRules([
        PhpCsFixerCustomFixers\Fixer\NumericLiteralSeparatorFixer::name([
        ]) => true,

    ]);

I'm sorry if this is a silly question, but I'm completely stuck!

I can see that the fixer is definitely getting called, it's just not set up how I want to set it up with these specific options

Beautiful collection!

Hi, I just want to stop by and say how I love this collection. Great work πŸ‘

It overlaps my Symplify\CodingStandard, but I also found many new inspiration.

Thanks for making this ❀️

Fixer promoted_constructor_property removes attributes

When applying the promoted_constructor_property fix on a property with one or more attributes, the fixer removes the attributes.

Original file

<?php

namespace App;

use Symfony\Component\Validator\Constraints\NotBlank;

class Foo
{
    #[NotBlank]
    private Bar $bar;

    public function __construct(Bar $bar)
    {
        $this->bar = $bar;
    }

    public function getBar(): Bar
    {
        return $this->bar;
    }
}

Expected result

<?php

namespace App;

use Symfony\Component\Validator\Constraints\NotBlank;

class Foo
{
    public function __construct(
        #[NotBlank]
        private Bar $bar
    ) {
    }

    public function getBar(): Bar
    {
        return $this->bar;
    }
}

Generated result

<?php

namespace App;

class Foo
{
    public function __construct(
        private Bar $bar
    ) {
    }

    public function getBar(): Bar
    {
        return $this->bar;
    }
}

Command and diff

root@ac16b6f02732:/app# vendor/bin/php-cs-fixer fix src/Foo.php --dry-run --diff -vvv
PHP CS Fixer 3.5.0 The Creation by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.0.14
Loaded config default from "/app/.php-cs-fixer.dist.php".
Using cache file ".php-cs-fixer.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
F                                                                                                                                                                                                                                                                                                                       1 / 1 (100%)
Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error
   1) src/Foo.php (PhpCsFixerCustomFixers/promoted_constructor_property, class_attributes_separation, PhpCsFixerCustomFixers/multiline_promoted_properties, braces, no_unused_imports, no_extra_blank_lines)
      ---------- begin diff ----------
--- /app/src/Foo.php
+++ /app/src/Foo.php
@@ -2,16 +2,11 @@

 namespace App;

-use Symfony\Component\Validator\Constraints\NotBlank;
-
 class Foo
 {
-    #[NotBlank]
-    private Bar $bar;
-
-    public function __construct(Bar $bar)
-    {
-        $this->bar = $bar;
+    public function __construct(
+        private Bar $bar
+    ) {
     }

     public function getBar(): Bar

      ----------- end diff -----------


Checked all files in 0.010 seconds, 18.000 MB memory used

Feature Request: Add MultilinePromotedPropertiesWithAttributesFixer

Currently I'm only able to get :

public function __construct(
    #[Required,
    StringType,
    In(['primary', 'secondary'])]
    public string $type,

What I'd like it it to just be:

public function __construct(
    #[Required, StringType, In(['primary', 'secondary'])]
    public string $type,
)

or even:

public function __construct(
    #[
          Required, 
          StringType, 
          In(['primary', 'secondary'])
    ]
    public string $type,
)

NoDuplicatedArrayKeyFixer

$rules = [
  'no_empty_phpdoc' => false,
  'no_empty_phpdoc' => false,
  Fixer\NoDuplicatedArrayKeyFixer::name() => true,
  Fixer\NoDuplicatedArrayKeyFixer::name()     => true,
]

Run PHP CS Fixer

// Actual
 $rules = [
   '@PSR1' => false,
-  '@PSR1' => false,
   Fixer\NoDuplicatedArrayKeyFixer::name() => true,
   Fixer\NoDuplicatedArrayKeyFixer::name() => true,
 ]
// Expected
 $rules = [
   '@PSR1' => false,
-  '@PSR1' => false,
-  Fixer\NoDuplicatedArrayKeyFixer::name() => true,
   Fixer\NoDuplicatedArrayKeyFixer::name() => true,
 ]

How can I use this with the php-cs-fixer PHAR?

I prefer using php-cs-fixer PHAR as to not pull in all the dependencies for a tool supposed to not be integrated directly into my application, e.g. https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/bb9f72904497cea78b59faa3abeca21aaa5390a5/composer.json#L17-L32

    "require": {
        "php": "^5.6 || ^7.0",
        "ext-json": "*",
        "ext-tokenizer": "*",
        "composer/semver": "^1.4 || ^2.0 || ^3.0",
        "composer/xdebug-handler": "^1.2",
        "doctrine/annotations": "^1.2",
        "php-cs-fixer/diff": "^1.3",
        "symfony/console": "^3.4.43 || ^4.4.11 || ^5.1.3",
        "symfony/event-dispatcher": "^3.0 || ^4.0 || ^5.0",
        "symfony/filesystem": "^3.0 || ^4.0 || ^5.0",
        "symfony/finder": "^3.0 || ^4.0 || ^5.0",
        "symfony/options-resolver": "^3.0 || ^4.0 || ^5.0",
        "symfony/polyfill-php70": "^1.0",
        "symfony/polyfill-php72": "^1.4",
        "symfony/process": "^3.0 || ^4.0 || ^5.0",
        "symfony/stopwatch": "^3.0 || ^4.0 || ^5.0"
    },

But then, how can I use this without having to install php-cs-fixer via composer πŸ€”

Thanks

Feature request: doctrine migration remove method getDescription

By default getDescription returns empty string:

final class Version20240410101614 extends AbstractMigration
{
    public function getDescription(): string
    {
        return '';
    }
}

But AbstractMigration has the same method.

Finally we can remove getDescription if it returns empty string

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.