PHP code example of amphp / php-cs-fixer-config

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

    

amphp / php-cs-fixer-config example snippets




$config = new Amp\CodeStyle\Config;
$config->getFinder()
    ->in(__DIR__ . "/examples")
    ->in(__DIR__ . "/src")
    ->in(__DIR__ . "/test");

$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
$config->setCacheFile($cacheDir . '/.php_cs.cache');

return $config;

vendor/
.php_cs.cache
yml
cache:
  directories:
    - $HOME/.php-cs-fixer
yml
script:
  - vendor/bin/php-cs-fixer fix --config=.php_cs.dist --verbose --diff --dry-run

./vendor/bin/php-cs-fixer fix -v
bash
#!/usr/bin/env bash

echo "Running php-cs-fixer to format the code..."

CURRENT_DIRECTORY=`pwd`
GIT_HOOKS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

PROJECT_DIRECTORY="$GIT_HOOKS_DIR/../.."

cd $PROJECT_DIRECTORY;
PHP_CS_FIXER="vendor/bin/php-cs-fixer"

HAS_PHP_CS_FIXER=false

if [ -x "$PHP_CS_FIXER" ]; then
    HAS_PHP_CS_FIXER=true
fi

if $HAS_PHP_CS_FIXER; then
    git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do
        ${PHP_CS_FIXER} fix --config-file=.php_cs --verbose ${line};
        git add "$line";
    done
else
    echo ""
    echo "Please install php-cs-fixer, e.g.:"
    echo ""
    echo "  composer