narrowspark/php-cs-fixer-config

Provides a configuration for friendsofphp/php-cs-fixer, used within Narrowspark.

v2.0.4 2017-09-01 19:59 UTC

README

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6172726f77737061726b2f7068702d63732d66697865722d636f6e6669672e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e312e302d3838393242462e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e6172726f77737061726b2f7068702d63732d66697865722d636f6e6669672f6d61737465722e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f6769747465722f726f6f6d2f6e776a732f6e772e6a732e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265

This repository provides a configuration for [`friendsofphp/php-cs-fixer`](http://github.com/FriendsOfPHP/PHP-CS-Fixer), which we use to verify and enforce a single coding standard for PHP code within Narrowspark.

Installation

Via Composer

$ composer require narrowspark/php-cs-fixer-config

Usage

Create a configuration file '.php_cs' in the root of your project:

<?php
use Narrowspark\CS\Config\Config;

$config = new Config();
$config->getFinder()
    ->files()
    ->in(__DIR__)
    ->exclude('build')
    ->exclude('vendor')
    ->name('*.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;

$config->setCacheFile($cacheDir . '/.php_cs.cache');

return $config;

💡 Optionally, you can specify a header comment to use, which will automatically enable the header_comment fixer:

$header = <<<EOF
Copyright (c) 2016 Narrowspark

For the full copyright and license information, please view
the LICENSE file that was distributed with this source code.
EOF;

$config = new Narrowspark\CS\Config\Config($header);

Git

Add .php_cs.cache (this is the cache file created by php-cs-fixer) to .gitignore:

vendor/
.php_cs.cache

Travis

Update your .travis.yml to cache the php_cs.cache file:

cache:
  directories:
    - $HOME/.php-cs-fixer

Then run php-cs-fixer in the script section:

script:
  - ./vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --diff --dry-run

If you only want to run php-cs-fixer on one PHP version, update your build matrix and use a condition:

matrix:
  include:
    - php: 7.1
      env: WITH_CS=true
    - php: 7.2
      env: WITH_COVERAGE=true

script:
  - if [[ "$WITH_CS" == "true" ]]; then ./vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --diff --dry-run; fi

#StyleCi

If you using StyleCi just copy .styleci.yml to you repository and enable styleci. Or copy this setting to StyleCi

preset: recommended

risky: true

linting: true

enabled:
  - align_equals
  - combine_consecutive_unsets
  - concat_with_spaces
  - const_visibility_required
  - declare_strict_types
  - dir_constant
  - echo_to_print
  - ereg_to_preg
  - mb_str_functions
  - modernize_types_casting
  - no_blank_lines_after_return
  - no_trailing_whitespace_in_comment
  - no_blank_lines_before_namespace
  - no_empty_comment
  - no_unneeded_control_parentheses
  - no_unreachable_default_argument_value
  - no_unused_imports
  - no_useless_else
  - ordered_class_elements
  - php_unit_construct
  - php_unit_dedicate_assert
  - phpdoc_add_missing_param_annotation
  - pow_to_exponentiation
  - protected_to_private
  - random_api_migration
  - return_type_declaration

disabled:
  - blank_line_after_opening_tag
  - class_keyword_remove
  - phpdoc_no_empty_return
  - self_accessor

finder:
  exclude:
    - "build"
    - "vendor"
    - "tests"
  name:
    - "*.php"

Testing

$ vendor/bin/phpunit

Contributing

If you would like to help take a look at the list of issues and check our Contributing guild.

Note: Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Credits

License

The MIT License (MIT). Please see License File for more information.