Skip to content

Commit 3fff3b3

Browse files
committed
minor PHP-CS-Fixer#2368 clean ups (SpacePossum, localheinz)
This PR was merged into the 2.0-dev branch. Discussion ---------- clean ups Commits ------- e1868d4 Enhancement: Assert that InvalidConfigurationException is thrown for unknown configuration key 27e35fe clean ups
2 parents 4974d46 + e1868d4 commit 3fff3b3

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

src/Fixer/ClassNotation/ProtectedToPrivateFixer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens)
4646
$classClose = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpen);
4747

4848
if (!$this->skipClass($tokens, $index, $classOpen, $classClose)) {
49-
$this->fixClass($tokens, $index, $classOpen, $classClose);
49+
$this->fixClass($tokens, $classOpen, $classClose);
5050
}
5151

5252
$index = $classClose;
@@ -69,11 +69,10 @@ protected function getDescription()
6969

7070
/**
7171
* @param Tokens $tokens
72-
* @param int $classIndex
7372
* @param int $classOpenIndex
7473
* @param int $classCloseIndex
7574
*/
76-
private function fixClass(Tokens $tokens, $classIndex, $classOpenIndex, $classCloseIndex)
75+
private function fixClass(Tokens $tokens, $classOpenIndex, $classCloseIndex)
7776
{
7877
for ($index = $classOpenIndex + 1; $index < $classCloseIndex; ++$index) {
7978
if ($tokens[$index]->equals('{')) {

src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace PhpCsFixer\Fixer\Phpdoc;
1414

1515
use PhpCsFixer\AbstractFunctionReferenceFixer;
16+
use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
1617
use PhpCsFixer\DocBlock\DocBlock;
1718
use PhpCsFixer\DocBlock\Line;
1819
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
@@ -215,7 +216,6 @@ private function prepareArgumentInformation(Tokens $tokens, $start, $end)
215216
);
216217

217218
$sawName = false;
218-
$sawEq = false;
219219

220220
for ($index = $start; $index <= $end; ++$index) {
221221
$token = $tokens[$index];
@@ -232,8 +232,6 @@ private function prepareArgumentInformation(Tokens $tokens, $start, $end)
232232
}
233233

234234
if ($token->equals('=')) {
235-
$sawEq = true;
236-
237235
continue;
238236
}
239237

src/Fixer/Phpdoc/PhpdocToCommentFixer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens)
7777
continue;
7878
}
7979

80-
if ($nextToken->isGivenKind(T_VARIABLE) && $this->isValidVariable($tokens, $token, $nextIndex)) {
80+
if ($nextToken->isGivenKind(T_VARIABLE) && $this->isValidVariable($tokens, $nextIndex)) {
8181
continue;
8282
}
8383

@@ -195,12 +195,11 @@ private function isValidList(Tokens $tokens, Token $docsToken, $listIndex)
195195
* Checks variable assignments for correct docblock usage.
196196
*
197197
* @param Tokens $tokens
198-
* @param Token $docsToken docs Token
199198
* @param int $variableIndex index of variable Token
200199
*
201200
* @return bool
202201
*/
203-
private function isValidVariable(Tokens $tokens, Token $docsToken, $variableIndex)
202+
private function isValidVariable(Tokens $tokens, $variableIndex)
204203
{
205204
$nextIndex = $tokens->getNextMeaningfulToken($variableIndex);
206205

src/Test/AbstractIntegrationTestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ abstract class AbstractIntegrationTestCase extends \PHPUnit_Framework_TestCase
6565
*/
6666
protected $linter;
6767

68+
/**
69+
* @var FileRemoval
70+
*/
6871
private static $fileRemoval;
6972

7073
public static function setUpBeforeClass()

src/Tokenizer/Transformer/SquareBraceTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function process(Tokens $tokens, Token $token, $index)
6565
$this->transformIntoArraySquareBrace($tokens, $token, $index);
6666

6767
if (PHP_VERSION_ID >= 70100) {
68-
$this->transformIntoDestructuringSquareBrace($tokens, $token, $index);
68+
$this->transformIntoDestructuringSquareBrace($tokens, $token);
6969
}
7070
}
7171

@@ -83,7 +83,7 @@ private function transformIntoArraySquareBrace(Tokens $tokens, Token $token, $in
8383
$this->cacheOfArraySquareBraceCloseIndex = $endIndex;
8484
}
8585

86-
private function transformIntoDestructuringSquareBrace(Tokens $tokens, Token $token, $index)
86+
private function transformIntoDestructuringSquareBrace(Tokens $tokens, Token $token)
8787
{
8888
if (
8989
null === $this->cacheOfArraySquareBraceCloseIndex

tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,51 @@
2222
*/
2323
final class PhpdocAddMissingParamAnnotationFixerTest extends AbstractFixerTestCase
2424
{
25+
public function testConfigureRejectsUnknownConfigurationKey()
26+
{
27+
$key = 'foo';
28+
29+
$this->setExpectedException('PhpCsFixer\ConfigurationException\InvalidConfigurationException', sprintf(
30+
'"%s" is not handled by the fixer.',
31+
$key
32+
));
33+
34+
$this->fixer->configure(array(
35+
$key => 'bar',
36+
));
37+
}
38+
39+
/**
40+
* @dataProvider providerInvalidConfigurationValue
41+
*
42+
* @param mixed $value
43+
*/
44+
public function testConfigureRejectsInvalidConfigurationValue($value)
45+
{
46+
$this->setExpectedException('PhpCsFixer\ConfigurationException\InvalidConfigurationException', sprintf(
47+
'Expected boolean got "%s".',
48+
is_object($value) ? get_class($value) : gettype($value)
49+
));
50+
51+
$this->fixer->configure(array(
52+
'only_untyped' => $value,
53+
));
54+
}
55+
56+
/**
57+
* @return array
58+
*/
59+
public function providerInvalidConfigurationValue()
60+
{
61+
return array(
62+
'null' => array(null),
63+
'int' => array(1),
64+
'array' => array(array()),
65+
'float' => array(0.1),
66+
'object' => array(new \stdClass()),
67+
);
68+
}
69+
2570
/**
2671
* @param string $expected
2772
* @param null|string $input

0 commit comments

Comments
 (0)