Skip to content

Commit

Permalink
DX: minor typing and validation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Mar 1, 2021
1 parent a8feb63 commit c39900d
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 34 deletions.
6 changes: 6 additions & 0 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace PhpCsFixer\RuleSet;

use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;

/**
* Set of rules to be used by fixer.
*
Expand Down Expand Up @@ -41,6 +43,10 @@ public function __construct(array $set = [])
if (\is_int($key)) {
throw new \InvalidArgumentException(sprintf('Missing value for "%s" rule/set.', $value));
}

if (true !== $value && false !== $value && !\is_array($value)) {
throw new InvalidFixerConfigurationException($key, 'Configuration must be an array and may not be empty.');
}
}

$this->resolveSet($set);
Expand Down
2 changes: 1 addition & 1 deletion tests/Console/ConfigurationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function testResolveConfigFileChooseFile($expectedFile, $expectedClass, $
$resolver = $this->createConfigurationResolver(
['path' => [$path]],
null,
$cwdPath
$cwdPath ?: ''
);

static::assertSame($expectedFile, $resolver->getConfigFile());
Expand Down
6 changes: 3 additions & 3 deletions tests/DocBlock/ShortDescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
final class ShortDescriptionTest extends TestCase
{
/**
* @param mixed $expected
* @param null|mixed $input
* @param null|int $expected
* @param string $input
*
* @dataProvider provideGetEndCases
*/
public function testGetEnd($expected, $input = null)
public function testGetEnd($expected, $input)
{
$doc = new DocBlock($input);
$shortDescription = new ShortDescription($doc);
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixer/ControlStructure/NoAlternativeSyntaxFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ final class NoAlternativeSyntaxFixerTest extends AbstractFixerTestCase
/**
* @dataProvider provideFixCases
*
* @param mixed $expected
* @param null|mixed $input
* @param string $expected
* @param null|string $input
*/
public function testFix($expected, $input = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function testLegacyFix()
}

/**
* @param string $expected
* @param string $input
* @param string $expected
* @param null|string $input
*
* @dataProvider provideFixCases
*/
Expand Down
8 changes: 4 additions & 4 deletions tests/Fixer/Naming/NoHomoglyphNamesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ final class NoHomoglyphNamesFixerTest extends AbstractFixerTestCase
/**
* @dataProvider provideFixCases
*
* @param mixed $expected
* @param null|mixed $input
* @param string $expected
* @param null|string $input
*/
public function testFix($expected, $input = null)
{
Expand Down Expand Up @@ -106,8 +106,8 @@ public function provideFixCases()
* @dataProvider provideFix74Cases
* @requires PHP 7.4
*
* @param mixed $expected
* @param null|mixed $input
* @param string $expected
* @param null|string $input
*/
public function testFix74($expected, $input = null)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Fixer/PhpUnit/PhpUnitInternalClassFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class PhpUnitInternalClassFixerTest extends AbstractFixerTestCase
/**
* @dataProvider provideFixCases
*
* @param string $expected
* @param null|mixed $input
* @param array $config
* @param string $expected
* @param null|string $input
* @param array $config
*/
public function testFix($expected, $input = null, $config = [])
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixer/PhpUnit/PhpUnitMethodCasingFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function testFixToCamelCase($expected, $input = null)
/**
* @dataProvider provideFixCases
*
* @param mixed $camelExpected
* @param null|mixed $camelInput
* @param string $camelExpected
* @param null|string $camelInput
*/
public function testFixToSnakeCase($camelExpected, $camelInput = null)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Fixer/PhpUnit/PhpUnitSizeClassFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class PhpUnitSizeClassFixerTest extends AbstractFixerTestCase
/**
* @dataProvider provideFixCases
*
* @param string $expected
* @param null|mixed $input
* @param array $config
* @param string $expected
* @param null|string $input
* @param array $config
*/
public function testFix($expected, $input = null, $config = [])
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Test/AbstractIntegrationCaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function create(SplFileInfo $file)
/**
* Parses the '--CONFIG--' block of a '.test' file.
*
* @param string $config
* @param ?string $config
*
* @return array
*/
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function determineConfig(SplFileInfo $file, $config)
/**
* Parses the '--REQUIREMENTS--' block of a '.test' file and determines requirements.
*
* @param string $config
* @param ?string $config
*
* @return array
*/
Expand Down Expand Up @@ -155,7 +155,7 @@ protected function determineTitle(SplFileInfo $file, $config)
/**
* Parses the '--SETTINGS--' block of a '.test' file and determines settings.
*
* @param string $config
* @param ?string $config
*
* @return array
*/
Expand Down
22 changes: 11 additions & 11 deletions tests/Tokenizer/TokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public function testReadFromCacheAfterClearing()
}

/**
* @param string $source
* @param Token[] $sequence
* @param int $start
* @param null|int $end
* @param array|bool $caseSensitive
* @param string $source
* @param Token[] $sequence
* @param int $start
* @param null|int $end
* @param null|array|bool $caseSensitive
*
* @dataProvider provideFindSequenceCases
*/
Expand Down Expand Up @@ -210,7 +210,7 @@ public function provideFindSequenceCases()
],
0,
1,
[1, true],
[1 => true],
],
[
'<?php $x = 13;',
Expand Down Expand Up @@ -238,7 +238,7 @@ public function provideFindSequenceCases()
],
0,
1,
[1, false],
[1 => false],
],
[
'<?php $x = 15;',
Expand Down Expand Up @@ -621,7 +621,7 @@ public function provideGetClearTokenAndMergeSurroundingWhitespaceCases()
}

/**
* @param int $expectedIndex
* @param ?int $expectedIndex
* @param int $direction
* @param int $index
* @param bool $caseSensitive
Expand Down Expand Up @@ -1247,9 +1247,9 @@ public function testRemovingTrailingWhitespaceWillNotIncreaseTokensCount()
}

/**
* @param null|int $expected
* @param string $code
* @param int $index
* @param null|array $expected
* @param string $code
* @param int $index
*
* @dataProvider provideDetectBlockTypeCases
*/
Expand Down

0 comments on commit c39900d

Please sign in to comment.