### PHP Encoding Example (UTF-8 without BOM) Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Demonstrates the `encoding` rule, which ensures PHP files use UTF-8 encoding without a Byte Order Mark (BOM). The example shows the removal of a leading BOM. ```diff -check()) @else @endif ``` -------------------------------- ### Use Correct Casing for Native PHP Functions Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Ensures that built-in PHP functions are called using their correct, standard casing. For example, 'strlen()' should be used instead of 'STRLEN()'. ```php get()` or similar methods with the direct `request()` helper function for accessing request values. This simplifies code and promotes the use of Laravel's built-in helpers. ```php get('savedVehicleId')); + return SavedVehicle::findOrFail(request('savedVehicleId')); } } ``` -------------------------------- ### Duster with Containerized Environment Source: https://github.com/tighten/duster/blob/3.x/README.md Installs Duster's Husky hooks while specifying a containerized environment like ddev, useful when PHP is not installed locally. ```bash ./vendor/bin/duster husky-hooks --env=ddev ``` -------------------------------- ### PHP Explicit String Variable Example Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Transforms implicit variables in double-quoted strings and heredoc syntax into explicit ones using curly braces, as required by the `explicit_string_variable` rule. ```diff country !"; -$c = "I have $farm[0] chickens !"; +$a = "My name is {$name} !"; +$b = "I live in {$state->country} !"; +$c = "I have {$farm[0]} chickens !"; ``` -------------------------------- ### No empty PHPDoc blocks Source: https://github.com/tighten/duster/blob/3.x/style-guide.md This rule disallows empty PHPDoc blocks (`/** */`). It ensures that PHPDoc blocks, when present, contain meaningful documentation. ```php - app config database public resources routes tests ``` -------------------------------- ### Use correct case for standard PHP types in PHPDoc Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Ensures that standard PHP types in PHPDoc annotations use the correct casing (e.g., 'string' instead of 'STRING', 'int' instead of 'inT'). Examples cover @param and @return annotations in PHP. ```php */database/* */tests/* ``` -------------------------------- ### Custom Controller Order Configuration Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Defines a custom order for controller class elements, including traits, properties, constants, and methods, to ensure a consistent and organized structure. ```php [ 'order' => [ 'use_trait', 'property_public_static', 'property_protected_static', 'property_private_static', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'method:__invoke', 'method_public_static', 'method_protected_static', 'method_private_static', 'method:index', 'method:create', 'method:store', 'method:show', 'method:edit', 'method:update', 'method:destroy', 'method_public', 'method_protected', 'method_private', 'magic', ], ] ``` -------------------------------- ### Exclude Config Directory from UseConfigOverEnv Rule Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Configuration to exclude the `/config` directory from the Tighten.PHP.UseConfigOverEnv rule, allowing the use of `env()` within configuration files. ```xml /config/* ``` -------------------------------- ### Fix PHPDoc @link and @tutorial tags Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Ensures that PHPDoc @link and @tutorial tags are correctly formatted, typically by changing curly braces to square brackets. This rule applies to PHP code. ```php /public/index.php ``` -------------------------------- ### PHP Blank Line After Opening Tag Fix Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Ensures that there is no code on the same line as the opening PHP tag (` 'one', ] ``` -------------------------------- ### PHP Blank Line Before Statement Fix Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Adds an empty line before specific configured statements like `continue` and `return`. This enhances the readability of control flow within code blocks. ```diff foreach ($foo as $bar) { if ($bar->isTired()) { $bar->sleep(); + continue; } } ``` ```diff if (true) { $foo = $bar; + return; } ``` -------------------------------- ### Correct Casing for PHP Magic Methods Source: https://github.com/tighten/duster/blob/3.x/style-guide.md This rule enforces the correct lowercase casing for magic method definitions and calls in PHP, such as '__sleep()' and '__invoke()'. ```php __INVOKE(1); +$foo->__invoke(1); ``` -------------------------------- ### Configure Forbidden Functions Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Defines a list of forbidden functions, including `compact`, `dd`, `dump`, `var_dump`, and `ray`, to enforce cleaner and more controlled debugging practices. ```xml ``` -------------------------------- ### No spaces after function/method name in calls Source: https://github.com/tighten/duster/blob/3.x/style-guide.md This rule mandates that there should be no space between a function or method name and its opening parenthesis `(` when making a call. This is a common convention for function calls. ```php 'lower', ] ``` -------------------------------- ### Function type hint spacing Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Enforces a single space between a function's argument and its type hint. This improves the readability of function signatures, especially when type hinting is used. ```php with()` method. It aims to simplify view data passing in Laravel applications. ```php with('testing', '1212'); + return view('test.view', ['testing' => '1212']); } } ``` -------------------------------- ### PHP: Remove Unused Imports Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Removes `use` statements that are not actually used in the PHP file. This helps to keep the import section clean and reduces potential confusion. ```php true, 'single_item_single_line' => true, 'single_line' => true, ] ``` -------------------------------- ### Fix Switch Case Spacing Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Standardizes spacing around switch case statements. This rule ensures consistent formatting for 'case' and 'default' keywords within switch blocks. ```php [ 0 => 'const', 1 => 'property', ], ] ``` ```diff [ 'method' => 'one', ], ] ``` -------------------------------- ### Remove name from @var and @type annotations for class properties Source: https://github.com/tighten/duster/blob/3.x/style-guide.md This rule enforces that @var and @type annotations for class properties should not include the property name. Examples are provided for PHP class properties using both @var and @type. ```php final class Foo { /** - * @var int $bar + * @var int */ public $bar; /** - * @type $baz float + * @type float */ public $baz; } ``` -------------------------------- ### Enforce Visibility Declaration Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Mandates that all properties and methods must have explicit visibility declared (public, protected, private). Abstract and final declarations must precede visibility, while static must follow it. ```php [ 0 => 'hash', ], ] ``` ```diff [ 'use_trait', 'property_public_static', 'property_protected_static', 'property_private_static', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'method:__invoke', 'method_public_static', 'method_protected_static', 'method_private_static', 'method_public', 'method_protected', 'method_private', 'magic', ], ] ``` -------------------------------- ### Update Dependencies with Composer Source: https://github.com/tighten/duster/blob/3.x/CONTRIBUTING.md Updates project dependencies to their latest versions using Composer. Includes commands for both production and development environments. ```bash # Production composer require friendsofphp/php-cs-fixer laravel-zero/framework laravel/pint squizlabs/php_codesniffer tightenco/tlint --dev # Development COMPOSER=composer-dev.json composer require friendsofphp/php-cs-fixer laravel-zero/framework laravel/pint squizlabs/php_codesniffer tightenco/tlint --dev ``` -------------------------------- ### Running Custom Scripts with Duster Source: https://context7.com/tighten/duster/llms.txt Execute custom scripts defined in `duster.json` using the `lint` or `fix` commands. You can run all scripts, specific scripts using the `--using` flag, or combine built-in tools with custom scripts. ```bash # Runs tlint, phpcs, php-cs-fixer, pint, AND phpstan, pest ./vendor/bin/duster lint # Run only specific custom script ./vendor/bin/duster lint --using="phpstan" # Combine built-in tools with custom scripts ./vendor/bin/duster lint --using="pint,phpstan" ``` -------------------------------- ### Whitespace After Comma in Array Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Requires a whitespace character after each comma within array declarations. This ensures consistent formatting for array elements. ```php ` inequality operator with the `!=` operator. This standardizes the inequality comparison syntax across the codebase. ```diff $c; +$a = $b != $c; ``` -------------------------------- ### Configure Brace Placement in PHP Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Defines the placement of opening braces for control structures, functions, anonymous functions, classes, and anonymous classes. It also includes settings for single-line anonymous classes and functions. ```php [ 'control_structures_opening_brace' => 'same_line', 'functions_opening_brace' => 'next_line_unless_newline_at_signature_end', 'anonymous_functions_opening_brace' => 'same_line', 'classes_opening_brace' => 'next_line_unless_newline_at_signature_end', 'anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end', 'allow_single_line_empty_anonymous_classes' => true, 'allow_single_line_anonymous_functions' => false, ] ``` -------------------------------- ### Pint Configuration Source: https://context7.com/tighten/duster/llms.txt Customize Laravel Pint formatting rules by creating a `pint.json` file. You can set the preset, define specific rules for code style, and specify files or directories to exclude from formatting. ```json { "preset": "laravel", "rules": { "blank_line_between_import_groups": true, "concat_space": { "spacing": "one" }, "ordered_imports": { "sort_algorithm": "alpha", "imports_order": ["const", "class", "function"] }, "php_unit_test_annotation": { "style": "annotation" }, "global_namespace_import": { "import_classes": true, "import_constants": true, "import_functions": true } }, "exclude": [ "tests/Fixtures" ] } ``` -------------------------------- ### Duster CLI: Lint Commands Source: https://context7.com/tighten/duster/llms.txt Analyzes your codebase for style violations without modifying files. Supports linting all files, dirty files, files changed since a specific branch, specific paths, and using only selected tools. Available tools include tlint, phpcs, php-cs-fixer, and pint. ```bash # Lint all files in the project ./vendor/bin/duster lint # Lint only files with uncommitted Git changes ./vendor/bin/duster lint --dirty # Lint only files changed since branching from main ./vendor/bin/duster lint --diff=main # Lint specific paths ./vendor/bin/duster lint app/Http/Controllers app/Models # Lint using only specific tools (comma-separated) ./vendor/bin/duster lint --using="tlint,pint" ``` -------------------------------- ### PHPDoc tag renaming Source: https://github.com/tighten/duster/blob/3.x/style-guide.md Renames specific PHPDoc tags to their preferred or standardized equivalents. This ensures consistency in documentation comments across the project. ```php