Skip to content

Commit 9c427fb

Browse files
committed
minor #4521 Remove superfluous leading backslash, closes 4520 (ktomk)
This PR was squashed before being merged into the 2.15 branch (closes #4521). Discussion ---------- Remove superfluous leading backslash, closes 4520 In string context, there is no need to prefix the exception class-name of the exception with any backslashes as these are always in the global name-space. Looks like the prefix is only useful for verbatim class names which is not addressed in this issue (see #4068 for more details on verbatim class- names and also a generic resolution suggestion for many fixers). Additionally minor changes regarding standard (Phpstorm) inspections. Closes: #4520 Related: #4068 Commits ------- 7eb6087 Remove superfluous leading backslash, closes 4520
2 parents 4515e65 + 7eb6087 commit 9c427fb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,10 @@ private function fixPhpUnitClass(Tokens $tokens, $startIndex, $endIndex)
245245
$tokens[$docBlockIndex] = new Token([T_DOC_COMMENT, $doc->getContent()]);
246246
$tokens->insertAt($braceIndex + 1, $newMethods);
247247

248-
$tokens[$braceIndex + $newMethods->getSize() + 1] = new Token([
248+
$whitespaceIndex = $braceIndex + $newMethods->getSize() + 1;
249+
$tokens[$whitespaceIndex] = new Token([
249250
T_WHITESPACE,
250-
$this->whitespacesConfig->getLineEnding().$tokens[$braceIndex + $newMethods->getSize() + 1]->getContent(),
251+
$this->whitespacesConfig->getLineEnding().$tokens[$whitespaceIndex]->getContent(),
251252
]);
252253

253254
$i = $docBlockIndex;
@@ -275,10 +276,10 @@ private function extractContentFromAnnotation(Annotation $annotation)
275276
private function annotationsToParamList(array $annotations)
276277
{
277278
$params = [];
278-
$exceptionClass = '\\'.ltrim($annotations['expectedException'], '\\');
279+
$exceptionClass = ltrim($annotations['expectedException'], '\\');
279280

280281
if ($this->configuration['use_class_const']) {
281-
$params[] = $exceptionClass.'::class';
282+
$params[] = "\\{$exceptionClass}::class";
282283
} else {
283284
$params[] = "'{$exceptionClass}'";
284285
}

tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ final class MyTest extends \PHPUnit_Framework_TestCase
221221
*/
222222
public function testFnc()
223223
{
224-
$this->setExpectedException(\'\FooException\');
224+
$this->setExpectedException(\'FooException\');
225225
226226
aaa();
227227
}

0 commit comments

Comments
 (0)