Skip to content

Instantly share code, notes, and snippets.

@debiprasad
Last active May 9, 2017 06:24
Show Gist options
  • Save debiprasad/9111eb310d0bedcd727ac4c716c6ac2e to your computer and use it in GitHub Desktop.
Save debiprasad/9111eb310d0bedcd727ac4c716c6ac2e to your computer and use it in GitHub Desktop.
Recommended configuration file for PHP Coding Standards Fixer (FriendsOfPHP/PHP-CS-Fixer) for Laravel projects. This is designed for version 2.x of FriendsOfPHP/PHP-CS-Fixer and does not work for 1.x version.
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('public')
->exclude('vendor')
->exclude('storage')
->exclude('app')
->exclude('bootstrap')
->exclude('tests')
->notPath('server.php')
->in(__DIR__);
return PhpCsFixer\Config::create()
->setRules([
// PSR2 Level
'@PSR2' => true,
// PHP arrays should be declared using the short syntax.
'array_syntax' => ['syntax' => 'short'],
// Binary operators should be surrounded by at least one space.
'binary_operator_spaces' => true,
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline.
'blank_line_after_opening_tag' => true,
// An empty line feed should precede a return statement.
'blank_line_before_return' => true,
// A single space should be between cast and variable.
'cast_spaces' => true,
// No whitespace for concatenation.
'concat_space' => ['spacing' => 'none'],
// Include/Require and file path should be divided with a single space. File path should not be placed under brackets.
'include' => true,
// Master functions shall be used instead of aliases. Risky.
// 'no_alias_functions' => true,
// There should be no empty lines after class opening brace.
'no_blank_lines_after_class_opening' => true,
// There should not be blank lines between docblock and the documented element.
'no_blank_lines_after_phpdoc' => true,
// Remove duplicated semicolons.
'no_empty_statement' => true,
// Removes extra consecutive blank lines.
'no_extra_consecutive_blank_lines' => ['use'],
// Remove leading slashes in use clauses.
'no_leading_import_slash' => true,
// The namespace declaration line shouldn't contain leading whitespace.
'no_leading_namespace_whitespace' => true,
// No multiline whitespace around the double arrow.
'no_multiline_whitespace_around_double_arrow' => true,
// Multi-line whitespace before closing semicolon are prohibited.
'no_multiline_whitespace_before_semicolons' => true,
// Replace short-echo <?= with long format <?php echo syntax.
'no_short_echo_tag' => true,
// Single-line whitespace before closing semicolon are prohibited.
'no_singleline_whitespace_before_semicolons' => true,
// Remove trailing commas in list function calls.
'no_trailing_comma_in_list_call' => true,
// PHP single-line arrays should not have trailing comma.
'no_trailing_comma_in_singleline_array' => true,
// Unused use statements must be removed.
'no_unused_imports' => true,
// Remove trailing whitespace at the end of blank lines.
'no_whitespace_in_blank_line' => true,
// Logical NOT operators (!) should have one trailing whitespace.
'not_operator_with_successor_space' => true,
// There should not be space before or after object T_OBJECT_OPERATOR ->.
'object_operator_without_whitespace' => true,
// Use statements must be in order.
'ordered_imports' => true,
// Docblocks should have the same indentation as the documented subject.
'phpdoc_indent' => true,
// Fix phpdoc inline tags, make inheritdoc always inline.
'phpdoc_inline_tag' => true,
// @access annotations should be omitted from phpdocs.
'phpdoc_no_access' => true,
// No alias PHPDoc tags should be used.
'phpdoc_no_alias_tag' => ['type' => 'var'],
// @package and @subpackage annotations should be omitted from phpdocs.
'phpdoc_no_package' => true,
// Scalar types should always be written in the same form. int not integer, bool not boolean, float not real or double.
'phpdoc_scalar' => true,
// Phpdocs summary should end in either a full stop, exclamation mark, or question mark.
'phpdoc_summary' => true,
// Docblocks should only be used on structural elements.
'phpdoc_to_comment' => true,
// Phpdocs should start and end with content, excluding the very first and last line of the docblocks.
'phpdoc_trim' => true,
// @var and @type annotations should not contain the variable name.
'phpdoc_var_without_name' => true,
// Inside a classy element "self" should be preferred to the class name itself.
'self_accessor' => true,
// A return statement wishing to return void should not return null. Risky since 7.1.
// 'simplified_null_return' => true,
// There should be exactly one blank line before a namespace declaration.
'single_blank_line_before_namespace' => true,
// Convert double quotes to single quotes for simple strings.
'single_quote' => true,
// Replace all <> with !=.
'standardize_not_equals' => true,
// Standardize spaces around ternary operator.
'ternary_operator_spaces' => true,
// PHP multi-line arrays should have a trailing comma.
'trailing_comma_in_multiline_array' => true,
// Arrays should be formatted like function/method arguments, without leading or trailing single line space.
'trim_array_spaces' => true,
// Unary operators should be placed adjacent to their operands.
'unary_operator_spaces' => true,
])
->setFinder($finder);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment