├── .github └── workflows │ └── lint.yml ├── .gitignore ├── .php-cs-fixer.dist.php ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src └── Config.php /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | on: 3 | push: 4 | branches: 5 | - master 6 | - stable* 7 | pull_request: 8 | 9 | jobs: 10 | lint-php: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2 15 | - name: Install Dependencies 16 | run: composer install --prefer-dist 17 | - name: Load problem matcher for php -l 18 | uses: korelstar/phplint-problem-matcher@v1 19 | - name: PHP syntax check 20 | run: "find src/ -type f -name '*.php' -print0 | xargs -0 -L1 -P4 -- php -l -f" 21 | - name: PHP Coding Standards Fixer 22 | run: vendor/bin/php-cs-fixer fix --dry-run --diff 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | /composer.lock 3 | /vendor/ 4 | 5 | /.idea 6 | 7 | .php_cs.cache 8 | .php-cs-fixer.cache 9 | -------------------------------------------------------------------------------- /.php-cs-fixer.dist.php: -------------------------------------------------------------------------------- 1 | getFinder() 12 | ->ignoreVCSIgnored(true) 13 | ->notPath('vendor') 14 | ->in(__DIR__); 15 | return $config; 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | ## 1.3.2 - 2024-10-14 5 | ### Added 6 | * `type_declaration_spaces`: A single space between typehint and variable name 7 | 8 | ## 1.3.1 - 2024-09-19 9 | ### Fixed 10 | * Removed misbehaving `ErickSkrauch/blank_line_before_return` and `ErickSkrauch/line_break_after_statements` rules 11 | 12 | ## 1.3.0 - 2024-09-18 13 | ### Changed 14 | * `trailing_comma_in_multiline`: Add a trailing comma to multline function parameters 15 | * `MultilinePromotedPropertiesFixer`: Break promoted properties on multiple lines 16 | * `ErickSkrauch/blank_line_before_return`: Add a blank line before each return 17 | * `ErickSkrauch/line_break_after_statements`: Add a blank line after all control statements 18 | * `concat_space`: Concatenation should be spaced 19 | * `nullable_type_declaration`: Changes `DateTimeInterface|null` to `?DateTimeInterface` 20 | 21 | ## 1.2.3 - 2024-08-23 22 | ### Changed 23 | * `cast_spaces`: No space between cast and variable 24 | 25 | ## 1.2.2 - 2024-08-23 26 | ### Added 27 | * `cast_spaces`: A single space between cast and variable 28 | * `lowercase_cast`: Cast should be written in lower case 29 | * `method_chaining_indentation`: Use the same indentation when changing methods 30 | * `no_short_bool_cast`: Short cast bool using double exclamation mark should not be used 31 | * `phpdoc_align`: All items of the given PHPDoc tags must be left-aligned 32 | * `phpdoc_single_line_var_spacing`: Single line @var PHPDoc should have proper spacing 33 | * `phpdoc_var_annotation_correct_order`: Enforce the correct order for phpdoc annotations 34 | * `short_scalar_cast`: (boolean) => (bool), (integer) => (int), ... 35 | * `single_quote`: Use single quotes for simple strings 36 | * `types_spaces`: No spaces around union and intersection type operators 37 | 38 | ## 1.2.1 - 2024-02-01 39 | ### Fix 40 | * fix: Remove `fully_qualified_strict_types` again by @nickvergessen in https://github.com/nextcloud/coding-standard/pull/16 41 | 42 | ## 1.2.0 - 2024-02-01 43 | ### Added 44 | - `array_syntax`: Force short syntax for array 45 | - `list_syntax`: Same for list 46 | - ~~`fully_qualified_strict_types`: Remove namespace from classname when there is a `use` statement, and add missing backslash for global namespace~~ - Removed in 1.2.1 due to issues 47 | - `no_leading_import_slash`: Remove leading slash from `use` statement 48 | - `nullable_type_declaration_for_default_null_value`: Add missing `?` on type declaration for parameters defaulting to `null`. This will most likely be needed to avoid warnings in PHP 8.4. 49 | - `yoda_style`: forbid yoda style comparision. This replaces `null === $a` by `$a === null`. 50 | 51 | ## 1.1.1 - 2023-06-23 52 | ### Changed 53 | * feat: use php-cs-fixer/shim by @kesselb in https://github.com/nextcloud/coding-standard/pull/13 54 | 55 | ## 1.1.0 - 2023-04-13 56 | ### Changed 57 | * Order imports alphabetically by @come-nc in https://github.com/nextcloud/coding-standard/pull/10 58 | * fix(rules): Replace deprecated braces rules by @nickvergessen in https://github.com/nextcloud/coding-standard/pull/12 59 | 60 | ## 1.0.0 – 2021-11-10 61 | ### Breaking change 62 | * Update php-cs-fixer to 3.x 63 | * See https://github.com/nextcloud/coding-standard#upgrade-from-v0x-to-v10 for instructions. 64 | 65 | ## 0.5.0 – 2021-01-11 66 | ### Added 67 | - New rule: short list syntax 68 | - php7.2 support (back, for apps that support Nextclod 20 - 21) 69 | 70 | ## 0.4.0 – 2020-12-14 71 | ### Added 72 | - php8 support 73 | - New rule: binary operators should be surrounded by a single space 74 | ### Changed 75 | - php-cs-fixer updated to the latest version 76 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Christoph Wurst 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nextcloud Coding Standard 2 | 3 | Nextcloud coding standards for the [php cs fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). 4 | 5 | ## Installation 6 | 7 | Add the package to your dev dependencies 8 | 9 | ```bash 10 | composer require --dev nextcloud/coding-standard 11 | ``` 12 | 13 | and create a `.php-cs-fixer.dist.php` like 14 | 15 | ```php 16 | getFinder() 27 | ->ignoreVCSIgnored(true) 28 | ->notPath('build') 29 | ->notPath('l10n') 30 | ->notPath('src') 31 | ->notPath('vendor') 32 | ->in(__DIR__); 33 | return $config; 34 | ``` 35 | 36 | To run the fixer you first have to [install it](https://github.com/FriendsOfPhp/PHP-CS-Fixer#installation). Then you can run `php-cs-fixer fix` to apply all automated fixes. 37 | 38 | For convenience you may add it to the `scripts` section of your `composer.json`: 39 | 40 | ```json 41 | { 42 | "scripts": { 43 | "cs:check": "php-cs-fixer fix --dry-run --diff", 44 | "cs:fix": "php-cs-fixer fix" 45 | } 46 | } 47 | ``` 48 | 49 | *Note: Don't forget to exclude `.php-cs-fixer.dist.php` and `.php-cs-fixer.cache` in your build scripts.* 50 | 51 | ## Upgrade from v0.x to v1.0 52 | 53 | With v1.0 php-cs-fixer was updated from v2 to v3. You'll have to adjust your app slightly: 54 | 55 | * Rename `.php_cs.dist` to `.php-cs-fixer.dist.php` 56 | * Add `.php-cs-fixer.cache` to your ignore files 57 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nextcloud/coding-standard", 3 | "description": "Nextcloud coding standards for the php cs fixer", 4 | "type": "library", 5 | "keywords": [ 6 | "dev" 7 | ], 8 | "require": { 9 | "php": "^8.0", 10 | "php-cs-fixer/shim": "^3.17", 11 | "kubawerlos/php-cs-fixer-custom-fixers": "^3.22" 12 | }, 13 | "license": "MIT", 14 | "authors": [ 15 | { 16 | "name": "Christoph Wurst", 17 | "email": "christoph@winzerhof-wurst.at" 18 | } 19 | ], 20 | "autoload": { 21 | "psr-4": { 22 | "Nextcloud\\CodingStandard\\": "src" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Config.php: -------------------------------------------------------------------------------- 1 | setIndent("\t"); 14 | $this->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers()); 15 | } 16 | 17 | public function getRules() : array { 18 | return [ 19 | '@PSR1' => true, 20 | '@PSR2' => true, 21 | 'align_multiline_comment' => true, 22 | 'array_indentation' => true, 23 | 'array_syntax' => true, 24 | 'binary_operator_spaces' => [ 25 | 'default' => 'single_space', 26 | ], 27 | 'blank_line_after_namespace' => true, 28 | 'blank_line_after_opening_tag' => true, 29 | 'cast_spaces' => ['space' => 'none'], 30 | 'concat_space' => ['spacing' => 'one'], 31 | 'curly_braces_position' => [ 32 | 'classes_opening_brace' => 'same_line', 33 | 'functions_opening_brace' => 'same_line', 34 | ], 35 | 'elseif' => true, 36 | 'encoding' => true, 37 | 'full_opening_tag' => true, 38 | 'function_declaration' => [ 39 | 'closure_function_spacing' => 'one', 40 | ], 41 | 'indentation_type' => true, 42 | 'line_ending' => true, 43 | 'list_syntax' => true, 44 | 'lowercase_cast' => true, 45 | 'lowercase_keywords' => true, 46 | 'method_argument_space' => [ 47 | 'on_multiline' => 'ignore', 48 | ], 49 | 'method_chaining_indentation' => true, 50 | 'no_closing_tag' => true, 51 | 'no_leading_import_slash' => true, 52 | 'no_short_bool_cast' => true, 53 | 'no_spaces_after_function_name' => true, 54 | 'no_spaces_inside_parenthesis' => true, 55 | 'no_trailing_whitespace' => true, 56 | 'no_trailing_whitespace_in_comment' => true, 57 | 'no_unused_imports' => true, 58 | 'nullable_type_declaration_for_default_null_value' => true, 59 | 'nullable_type_declaration' => ['syntax' => 'question_mark'], 60 | 'operator_linebreak' => [ 61 | 'position' => 'beginning', 62 | ], 63 | 'ordered_imports' => [ 64 | 'imports_order' => ['class', 'function', 'const'], 65 | 'sort_algorithm' => 'alpha' 66 | ], 67 | 'phpdoc_align' => ['align' => 'left'], 68 | 'phpdoc_single_line_var_spacing' => true, 69 | 'phpdoc_var_annotation_correct_order' => true, 70 | 'short_scalar_cast' => true, 71 | 'single_blank_line_at_eof' => true, 72 | 'single_class_element_per_statement' => true, 73 | 'single_import_per_statement' => true, 74 | 'single_line_after_imports' => true, 75 | 'single_quote' => ['strings_containing_single_quote_chars' => false], 76 | 'switch_case_space' => true, 77 | 'trailing_comma_in_multiline' => ['elements' => ['parameters']], 78 | 'types_spaces' => ['space' => 'none', 'space_multiple_catch' => 'none'], 79 | 'type_declaration_spaces' => ['elements' => ['function', 'property']], 80 | 'visibility_required' => [ 81 | 'elements' => ['property', 'method', 'const'] 82 | ], 83 | 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], 84 | PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer::name() => true, 85 | ]; 86 | } 87 | } 88 | --------------------------------------------------------------------------------