PHP code example of kubawerlos / php-cs-fixer-custom-fixers

1. Go to this page and download the library: Download kubawerlos/php-cs-fixer-custom-fixers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kubawerlos / php-cs-fixer-custom-fixers example snippets



diff
 
 return (new PhpCsFixer\Config())
+    ->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers())
     ->setRules([
         '@PSR2' => true,
         'array_syntax' => ['syntax' => 'short'],
+        PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer::name() => true,
+        PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer::name() => true,
     ]);
diff
 
-/*foo*/
+/* foo */
diff
 
-var_dump($x);
+//var_dump($x);
diff
 
 class Foo {
     public function __construct(
         $param1,
         $param2
-    ) {
-    }
+    ) {}
 }
diff
 
 class FooTest extends TestCase {
     /**
-     * @dataProvider dataProvider
+     * @dataProvider provideSomethingCases
      */
     public function testSomething($expected, $actual) {}
-    public function dataProvider() {}
+    public function provideSomethingCases() {}
 }
diff
 
 class FooTest extends TestCase {
     /**
      * @dataProvider provideSomethingCases
      */
     public function testSomething($expected, $actual) {}
-    public function provideSomethingCases(): array {}
+    public function provideSomethingCases(): iterable {}
 }
diff
-
+ declare(strict_types=1);
 $foo;
-declare(strict_types=1);
 $bar;
diff
  function foo(
     int $x
-)
-{
-}
+) {}
diff
 
-if (isset($array[$key])) {
+if (array_key_exists($key, $array)) {
     echo $array[$key];
 }
diff
 
-/** Hello
+/**
+ * Hello
  * World!
  */
diff
  class Foo {
-    public function __construct(private array $a, private bool $b, private int $i) {}
+    public function __construct(
+        private array $a,
+        private bool $b,
+        private int $i
+    ) {}
 }
diff
 
-//var_dump($_POST);
 print_r($_POST);
diff
 
 namespace Migrations;
 use Doctrine\DBAL\Schema\Schema;
-/**
- * Auto-generated Migration: Please modify to your needs!
- */
 final class Version20180609123456 extends AbstractMigration
 {
     public function up(Schema $schema)
     {
-        // this up() migration is auto-generated, please modify it to your needs
         $this->addSql("UPDATE t1 SET col1 = col1 + 1");
     }
     public function down(Schema $schema)
     {
-        // this down() migration is auto-generated, please modify it to your needs
         $this->addSql("UPDATE t1 SET col1 = col1 - 1");
     }
 }
diff
 
 $x = [
-    "foo" => 1,
     "bar" => 2,
     "foo" => 3,
 ];
diff
 
 namespace Foo;
-use DateTime;
 class Bar {
-    public function __construct(DateTime $dateTime) {}
+    public function __construct(\DateTime $dateTime) {}
 }
diff
 
-$x = new \Foo();
+$x = new Foo();
 namespace Bar;
 $y = new \Baz();
diff
 
-/**
- * Created by PhpStorm.
- * User: root
- * Date: 01.01.70
- * Time: 12:00
- */
 namespace Foo;
diff
 
-function foo(&$x) {}
+function foo($x) {}
diff
 
-echo 'foo' . 'bar';
+echo 'foobar';
diff
 
-$x = ['foo', 'bar', ];
+$x = ['foo', 'bar'];
diff
 
 /**
- * Class Foo
  * Class to do something
  */
 class Foo {
     /**
-     * Get bar
      */
     function getBar() {}
 }
diff
 
-DIR__ . "/../vendor/autoload.php";
diff
 
-foo(($bar));
+foo($bar);
diff
 
-$isEmpty = strlen($string) === 0;
-$isNotEmpty = strlen($string) > 0;
+$isEmpty = $string === '';
+$isNotEmpty = $string !== '';
diff
 
-echo 0b01010100_01101000; // binary
-echo 135_798_642; // decimal
-echo 1_234.456_78e-4_321; // float
-echo 0xAE_B0_42_FC; // hexadecimal
-echo 0123_4567; // octal
+echo 0b0101010001101000; // binary
+echo 135798642; // decimal
+echo 1234.45678e-4321; // float
+echo 0xAEB042FC; // hexadecimal
+echo 01234567; // octal
diff
 
 class FooTest extends TestCase {
     public function testFoo() {
-        self::assertSame($value, 10);
+        self::assertSame(10, $value);
     }
 }
diff
 
 class FooTest extends TestCase {
     public function testFoo() {
-        self::assertSame($size, count($elements));
-        self::assertSame($className, get_class($object));
+        self::assertCount($size, $elements);
+        self::assertInstanceOf($className, $object);
     }
 }
diff
 
 class FooTest extends TestCase {
     public function testFoo() {
         $this->markTestSkipped();
-        return;
     }
 }
diff
 
 /**
- * @return int[]
+ * @return array<int>
  */
  function foo() { return [1, 2]; }
diff
 
-/** @var Foo $foo */
 $bar = new Foo();
diff
 
 /**
  * @param bool $b
- * @param int $i
  * @param string $s this is string
- * @param string $s duplicated
  */
 function foo($b, $s) {}
diff
 
 /**
  * @author John Doe
- * @package foo
- * @subpackage bar
  * @version 1.0
  */
 function foo_bar() {}
diff
 
 /**
+ * @param int $a
  * @param int $b
- * @param int $a
  * @param int $c
  */
 function foo($a, $b, $c) {}
diff
 
 /**
  * @param string $foo
- * @param        $bar
+ * @param mixed  $bar
  */
 function a($foo, $bar) {}
diff
 
 class Foo {
     /**
-     * @var Foo
+     * @var self
      */
      private $instance;
 }
diff
 
 /**
- * @param array<string>
+ * @param list<string>
  */
 function foo($x) {}
diff
- /** @var array<int,string> */
+ /** @var array<int, string> */
diff
 
 /**
- * @param null | string $x
+ * @param null|string $x
  */
 function foo($x) {}
diff
 
-/** @var string $x */
 $x = getValue();
+assert(is_string($x));
diff
  class Foo {
     public function __construct(
-        public array $a,
-        public bool $b,
+        public readonly array $a,
+        public readonly bool $b,
     ) {}
 }
diff
 
-$foo =new Foo();
+$foo = new Foo();
diff
 
-class Foo
+class Foo implements \Stringable
 {
    public function __toString()
    {
         return "Foo";
    }
 }