-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[noticket] Optimization for customization (#14)
[noticket] Optimization for customization
- Loading branch information
Showing
15 changed files
with
194 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/vendor/ | ||
.php_cs.cache | ||
vendor | ||
.php_cs.cache | ||
composer.lock | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
# Usage | ||
|
||
First require the package via composer | ||
## Installation | ||
First require the package via composer: | ||
|
||
`composer require --dev k10r/codestyle` | ||
|
||
After that, decide which configuration you want to use, currenty the following configurations are supported: | ||
## Choose a version | ||
After that, decide which configuration you want to use, currently the following configurations are supported: | ||
- PHP 5.6 | ||
- PHP 7.0 | ||
- PHP 7.1 | ||
- PHP 7.2 | ||
- PHP 7.3 | ||
|
||
Add a `.php_cs.dist` to the root folder of your project with the required chosen configuration applied. A good example can be found in this project root folder. | ||
|
||
Finally add `.php_cs.cache` to project specific .gitignore file and run php-cs-fixer with the following command: `vendor/bin/php-cs-fixer.phar fix -vvv` | ||
## Implementation | ||
- Create a `.php_cs.dist` or add the one provided by the project to the root folder of your project. | ||
- Change the version to one of the listed above | ||
- Finally, add `.php_cs.cache` to project specific `.gitignore` file | ||
- If you want to apply the changes simply use: `vendor/bin/php-cs-fixer.phar fix` | ||
- Use the following command to take a look at the changes before applying them: `vendor/bin/php-cs-fixer.phar fix --dry-run` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
{ | ||
"name": "k10r/codestyle", | ||
"description": "Kellerkinder codestyle definitions for different PHP versions.", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Kellerkinder / k10r GmbH", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"K10r\\Codestyle\\": "src" | ||
} | ||
}, | ||
"bin": [ | ||
"php-cs-fixer.phar", | ||
"php-cs-fixer" | ||
] | ||
"name": "k10r/codestyle", | ||
"description": "Kellerkinder codestyle definitions for different PHP versions.", | ||
"type": "library", | ||
"license": "MIT", | ||
"keywords": [ | ||
"fixer", | ||
"php-cs-fixer", | ||
"custom-fixer", | ||
"k10r" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Kellerkinder GmbH", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"K10r\\Codestyle\\": "src/" | ||
} | ||
}, | ||
"bin": [ | ||
"php-cs-fixer.phar", | ||
"php-cs-fixer" | ||
] | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace K10r\Codestyle; | ||
|
||
use K10r\Codestyle\Fixer\AutomaticCommentsFixer; | ||
use K10r\Codestyle\Fixer\MultiToSingleLineAnnotationFixer; | ||
|
||
final class CustomFixer | ||
{ | ||
/** @return array */ | ||
public static function getCustomFixer() | ||
{ | ||
return [ | ||
new AutomaticCommentsFixer(), | ||
new MultiToSingleLineAnnotationFixer(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace K10r\Codestyle; | ||
|
||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
|
||
abstract class DefaultRules | ||
{ | ||
const RULES = [ | ||
'@PSR2' => true, | ||
'@Symfony' => true, | ||
'@DoctrineAnnotation' => true, | ||
'no_useless_else' => true, | ||
'no_useless_return' => true, | ||
'ordered_class_elements' => true, | ||
'ordered_imports' => true, | ||
'phpdoc_order' => true, | ||
'Kellerkinder/single_line_annotation' => true, | ||
'Kellerkinder/automatic_comments' => true, | ||
'phpdoc_summary' => false, | ||
'phpdoc_types_order' => true, | ||
'return_assignment' => true, | ||
'phpdoc_align' => true, | ||
'phpdoc_to_comment' => false, | ||
'yoda_style' => false, | ||
'phpdoc_var_without_name' => false, | ||
'no_multiline_whitespace_before_semicolons' => true, | ||
'no_unused_imports' => true, | ||
'no_superfluous_phpdoc_tags' => true, | ||
'concat_space' => [ | ||
'spacing' => 'one', | ||
], | ||
'blank_line_before_statement' => [ | ||
'statements' => [ | ||
'break', | ||
'continue', | ||
'do', | ||
'die', | ||
'exit', | ||
'if', | ||
'return', | ||
'switch', | ||
'try', | ||
'yield', | ||
], | ||
], | ||
'array_syntax' => [ | ||
'syntax' => 'short', | ||
], | ||
'binary_operator_spaces' => [ | ||
'operators' => [ | ||
'=>' => 'align_single_space_minimal', | ||
'=' => 'align_single_space_minimal', | ||
], | ||
], | ||
]; | ||
|
||
public static function getRules() | ||
{ | ||
return self::RULES; | ||
} | ||
|
||
/** | ||
* @param array $additionalRules | ||
* @param bool $usingCache | ||
* | ||
* @return Config | ||
*/ | ||
public static function create(Finder $finder = null, $additionalRules = [], $usingCache = true) | ||
{ | ||
$newConfig = Config::create(); | ||
|
||
if ($finder) { | ||
$newConfig->setFinder($finder); | ||
} | ||
|
||
return $newConfig->setUsingCache($usingCache) | ||
->setRules( | ||
array_merge( | ||
self::getRules(), | ||
$additionalRules | ||
) | ||
) | ||
->registerCustomFixers(CustomFixer::getCustomFixer()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...Fixers/Comment/AutomaticCommentsFixer.php → src/Fixer/AutomaticCommentsFixer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ment/MultiToSingleLineAnnotationFixer.php → ...ixer/MultiToSingleLineAnnotationFixer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.