PHP code example of kgabryel / code-quality

1. Go to this page and download the library: Download kgabryel/code-quality 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/ */

    

kgabryel / code-quality example snippets



// .php-cs-fixer.dist.php (Symfony)

declare(strict_types=1);

use Kgabryel\CodeQuality\Preset\CsFixer\SymfonyConfig as Preset;

$finder = new PhpCsFixer\Finder()
    ->in([
        ...Preset::getPaths(__DIR__),               // katalogi analizowane dla frameworka
    ]);

return new PhpCsFixer\Config()
    ->setRiskyAllowed(Preset::isRiskyAllowed())     // zezwolenie na reguły risky
    ->setRules([
        ...Preset::getSets(),                       // kompletny zestaw reguł
    ])
    ->setFinder($finder)
    ->setCacheFile(__DIR__ . '/var/.php-cs-fixer.cache');

->setRules([
    ...Preset::getSets(),
    'yoda_style' => true,   // nadpisanie
    'final_class' => true,  // nowa reguła
])

$rules = Preset::getSets();
unset($rules['declare_strict_types']);

return new PhpCsFixer\Config()
    // ...
    ->setRules($rules)

$finder = new PhpCsFixer\Finder()
    ->in([
        ...Preset::getPaths(__DIR__),
        __DIR__ . '/bin',            // dodatkowy katalog
    ])
    ->exclude('Legacy');             // wykluczenie


// rector.php (Laravel)

declare(strict_types=1);

use Kgabryel\CodeQuality\Preset\Rector\LaravelConfig as Preset;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;

return RectorConfig::configure()
    ->withPaths([
        ...Preset::getPaths(__DIR__),      // katalogi analizowane dla frameworka
    ])
    ->withImportNames()                    // FQCN zamieniane na importy use
    ->withPhpSets(php84: true)             // reguły dla wybranej wersji PHP
    ->withSets([
        ...Preset::getSets(),              // zestawy reguł Rectora
    ])
    ->withComposerBased(
        ...Preset::getComposerBased(),     // zestawy aktywowane na podstawie composer.json
    )
    ->withAttributesSets(
        ...Preset::getAttributesSets(),    // migracja adnotacji do atrybutów
    )
    ->withCache(__DIR__ . '/.rector-cache/')
    ->withSkip([
        ...Preset::getsSkip(),             // reguły wyłączone z analizy
    ]);

->withSkip([
    ...Preset::getsSkip(),
    ReadonlyPropertyRector::class,  // dodatkowa reguła do pominięcia
    __DIR__ . '/src/Legacy',        // katalog wyłączony z analizy
])

->withSets([
    ...Preset::getSets(),
    SetList::NAMING,                // nowy zestaw
])
bash
composer in/code-quality analysis
php vendor/bin/code-quality test
shell
# Przykład zawartości pliku check.sh (Base, wszystkie narzędzia)
#!/usr/bin/env sh

echo "===== PHP Parallel Lint ====="
php vendor/bin/parallel-lint src tests && echo "✓ PHP Parallel Lint passed" || echo "✗ PHP Parallel Lint failed"

echo "===== PHP Code Sniffer (check) ====="
php vendor/bin/phpcs && echo "✓ PHP Code Sniffer (check) passed" || echo "✗ PHP Code Sniffer (check) failed"

echo "===== PHPStan ====="
php vendor/bin/phpstan analyse --memory-limit=512M && echo "✓ PHPStan passed" || echo "✗ PHPStan failed"
json5
// infection.json5 (Symfony)
{
  "$schema": "vendor/infection/infection/resources/schema.json",
  "tmpDir": "var/.infection/",
  "source": {
    "directories": [
      "src"
    ],
    "excludes": [
      "Kernel.php"
    ]
  },
  "logs": {
    "text": "var/.infection/infection.txt",
    "html": "var/.infection/infection.html"
  },
  "mutators": {
    "@default": true,
    "CastInt": false,
    "CastString": false,
    "MethodCallRemoval": {
      "ignore": [
        "App\\Entity\\*::*",
        "*::__construct"
      ]
    }
  }
}