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