PHP code example of pmjones / php-styler

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

    

pmjones / php-styler example snippets



use PhpStyler\Config;
use PhpStyler\Files;
use PhpStyler\Styler;

return new Config(
    files: new Files(__DIR__ . '/src'),
    styler: new Styler(),
    cache: __DIR__ . '/.php-styler.cache',
);


use PhpStyler\Config;
use PhpStyler\Files;
use PhpStyler\Styler;

return new Config(
    files: new Files(__DIR__ . '\\src'),
    styler: new Styler(
        eol: "\r\n",
        lineLen: 120,
        indentLen: 8,
        indentTab: true,
    ),
);

$foo = ['bar', 'baz', 'dib'];

/** @php-styler-expansive */
$foo = [
    'bar',
    'baz',
    'dib',
];

/**
 * @php-styler-expansive
 */

$sql = "
    SELECT *
    FROM {$table}
";

$sql = "\n    SELECT TABLE_NAME\n    FROM {$table}\n";

$sql = <<<SQL
    SELECT *
    FROM {$table}
SQL;

    case 'foo':
        $foo = 'bar';
        // no break

    case 'baz':
        $baz = 'dib'
        break;

    case 'foo':
        $foo = 'bar';

    // no break
    case 'baz':
        $baz = 'dib'
        break;

switch ($foo) {
    /* this comment disappears */
}

function bar(/* this comment disappears */)
{
}

$fb = 'veryVeryLongStringToConcatenate' // this comment disappears
    . 'veryVeryLongStringToConcatenate' // this comment disappears
    . 'veryVeryLongStringToConcatenate' // this comment disappears
    . 'veryVeryLongStringToConcatenate' // this comment disappears
    . 'veryVeryLongStringToConcatenate';

$map = [
    34 => 'quot', // quotation mark
    38 => 'amp', // ampersand
    60 => 'lt', // less-than sign
    62 => 'gt', // greater-than sign -- this comment disappears
];

cp ./vendor/pmjones/php-styler/resources/php-styler.php .

./vendor/bin/php-styler preview ./src/My/Source/File.php

./vendor/bin/php-styler preview \
    -c /path/to/other/php-styler.php \
    ./src/My/Source/File.php

./vendor/bin/php-styler apply

./vendor/bin/php-styler apply -c /path/to/other/php-styler.php

./vendor/bin/php-styler apply --force

./vendor/bin/php-styler apply ./src/File.php ./resources/

./vendor/bin/php-styler check

./vendor/bin/php-styler apply -c /path/to/other/php-styler.php