PHP code example of valkyrja / phpcsfixer

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

    

valkyrja / phpcsfixer example snippets


// .php-cs-fixer.php
use Valkyrja\Fixer\Rules;
use PhpCsFixer\Finder;

$finder = Finder::create()
    ->in(__DIR__ . '/src')
    ->in(__DIR__ . '/tests');

return Rules::getConfig($finder, 'Valkyrja Framework');

Rules::getHeader('Valkyrja Framework');

// bad
$a = array(1, 2, 3);
// good
$a = [1, 2, 3];

$s = 'Hello' . ' ' . 'World';

// bad
?string $value
// good
string|null $value

$result = $a
    && $b
    && $c;

/** @param string|int|null $value */

// assertions
self::assertSame($expected, $actual);

// mock expectations
$mock->expects($this->once())->method('run');

// bad (yoda)
if (null === $value) { ... }
// good
if ($value === null) { ... }
yaml
jobs:
  phpcsfixer:
    uses: valkyrjaio/ci-phpcsfixer-php/.github/workflows/[email protected]
    permissions:
      pull-requests: write
      contents: read
    with:
      php-version: '8.4'
      paths: |
        ci:
          - '.github/ci/phpcsfixer/**'
          - '.github/workflows/phpcsfixer.yml'
        files:
          - '.github/ci/phpcsfixer/**'
          - '.github/workflows/phpcsfixer.yml'
          - 'src/**/*.php'
          - 'composer.json'
    secrets: inherit