### Install CodeIgniter Coding Standard Source: https://context7.com/codeigniter/coding-standard/llms.txt Install the library as a development dependency using Composer. This is the recommended approach for most projects. ```bash composer require --dev codeigniter/coding-standard ``` ```bash composer require codeigniter/coding-standard ``` -------------------------------- ### Minimal Project Setup with Factory::create() Source: https://context7.com/codeigniter/coding-standard/llms.txt Configure PHP CS Fixer for application projects using the CodeIgniter4 ruleset without license headers. This is the simplest setup for automated style enforcement. ```php forProjects(); ``` ```bash # Run the fixer in dry-run mode to preview changes vendor/bin/php-cs-fixer fix --dry-run --verbose --diff # Apply fixes vendor/bin/php-cs-fixer fix --verbose ``` -------------------------------- ### Setup PHP CS Fixer Configuration Source: https://github.com/codeigniter/coding-standard/blob/1.x/README.md Create a .php-cs-fixer.dist.php file at the root of your project to configure the CodeIgniter Coding Standard. ```php forProjects(); ``` -------------------------------- ### Library Setup with License Header Source: https://context7.com/codeigniter/coding-standard/llms.txt Configure PHP CS Fixer for libraries, including a license header in each fixed PHP file. Specify the library name, author, and optional contact email and copyright year. ```php forLibrary( 'My Library Name', // library name 'My Organization', // author / organization 'contact@example.com', // email (optional) 2021, // starting copyright year (optional) ); // Expected header injected at the top of every PHP file: // // /** // * This file is part of My Library Name. // * // * (c) 2021 My Organization // * // * For the full copyright and license information, please view // * the LICENSE file that was distributed with this source code. // */ ``` -------------------------------- ### Add License Headers to PHP Files Source: https://github.com/codeigniter/coding-standard/blob/1.x/README.md Configure the coding standard to automatically add license headers to your PHP files. Provide library name, author name, email, and starting year. ```php forLibrary( 'CodeIgniter 4 framework', 'CodeIgniter Foundation', 'admin@codeigniter.com', 2021, ); ``` -------------------------------- ### Configure Overriding Rules and Options Source: https://github.com/codeigniter/coding-standard/blob/1.x/README.md Modify the PhpCsFixer\Config instance by providing overriding rules or options. This example disables caching. ```php false, ])->forProjects(); ``` -------------------------------- ### Configure PHP CS Fixer with Factory::create() Source: https://context7.com/codeigniter/coding-standard/llms.txt Use this snippet to configure PHP CS Fixer with custom Finder and options. It allows overriding default rules and specifying cache settings. ```php files() ->in([__DIR__ . '/src', __DIR__ . '/tests']) ->exclude(['build', 'vendor']) ->append([__FILE__]); // also fix this config file itself $overrides = [ 'declare_strict_types' => true, ]; $options = [ 'finder' => $finder, 'cacheFile' => 'build/.php-cs-fixer.cache', 'usingCache' => true, // default: true ]; return Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary( 'CodeIgniter 4 framework', 'CodeIgniter Foundation', 'admin@codeigniter.com', 2021, ); ``` -------------------------------- ### Run PHPUnit Test Suite Source: https://context7.com/codeigniter/coding-standard/llms.txt Command to execute the PHPUnit test suite for the CodeIgniter Coding Standard. ```bash # Run the test suite vendor/bin/phpunit --testdox # Expected output (abridged): # CodeIgniter4 (CodeIgniter\CodingStandard\Tests\CodeIgniter4) # ✔ Rules are sorted alphabetically # ✔ All configured rules exist in the installed php-cs-fixer version # ✔ Deprecated rules are not used ``` -------------------------------- ### Overriding Rules with Factory::create() Source: https://context7.com/codeigniter/coding-standard/llms.txt Customize the CodeIgniter4 ruleset by providing an array of overrides to `Factory::create()`. This allows modification or disabling of specific rules without forking the ruleset class. ```php true, // Disable the rule that rewrites rand() to mt_rand() 'random_api_migration' => false, // Change binary operator alignment to simple single-space 'binary_operator_spaces' => ['default' => 'single_space'], ]; return Factory::create(new CodeIgniter4(), $overrides)->forProjects(); ``` -------------------------------- ### Inspect CodeIgniter4 Ruleset Source: https://context7.com/codeigniter/coding-standard/llms.txt This snippet demonstrates how to programmatically inspect the ruleset provided by the CodeIgniter4 class. It retrieves the ruleset name, the full array of fixer rules, the required PHP version, and the status of risky rules. ```php getName(); // => "CodeIgniter4 Coding Standards" // Get the full array of fixer rules (key => true|false|array) $rules = $ruleset->getRules(); var_dump(isset($rules['array_syntax'])); // bool(true) var_dump($rules['array_syntax']); // array(1) { ["syntax"] => string(5) "short" } var_dump($rules['declare_strict_types']); // bool(false) — disabled by default // Minimum PHP version required (integer, e.g. 80100 = PHP 8.1.0) echo $ruleset->getRequiredPHPVersion(); // => 80100 // Whether risky fixers are automatically allowed var_dump($ruleset->willAutoActivateIsRiskyAllowed()); // => bool(true) ``` -------------------------------- ### PHPUnit Test for CodeIgniter4 Ruleset Source: https://context7.com/codeigniter/coding-standard/llms.txt This PHPUnit test class validates the CodeIgniter4 ruleset. It extends AbstractRulesetTestCase and automatically resolves the ruleset class to be tested. ```php $ruleset */ $ruleset = preg_replace( '/^(CodeIgniter\\CodingStandard)\\Tests(\\\\S+)Test/', '$1$2', self::class, ); return new $ruleset(); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.