Skip to content

Commit ba7194f

Browse files
authored
Fix/symfony risky rule factory (#39)
* Fix CS * Fix ->symfony(true) behavior in RuleSetFactory
1 parent c28e9e4 commit ba7194f

File tree

11 files changed

+26
-15
lines changed

11 files changed

+26
-15
lines changed

.circleci/config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ version: 2
33

44
composer_with_lowest_dependencies: &composer_with_lowest_dependencies
55
run: |
6-
composer self-update
76
composer global require hirak/prestissimo --no-progress
87
composer update --prefer-lowest --prefer-stable
98
109
composer: &composer
1110
run: |
12-
composer self-update
1311
composer global require hirak/prestissimo --no-progress
1412
composer update
1513

spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ function it_adds_a_symfony_set()
4040

4141
function it_adds_a_symfony_strict_set()
4242
{
43-
$this->symfony(true)->getRules()->shouldReturn(['@Symfony:risky' => true]);
43+
$this->symfony()->getRules()->shouldReturn([
44+
'@Symfony' => true,
45+
]);
46+
47+
$this->symfony(true)->getRules()->shouldReturn([
48+
'@Symfony' => true,
49+
'@Symfony:risky' => true,
50+
]);
4451
}
4552

4653
function it_adds_a_php_version_support()

src/PedroTroller/CS/Fixer/AbstractFixer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function hasUseStatements(Tokens $tokens, $fqcn)
101101
*/
102102
protected function getUseStatements(Tokens $tokens, $fqcn)
103103
{
104-
if (false === is_array($fqcn)) {
104+
if (false === \is_array($fqcn)) {
105105
$fqcn = explode('\\', $fqcn);
106106
}
107107
$sequence = [[T_USE]];
@@ -111,7 +111,7 @@ protected function getUseStatements(Tokens $tokens, $fqcn)
111111
[[T_STRING, $component], [T_NS_SEPARATOR]]
112112
);
113113
}
114-
$sequence[count($sequence) - 1] = ';';
114+
$sequence[\count($sequence) - 1] = ';';
115115

116116
return $tokens->findSequence($sequence);
117117
}
@@ -123,7 +123,7 @@ protected function getUseStatements(Tokens $tokens, $fqcn)
123123
*/
124124
protected function extendsClass(Tokens $tokens, $fqcn)
125125
{
126-
if (false === is_array($fqcn)) {
126+
if (false === \is_array($fqcn)) {
127127
$fqcn = explode('\\', $fqcn);
128128
}
129129

src/PedroTroller/CS/Fixer/AbstractOrderedClassElementsFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens)
2626
}
2727

2828
$sorted = $this->sortElements($elements);
29-
$endIndex = $elements[count($elements) - 1]['end'];
29+
$endIndex = $elements[\count($elements) - 1]['end'];
3030

3131
if ($sorted !== $elements) {
3232
$this->sortTokens($tokens, $i, $endIndex, $sorted);

src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function sortElements(array $elements)
133133
continue;
134134
}
135135

136-
if (in_array($element['methodName'], $methods)) {
136+
if (\in_array($element['methodName'], $methods)) {
137137
$portions[array_search($element['methodName'], $methods)] = $element;
138138
unset($elements[$index]);
139139
}

src/PedroTroller/CS/Fixer/CodingStyle/ForbiddenFunctionsFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens)
7878
continue;
7979
}
8080

81-
if (in_array($token->getContent(), $this->configuration['functions'])) {
81+
if (\in_array($token->getContent(), $this->configuration['functions'])) {
8282
$end = $this->analyze($tokens)->getEndOfTheLine($index);
8383
$tokens[$end] = new Token([T_WHITESPACE, sprintf(' // %s%s', $this->configuration['comment'], $tokens[$end]->getContent())]);
8484
}

src/PedroTroller/CS/Fixer/CodingStyle/LineBreakBetweenStatementsFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ private function ensureNumberOfBreaks($whitespace)
104104
{
105105
$parts = explode("\n", $whitespace);
106106

107-
while (3 < count($parts)) {
107+
while (3 < \count($parts)) {
108108
array_shift($parts);
109109
}
110110

111-
while (3 > count($parts)) {
111+
while (3 > \count($parts)) {
112112
array_unshift($parts, '');
113113
}
114114

src/PedroTroller/CS/Fixer/Comment/UselessCommentFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private function getUselessComments($index, Tokens $tokens)
187187

188188
if (null === $return) {
189189
$useless[] = '/^@return null$/';
190-
} elseif (false === is_array($return)) {
190+
} elseif (false === \is_array($return)) {
191191
$useless[] = sprintf('/^@return +%s$/', str_replace('\\', '\\\\', $return));
192192
} else {
193193
$return = array_map(function ($value) { return null === $value ? 'null' : $value; }, $return);

src/PedroTroller/CS/Fixer/Phpspec/OrderedSpecElementsFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getPriority()
8080
protected function sortElements(array $elements)
8181
{
8282
$portions = [];
83-
$numberOfElements = count($elements);
83+
$numberOfElements = \count($elements);
8484

8585
foreach ($elements as $index => $element) {
8686
if ('method' !== $element['type']) {

src/PedroTroller/CS/Fixer/RuleSetFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,15 @@ public function psr4()
8787
*/
8888
public function symfony($risky = false)
8989
{
90+
$rules = ['@Symfony' => true];
91+
92+
if ($risky) {
93+
$rules['@Symfony:risky'] = true;
94+
}
95+
9096
return self::create(array_merge(
9197
$this->rules,
92-
[($risky ? '@Symfony:risky' : '@Symfony') => true]
98+
$rules
9399
));
94100
}
95101

0 commit comments

Comments
 (0)