PHP code example of juliangut / easy-coding-standard-config

1. Go to this page and download the library: Download juliangut/easy-coding-standard-config 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/ */

    

juliangut / easy-coding-standard-config example snippets




use Jgut\ECS\ConfigSet82;

return (new ConfigSet82())
    ->setHeader(<<<'HEADER'
    Easy Coding Standard config.

    @license BSD-3-Clause
    @link https://github.com/juliangut/easy-coding-standard-config
    HEADER)
    ->configureBuilder()
    ->withPaths([
        __FILE__,
        __DIR__ . '/src',
    ]);

(new ConfigSet82())
    ->setHeader(<<<'HEADER'
    (c) 2021-{{year}} Julián Gutiérrez <[email protected]>

    This file is part of package {{package}}
    HEADER);

// Assuming current year is 2024
(new ConfigSet82())
    ->setHeader(<<<'HEADER'
    (c) 2023-{{year}} Julián Gutiérrez <[email protected]>

    This file is part of package {{package}}
    HEADER);

(new ConfigSet82())
    ->enablePhpUnitRules();

(new ConfigSet82())
    ->enableDoctrineRules();

(new ConfigSet82())
    ->enableTypeInferRules();

(new ConfigSet82())
    ->setAdditionalRules([
        SingleLineThrowFixer::class => true,
    ]);

use Jgut\ECS\ConfigSet82;
use PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer;

class CustomConfigSet extends ConfigSet82
{
    protected function getRules(): array
    {
        // Return your custom rules, or add/remove rules from parent's getRules()
        return array_merge(
            parent::getRules(),
            [
                SingleLineThrowFixer::class => true,
            ]
        );
    }
}
diff
--- Original
+++ New
 

+/*
+ * (c) 2021-2024 Julián Gutiérrez <[email protected]>
+ *
+ * This file is part of package juliangut/php-cs-fixer-config
+ */
+
 declare(strict_types=1);

 namespace App;
diff
--- Original
+++ New
 

+/*
+ * (c) 2024 Julián Gutiérrez <[email protected]>
+ *
+ * This file is part of package juliangut/php-cs-fixer-config
+ */
+
 declare(strict_types=1);

 namespace App;
diff
--- Original
+++ New


 declare(strict_types=1);

 namespace App;
 
 class Foo
 {
-    /**
-     * @var string|null
-     */
-    protected $foo
+    protected ?string $foo

-    /**
-     * @var Bar
-     */
-    protected $bar
+    protected Bar $bar

-    /**
-     * @var bool
-     */
-    protected $baz
+    protected bool $baz

     /**
      * Foo constructor.
-     *
-     * @param string|null $foo
-     * @param Bar         $bar
-     * @param bool        $baz
      */
-    public function __construct($foo, $bar, $baz = false)
+    public function __construct(?string $foo, Bar $bar, bool $baz = false)
     {
         $this->foo = $foo;
         $this->bar = $bar;
         $this->baz = $baz;
     }

-    /**
-     * @return bool
-     *
-    public function isBaz()
+    public function isBaz(): bool
     {
        return $this->baz;
     }
 }