Skip to content

Commit

Permalink
Fix/symfony risky rule factory (#39)
Browse files Browse the repository at this point in the history
* Fix CS

* Fix ->symfony(true) behavior in RuleSetFactory
  • Loading branch information
PedroTroller authored Aug 7, 2018
1 parent c28e9e4 commit ba7194f
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ version: 2

composer_with_lowest_dependencies: &composer_with_lowest_dependencies
run: |
composer self-update
composer global require hirak/prestissimo --no-progress
composer update --prefer-lowest --prefer-stable
composer: &composer
run: |
composer self-update
composer global require hirak/prestissimo --no-progress
composer update
Expand Down
9 changes: 8 additions & 1 deletion spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ function it_adds_a_symfony_set()

function it_adds_a_symfony_strict_set()
{
$this->symfony(true)->getRules()->shouldReturn(['@Symfony:risky' => true]);
$this->symfony()->getRules()->shouldReturn([
'@Symfony' => true,
]);

$this->symfony(true)->getRules()->shouldReturn([
'@Symfony' => true,
'@Symfony:risky' => true,
]);
}

function it_adds_a_php_version_support()
Expand Down
6 changes: 3 additions & 3 deletions src/PedroTroller/CS/Fixer/AbstractFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function hasUseStatements(Tokens $tokens, $fqcn)
*/
protected function getUseStatements(Tokens $tokens, $fqcn)
{
if (false === is_array($fqcn)) {
if (false === \is_array($fqcn)) {
$fqcn = explode('\\', $fqcn);
}
$sequence = [[T_USE]];
Expand All @@ -111,7 +111,7 @@ protected function getUseStatements(Tokens $tokens, $fqcn)
[[T_STRING, $component], [T_NS_SEPARATOR]]
);
}
$sequence[count($sequence) - 1] = ';';
$sequence[\count($sequence) - 1] = ';';

return $tokens->findSequence($sequence);
}
Expand All @@ -123,7 +123,7 @@ protected function getUseStatements(Tokens $tokens, $fqcn)
*/
protected function extendsClass(Tokens $tokens, $fqcn)
{
if (false === is_array($fqcn)) {
if (false === \is_array($fqcn)) {
$fqcn = explode('\\', $fqcn);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens)
}

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

if ($sorted !== $elements) {
$this->sortTokens($tokens, $i, $endIndex, $sorted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function sortElements(array $elements)
continue;
}

if (in_array($element['methodName'], $methods)) {
if (\in_array($element['methodName'], $methods)) {
$portions[array_search($element['methodName'], $methods)] = $element;
unset($elements[$index]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens)
continue;
}

if (in_array($token->getContent(), $this->configuration['functions'])) {
if (\in_array($token->getContent(), $this->configuration['functions'])) {
$end = $this->analyze($tokens)->getEndOfTheLine($index);
$tokens[$end] = new Token([T_WHITESPACE, sprintf(' // %s%s', $this->configuration['comment'], $tokens[$end]->getContent())]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ private function ensureNumberOfBreaks($whitespace)
{
$parts = explode("\n", $whitespace);

while (3 < count($parts)) {
while (3 < \count($parts)) {
array_shift($parts);
}

while (3 > count($parts)) {
while (3 > \count($parts)) {
array_unshift($parts, '');
}

Expand Down
2 changes: 1 addition & 1 deletion src/PedroTroller/CS/Fixer/Comment/UselessCommentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private function getUselessComments($index, Tokens $tokens)

if (null === $return) {
$useless[] = '/^@return null$/';
} elseif (false === is_array($return)) {
} elseif (false === \is_array($return)) {
$useless[] = sprintf('/^@return +%s$/', str_replace('\\', '\\\\', $return));
} else {
$return = array_map(function ($value) { return null === $value ? 'null' : $value; }, $return);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getPriority()
protected function sortElements(array $elements)
{
$portions = [];
$numberOfElements = count($elements);
$numberOfElements = \count($elements);

foreach ($elements as $index => $element) {
if ('method' !== $element['type']) {
Expand Down
8 changes: 7 additions & 1 deletion src/PedroTroller/CS/Fixer/RuleSetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ public function psr4()
*/
public function symfony($risky = false)
{
$rules = ['@Symfony' => true];

if ($risky) {
$rules['@Symfony:risky'] = true;
}

return self::create(array_merge(
$this->rules,
[($risky ? '@Symfony:risky' : '@Symfony') => true]
$rules
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/PedroTroller/CS/Fixer/TokensAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(Tokens $tokens)

public function __call($name, $arguments)
{
return call_user_func_array([$this->analyzer, $name], $arguments);
return \call_user_func_array([$this->analyzer, $name], $arguments);
}

/*
Expand Down

0 comments on commit ba7194f

Please sign in to comment.