Skip to content

Commit

Permalink
(chore): php cs fixer use config, update docs, run cs fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
FreakyWizard committed Nov 14, 2024
1 parent 3bdf888 commit c120d13
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 60 deletions.
56 changes: 1 addition & 55 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

# PHP CS Fixer can be run by using the composer script `composer format`
Expand All @@ -18,57 +17,4 @@
->exclude('build')
;

return (new Config)
->setFinder($finder)
->setRules([
'@PSR2' => true,
'indentation_type' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha',
],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'logical_operators' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'phpdoc_var_without_name' => true,
'phpdoc_single_line_var_spacing' => true,
'unary_operator_spaces' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'no_superfluous_elseif' => true,
'single_blank_line_before_namespace' => true,
'blank_line_after_opening_tag' => true,
'no_blank_lines_after_phpdoc' => true,
'phpdoc_separation' => true,
'method_chaining_indentation' => true,
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => null,
'|' => 'no_space',
],
],
'return_type_declaration' => [
'space_before' => 'none',
],
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'full_opening_tag' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
'identical' => true,
'less_and_greater' => true,
],
'declare_strict_types' => true,
])
->setLineEnding("\n")
->setRiskyAllowed(true);
return \Yard\PhpCsFixerRules\Config::create($finder);
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ To install this package using Composer, follow these steps:

## Usage

Simple example:
```php
<?php

Expand All @@ -45,10 +46,34 @@ $finder = Finder::create()
->exclude('build')
;

return \Yard\PhpCsFixerRules\Config::setFinder($finder)
->mergeRules([ // allows you to add new rules or override rules from default
'declare_strict_types' => false,
return \Yard\PhpCsFixerRules\Config::create($finder);
```

More complex:
```php
<?php

use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__)
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
->exclude('public')
->exclude('node_modules')
->exclude('build')
;

return \Yard\PhpCsFixerRules\Config::create($finder)
->mergeRules([
'yoda_style' => [
'equal' => false,
],
])
->setRiskyAllowed(false) // override and disable risky setting for old projects
->get();
->removeRule('declare_strict_types')
->removeRules(['no_unused_imports', 'trailing_comma_in_multiline'])
->setRiskyAllowed(false); // disable this for old sites!
```

2 changes: 2 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<?php

declare(strict_types=1);

0 comments on commit c120d13

Please sign in to comment.