|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * Derafu: Foundation - Base for Derafu's Projects. |
| 7 | + * |
| 8 | + * Copyright (c) 2025 Esteban De La Fuente Rubio / Derafu <https://www.derafu.org> |
| 9 | + * Licensed under the MIT License. |
| 10 | + * See LICENSE file for more details. |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * Configuration file for PHP CS Fixer. |
| 15 | + */ |
| 16 | + |
| 17 | +use PhpCsFixer\Config; |
| 18 | +use PhpCsFixer\Finder; |
| 19 | + |
| 20 | +$dir = __DIR__; |
| 21 | + |
| 22 | +$finder = Finder::create() |
| 23 | + ->in($dir) |
| 24 | + ->exclude('var') |
| 25 | +; |
| 26 | + |
| 27 | +return (new Config()) |
| 28 | + // Allow risky rules that may change code logic. |
| 29 | + ->setRiskyAllowed(true) |
| 30 | + // Based on PSR-12, the latest style recommendation. |
| 31 | + ->setRules([ |
| 32 | + '@PSR12' => true, |
| 33 | + // Add "declare(strict_types=1);" to files. |
| 34 | + // This adds it like <?php declare(strict_types=1); however, it is |
| 35 | + // recommended to edit or add it manually on separate lines. |
| 36 | + 'declare_strict_types' => true, |
| 37 | + // Indent using spaces. |
| 38 | + 'indentation_type' => true, |
| 39 | + // Sort "use" statements alphabetically. |
| 40 | + 'ordered_imports' => [ |
| 41 | + 'sort_algorithm' => 'alpha', |
| 42 | + ], |
| 43 | + // Remove unused imports. |
| 44 | + 'no_unused_imports' => true, |
| 45 | + // One import per statement. |
| 46 | + 'single_import_per_statement' => true, |
| 47 | + // Convert arrays to short syntax "[]". |
| 48 | + 'array_syntax' => [ |
| 49 | + 'syntax' => 'short', |
| 50 | + ], |
| 51 | + // Add trailing commas in multi-line arrays. |
| 52 | + 'trailing_comma_in_multiline' => true, |
| 53 | + // Separate constants and properties. |
| 54 | + 'class_attributes_separation' => [ |
| 55 | + 'elements' => [ |
| 56 | + 'const' => 'one', |
| 57 | + 'property' => 'one', |
| 58 | + 'method' => 'one', |
| 59 | + ], |
| 60 | + ], |
| 61 | + // Replace strpos with a boolean-returning function. |
| 62 | + // Example: use str_contains(). |
| 63 | + 'modernize_strpos' => true, |
| 64 | + // Convert anonymous functions to arrow functions. |
| 65 | + 'use_arrow_functions' => true, |
| 66 | + // Use PHPUnit constructors instead of factory methods. |
| 67 | + 'php_unit_construct' => true, |
| 68 | + // Use stricter assertions in PHPUnit. |
| 69 | + // Example: use assertSame() instead of assertEquals(). |
| 70 | + 'php_unit_strict' => true, |
| 71 | + ]) |
| 72 | + ->setLineEnding("\n") |
| 73 | + ->setCacheFile($dir . '/var/cache/php-cs-fixer.cache') |
| 74 | + ->setFinder($finder) |
| 75 | +; |
0 commit comments