Skip to content

Commit 3e2e7e6

Browse files
authored
Merge pull request #126 from kubawerlos/useless-sprintf-fix
NoUselessSprintfFixer - fix with leading slash
2 parents dc6ebd9 + d16717f commit 3e2e7e6

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[![Build status](https://img.shields.io/travis/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://travis-ci.org/kubawerlos/php-cs-fixer-custom-fixers)
1010
[![Code coverage](https://img.shields.io/coveralls/github/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://coveralls.io/github/kubawerlos/php-cs-fixer-custom-fixers?branch=master)
11-
![Tests](https://img.shields.io/badge/tests-1051-brightgreen.svg)
11+
![Tests](https://img.shields.io/badge/tests-1052-brightgreen.svg)
1212
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/kubawerlos/php-cs-fixer-custom-fixers/master)](https://stryker-mutator.github.io)
1313

1414
A set of custom fixers for [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).

src/Fixer/NoUselessSprintfFixer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
5656
continue;
5757
}
5858

59+
$prevIndex = $tokens->getPrevMeaningfulToken($index);
60+
if ($tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) {
61+
$tokens->clearAt($prevIndex);
62+
}
5963
$tokens->clearAt($index);
6064
$tokens->clearAt($openParenthesis);
6165
if ($tokens[$openParenthesis + 1]->isWhitespace()) {

tests/Fixer/NoUselessSprintfFixerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public function provideFixCases(): iterable
5050
'<?php sprintf($foo);',
5151
];
5252

53+
yield [
54+
'<?php $foo;',
55+
'<?php \sprintf($foo);',
56+
];
57+
5358
yield [
5459
'<?php $foo;',
5560
'<?php SPRINTF($foo);',

0 commit comments

Comments
 (0)