|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tarantool\Queue; |
| 4 | + |
| 5 | +use PhpCsFixer\Config; |
| 6 | +use PhpCsFixer\Fixer\ConstantNotation\NativeConstantInvocationFixer; |
| 7 | +use PhpCsFixer\Fixer\FixerInterface; |
| 8 | +use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer; |
| 9 | +use PhpCsFixer\Tokenizer\Tokens; |
| 10 | + |
| 11 | +final class FilterableFixer implements FixerInterface |
| 12 | +{ |
| 13 | + private $fixer; |
| 14 | + private $pathRegex; |
| 15 | + |
| 16 | + public function __construct(FixerInterface $fixer, string $pathRegex) |
| 17 | + { |
| 18 | + $this->fixer = $fixer; |
| 19 | + $this->pathRegex = $pathRegex; |
| 20 | + } |
| 21 | + |
| 22 | + public function isCandidate(Tokens $tokens) : bool |
| 23 | + { |
| 24 | + return $this->fixer->isCandidate($tokens); |
| 25 | + } |
| 26 | + |
| 27 | + public function isRisky() : bool |
| 28 | + { |
| 29 | + return $this->fixer->isRisky(); |
| 30 | + } |
| 31 | + |
| 32 | + public function fix(\SplFileInfo $file, Tokens $tokens) : void |
| 33 | + { |
| 34 | + $this->fixer->fix($file, $tokens); |
| 35 | + } |
| 36 | + |
| 37 | + public function getName() : string |
| 38 | + { |
| 39 | + return (new \ReflectionClass($this))->getShortName().'/'.$this->fixer->getName(); |
| 40 | + } |
| 41 | + |
| 42 | + public function getPriority() : int |
| 43 | + { |
| 44 | + return $this->fixer->getPriority(); |
| 45 | + } |
| 46 | + |
| 47 | + public function supports(\SplFileInfo $file) : bool |
| 48 | + { |
| 49 | + if (1 !== preg_match($this->pathRegex, $file->getRealPath())) { |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + return $this->fixer->supports($file); |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | +$header = <<<EOF |
| 58 | +This file is part of the Tarantool Queue package. |
| 59 | +
|
| 60 | +(c) Eugene Leonovich <gen.work@gmail.com> |
| 61 | +
|
| 62 | +For the full copyright and license information, please view the LICENSE |
| 63 | +file that was distributed with this source code. |
| 64 | +EOF; |
| 65 | + |
| 66 | +return Config::create() |
| 67 | + ->setUsingCache(false) |
| 68 | + ->setRiskyAllowed(true) |
| 69 | + ->registerCustomFixers([ |
| 70 | + new FilterableFixer(new NativeConstantInvocationFixer(), '/\bsrc\b/'), |
| 71 | + new FilterableFixer(new NativeFunctionInvocationFixer(), '/\bsrc\b/'), |
| 72 | + ]) |
| 73 | + ->setRules([ |
| 74 | + '@Symfony' => true, |
| 75 | + '@Symfony:risky' => true, |
| 76 | + 'array_syntax' => ['syntax' => 'short'], |
| 77 | + 'binary_operator_spaces' => ['operators' => ['=' => null, '=>' => null]], |
| 78 | + 'native_constant_invocation' => false, |
| 79 | + 'native_function_invocation' => false, |
| 80 | + 'FilterableFixer/native_constant_invocation' => true, |
| 81 | + 'FilterableFixer/native_function_invocation' => true, |
| 82 | + 'no_useless_else' => true, |
| 83 | + 'no_useless_return' => true, |
| 84 | + 'ordered_imports' => true, |
| 85 | + 'phpdoc_order' => true, |
| 86 | + 'phpdoc_align' => false, |
| 87 | + 'return_type_declaration' => ['space_before' => 'one'], |
| 88 | + 'strict_comparison' => true, |
| 89 | + 'header_comment' => [ |
| 90 | + 'header' => $header, |
| 91 | + 'location' => 'after_declare_strict', |
| 92 | + 'separate' => 'both', |
| 93 | + ], |
| 94 | + ]) |
| 95 | +; |
0 commit comments