├── .gitattributes ├── .php-cs-fixer.php ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist └── src └── Prooph.php /.gitattributes: -------------------------------------------------------------------------------- 1 | /docs export-ignore 2 | /examples export-ignore 3 | /tests export-ignore 4 | .coveralls.yml export-ignore 5 | .docheader export-ignore 6 | .gitignore export-ignore 7 | .php_cs export-ignore 8 | .travis.yml export-ignore 9 | -------------------------------------------------------------------------------- /.php-cs-fixer.php: -------------------------------------------------------------------------------- 1 | 6 | * (c) 2016-2020 Sascha-Oliver Prolic 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | $config = new Prooph\CS\Config\Prooph(); 15 | $config->getFinder()->in(__DIR__); 16 | $config->getFinder()->append(['.php_cs']); 17 | 18 | $cacheDir = \getenv('TRAVIS') ? \getenv('HOME') . '/.php-cs-fixer' : __DIR__; 19 | 20 | $config->setCacheFile($cacheDir . '/.php_cs.cache'); 21 | 22 | return $config; 23 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [v0.2.1](https://github.com/prooph/php-cs-fixer-config/tree/v0.2.1) 4 | 5 | [Full Changelog](https://github.com/prooph/php-cs-fixer-config/compare/v0.2.0...v0.2.1) 6 | 7 | **Closed issues:** 8 | 9 | - Tag release [\#2](https://github.com/prooph/php-cs-fixer-config/issues/2) 10 | 11 | **Merged pull requests:** 12 | 13 | - Update composer.json [\#3](https://github.com/prooph/php-cs-fixer-config/pull/3) ([enumag](https://github.com/enumag)) 14 | 15 | ## [v0.2.0](https://github.com/prooph/php-cs-fixer-config/tree/v0.2.0) (2017-11-27) 16 | [Full Changelog](https://github.com/prooph/php-cs-fixer-config/compare/v0.1.1...v0.2.0) 17 | 18 | **Implemented enhancements:** 19 | 20 | - allow php 7.2 [\#1](https://github.com/prooph/php-cs-fixer-config/pull/1) ([prolic](https://github.com/prolic)) 21 | 22 | ## [v0.1.1](https://github.com/prooph/php-cs-fixer-config/tree/v0.1.1) (2016-12-01) 23 | [Full Changelog](https://github.com/prooph/php-cs-fixer-config/compare/v0.1.0...v0.1.1) 24 | 25 | ## [v0.1.0](https://github.com/prooph/php-cs-fixer-config/tree/v0.1.0) (2016-12-01) 26 | 27 | 28 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2025, prooph software GmbH 2 | Copyright (c) 2016-2025, Sascha-Oliver Prolic 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | * Neither the name of the prooph software GmbH nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # php-cs-fixer-config 2 | PHP CS Fixer config for prooph components 3 | 4 | [![Build Status](https://travis-ci.org/prooph/php-cs-fixer-config.svg?branch=master)](https://travis-ci.org/prooph/php-cs-fixer-config) 5 | [![Coverage Status](https://coveralls.io/repos/prooph/php-cs-fixer-config/badge.svg?branch=master&service=github)](https://coveralls.io/github/prooph/php-cs-fixer-config?branch=master) 6 | [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/prooph/improoph) 7 | 8 | It's based on the ideas of [`refinery29/php-cs-fixer-config`](https://github.com/refinery29/php-cs-fixer-config/). 9 | 10 | ## Installation 11 | 12 | Run 13 | 14 | ``` 15 | $ composer require --dev prooph/php-cs-fixer-config 16 | ``` 17 | 18 | Add to composer.json; 19 | 20 | ```json 21 | "scripts": { 22 | "check": [ 23 | "@cs", 24 | ], 25 | "cs": "php-cs-fixer fix -v --diff --dry-run", 26 | "cs-fix": "php-cs-fixer fix -v --diff", 27 | } 28 | ``` 29 | 30 | ## Usage 31 | 32 | ### Configuration 33 | 34 | Create a configuration file `.php-cs-fixer.php` in the root of your project: 35 | 36 | ```php 37 | getFinder()->in(__DIR__); 41 | $config->getFinder()->append(['.php-cs-fixer.php']); 42 | 43 | $cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__; 44 | 45 | $config->setCacheFile($cacheDir . '/.php-cs-fixer.cache'); 46 | 47 | return $config; 48 | ``` 49 | 50 | #### Header 51 | 52 | When you create a `.docheader` in the root of your project it will be used as header comment. 53 | 54 | It is recommended to use the following template but you may use anything you want. 55 | 56 | ``` 57 | This file is part of `%package%`. 58 | (c) 2016-%year% prooph software GmbH 59 | (c) 2016-%year% Sascha-Oliver Prolic 60 | 61 | For the full copyright and license information, please view the LICENSE 62 | file that was distributed with this source code. 63 | ``` 64 | 65 | ### Git 66 | 67 | Add `.php-cs-fixer.cache` (this is the cache file created by `php-cs-fixer`) to `.gitignore`: 68 | 69 | ``` 70 | vendor/ 71 | .php-cs-fixer.cache 72 | ``` 73 | 74 | ### Travis 75 | 76 | Update your `.travis.yml` to cache the `.php-cs-fixer.cache` file: 77 | 78 | ```yml 79 | cache: 80 | directories: 81 | - $HOME/.php-cs-fixer.cache 82 | ``` 83 | 84 | Then run `php-cs-fixer` in the `script` section: 85 | 86 | ```yml 87 | script: 88 | - vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --verbose --diff --dry-run 89 | ``` 90 | 91 | ## Fixing issues 92 | 93 | ### Manually 94 | 95 | If you need to fix issues locally, just run 96 | 97 | ``` 98 | $ composer cs-fix 99 | ``` 100 | 101 | ### Pre-commit hook 102 | 103 | You can add a `pre-commit` hook 104 | 105 | ``` 106 | $ touch .git/pre-commit && chmod +x .git/pre-commit 107 | ``` 108 | 109 | Paste this into `.git/pre-commit`: 110 | 111 | ```bash 112 | #!/usr/bin/env bash 113 | 114 | echo "pre commit hook start" 115 | 116 | CURRENT_DIRECTORY=`pwd` 117 | GIT_HOOKS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 118 | 119 | PROJECT_DIRECTORY="$GIT_HOOKS_DIR/../.." 120 | 121 | cd $PROJECT_DIRECTORY; 122 | PHP_CS_FIXER="vendor/bin/php-cs-fixer" 123 | 124 | HAS_PHP_CS_FIXER=false 125 | 126 | if [ -x "$PHP_CS_FIXER" ]; then 127 | HAS_PHP_CS_FIXER=true 128 | fi 129 | 130 | if $HAS_PHP_CS_FIXER; then 131 | git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do 132 | ${PHP_CS_FIXER} fix --config-file=.php-cs-fixer.php --verbose ${line}; 133 | git add "$line"; 134 | done 135 | else 136 | echo "" 137 | echo "Please install php-cs-fixer, e.g.:" 138 | echo "" 139 | echo " composer require friendsofphp/php-cs-fixer:2.0.0" 140 | echo "" 141 | fi 142 | 143 | cd $CURRENT_DIRECTORY; 144 | echo "pre commit hook finish" 145 | ``` 146 | 147 | ## License 148 | 149 | This package is licensed using the MIT License. 150 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prooph/php-cs-fixer-config", 3 | "description": "PHP CS Fixer config for prooph components", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Alexander Miertsch", 9 | "email": "contact@prooph.de", 10 | "homepage": "http://www.codeliner.ws/" 11 | }, 12 | { 13 | "name": "Sascha-Oliver Prolic", 14 | "email": "saschaprolic@googlemail.com" 15 | } 16 | ], 17 | "require": { 18 | "php": "^8.1", 19 | "friendsofphp/php-cs-fixer": "^3.69.1" 20 | }, 21 | "require-dev": { 22 | "phpunit/phpunit": "^10.5.45", 23 | "php-coveralls/php-coveralls": "^2.7.0" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Prooph\\CS\\Config\\": "src" 28 | } 29 | }, 30 | "autoload-dev": { 31 | "psr-4": { 32 | "ProophTest\\CS\\Config\\": "test" 33 | } 34 | }, 35 | "scripts": { 36 | "check": [ 37 | "@cs", 38 | "@test" 39 | ], 40 | "cs": "php-cs-fixer fix -v --diff --dry-run", 41 | "cs-fix": "php-cs-fixer fix -v --diff", 42 | "test": "phpunit" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | ./tests 15 | 16 | 17 | 18 | 19 | ./src/ 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Prooph.php: -------------------------------------------------------------------------------- 1 | 6 | * (c) 2016-2025 Sascha-Oliver Prolic 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Prooph\CS\Config; 15 | 16 | use PhpCsFixer\Config; 17 | 18 | class Prooph extends Config 19 | { 20 | public function __construct() 21 | { 22 | parent::__construct('prooph'); 23 | 24 | $this->setRiskyAllowed(true); 25 | } 26 | 27 | public function getRules(): array 28 | { 29 | $rules = [ 30 | '@PSR12' => true, 31 | 'array_syntax' => ['syntax' => 'short'], 32 | 'binary_operator_spaces' => [ 33 | 'operators' => [ 34 | '=>' => 'single_space', 35 | '=' => 'single_space', 36 | ], 37 | ], 38 | 'blank_line_after_opening_tag' => true, 39 | 'blank_line_after_namespace' => true, 40 | 'blank_line_before_statement' => true, 41 | 'braces' => true, 42 | 'cast_spaces' => true, 43 | 'class_definition' => true, 44 | 'combine_consecutive_unsets' => true, 45 | 'concat_space' => false, 46 | 'declare_strict_types' => true, 47 | 'echo_tag_syntax' => [ 48 | 'format' => 'long', 49 | ], 50 | 'elseif' => true, 51 | 'encoding' => true, 52 | 'full_opening_tag' => true, 53 | 'function_declaration' => true, 54 | 'function_typehint_space' => true, 55 | 'single_line_comment_style' => true, 56 | 'header_comment' => [ 57 | 'comment_type' => 'PHPDoc', 58 | 'header' => 'Prooph was here at `%package%` in `%year%`! Please create a .docheader in the project root and run `composer cs-fix`', 59 | 'location' => 'after_open', 60 | 'separate' => 'both', 61 | ], 62 | 'include' => true, 63 | 'indentation_type' => true, 64 | 'linebreak_after_opening_tag' => true, 65 | 'line_ending' => true, 66 | 'constant_case' => [ 67 | 'case' => 'lower', 68 | ], 69 | 'lowercase_keywords' => true, 70 | 'method_argument_space' => true, 71 | 'class_attributes_separation' => true, 72 | 'modernize_types_casting' => true, 73 | 'multiline_whitespace_before_semicolons' => [ 74 | 'strategy' => 'no_multi_line', 75 | ], 76 | 'native_function_casing' => true, 77 | 'native_function_invocation' => [ 78 | 'include' => ['@internal'], 79 | 'scope' => 'all', 80 | ], 81 | 'new_with_braces' => true, 82 | 'no_alias_functions' => true, 83 | 'no_blank_lines_after_class_opening' => true, 84 | 'no_closing_tag' => true, 85 | 'no_empty_statement' => true, 86 | 'no_extra_blank_lines' => true, 87 | 'no_leading_import_slash' => true, 88 | 'no_leading_namespace_whitespace' => true, 89 | 'no_multiline_whitespace_around_double_arrow' => true, 90 | 'no_short_bool_cast' => true, 91 | 'no_singleline_whitespace_before_semicolons' => true, 92 | 'no_spaces_around_offset' => true, 93 | 'no_trailing_comma_in_list_call' => true, 94 | 'no_trailing_comma_in_singleline_array' => true, 95 | 'no_unneeded_control_parentheses' => true, 96 | 'no_unreachable_default_argument_value' => true, 97 | 'no_unused_imports' => true, 98 | 'no_useless_else' => true, 99 | 'no_useless_return' => true, 100 | 'no_spaces_inside_parenthesis' => true, 101 | 'no_trailing_whitespace_in_comment' => true, 102 | 'no_whitespace_before_comma_in_array' => true, 103 | 'no_whitespace_in_blank_line' => true, 104 | 'normalize_index_brace' => true, 105 | 'not_operator_with_successor_space' => true, 106 | 'object_operator_without_whitespace' => true, 107 | 'ordered_imports' => true, 108 | 'phpdoc_indent' => true, 109 | 'phpdoc_inline_tag_normalizer' => true, 110 | 'phpdoc_tag_type' => true, 111 | 'psr_autoloading' => true, 112 | 'return_type_declaration' => true, 113 | 'semicolon_after_instruction' => true, 114 | 'short_scalar_cast' => true, 115 | 'simplified_null_return' => false, 116 | 'single_blank_line_at_eof' => true, 117 | 'single_class_element_per_statement' => true, 118 | 'single_import_per_statement' => true, 119 | 'single_line_after_imports' => true, 120 | 'single_quote' => true, 121 | 'standardize_not_equals' => true, 122 | 'strict_comparison' => true, 123 | 'switch_case_semicolon_to_colon' => true, 124 | 'switch_case_space' => true, 125 | 'ternary_operator_spaces' => true, 126 | 'trailing_comma_in_multiline' => [ 127 | 'elements' => [ 128 | 'arrays', 129 | ], 130 | ], 131 | 'trim_array_spaces' => true, 132 | 'unary_operator_spaces' => true, 133 | 'visibility_required' => true, 134 | 'whitespace_after_comma_in_array' => true, 135 | ]; 136 | 137 | $rules['header_comment'] = $this->headerComment($rules['header_comment']); 138 | 139 | return $rules; 140 | } 141 | 142 | private function headerComment(array $rules): array 143 | { 144 | if (\file_exists('.docheader')) { 145 | $header = \file_get_contents('.docheader'); 146 | } else { 147 | $header = $rules['header']; 148 | } 149 | 150 | // remove comments from existing .docheader or crash 151 | $header = \str_replace(['/**', ' */', ' * ', ' *'], '', $header); 152 | $package = 'unknown'; 153 | 154 | if (\file_exists('composer.json')) { 155 | $package = \json_decode(\file_get_contents('composer.json'))->name; 156 | } 157 | 158 | $header = \str_replace(['%package%', '%year%'], [$package, (new \DateTime('now'))->format('Y')], $header); 159 | 160 | $rules['header'] = \trim($header); 161 | 162 | return $rules; 163 | } 164 | } 165 | --------------------------------------------------------------------------------