Skip to content

Commit bcd693f

Browse files
authoredMar 19, 2024··
Update dev dependencies (#254)
Support nikic/php-parser 5 and PHPUnit 11.
2 parents d363d00 + e3f6e67 commit bcd693f

11 files changed

+33
-23
lines changed
 

‎composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
},
2727
"require-dev": {
2828
"nette/neon": "^3.2",
29-
"nikic/php-parser": "^4.13",
30-
"phpunit/phpunit": "^8.5 || ^10.1",
29+
"nikic/php-parser": "^4.13 || ^5.0",
30+
"phpunit/phpunit": "^8.5 || ^10.1 || ^11.0",
3131
"php-parallel-lint/php-parallel-lint": "^1.2",
3232
"php-parallel-lint/php-console-highlighter": "^1.0",
3333
"spaze/coding-standard": "^1.7"

‎src/Allowed/Allowed.php

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPStan\Type\NullType;
1515
use PHPStan\Type\Type;
1616
use PHPStan\Type\UnionType;
17+
use PHPStan\Type\VerbosityLevel;
1718
use Spaze\PHPStan\Rules\Disallowed\DisallowedWithParams;
1819
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeException;
1920
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeInConfigException;
@@ -25,6 +26,7 @@
2526
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueCaseInsensitiveExcept;
2627
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueExcept;
2728
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueExceptAny;
29+
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueFlag;
2830
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueFlagExcept;
2931
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueFlagSpecific;
3032
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueSpecific;
@@ -302,6 +304,13 @@ private function paramFactory(string $class, $key, $value): ParamValue
302304
} else {
303305
throw new UnsupportedParamTypeInConfigException($paramPosition, $paramName, gettype($paramValue));
304306
}
307+
if (is_subclass_of($class, ParamValueFlag::class)) {
308+
foreach ($type->getConstantScalarValues() as $value) {
309+
if (!is_int($value)) {
310+
throw new UnsupportedParamTypeInConfigException($paramPosition, $paramName, gettype($value) . ' of ' . $type->describe(VerbosityLevel::precise()));
311+
}
312+
}
313+
}
305314
return new $class($paramPosition, $paramName, $type);
306315
}
307316

‎src/Params/ParamValueFlag.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,21 @@
55

66
use PHPStan\Type\Constant\ConstantIntegerType;
77
use PHPStan\Type\Type;
8-
use PHPStan\Type\VerbosityLevel;
98
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeException;
10-
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeInConfigException;
119

1210
abstract class ParamValueFlag extends ParamValue
1311
{
1412

1513
/**
1614
* @throws UnsupportedParamTypeException
17-
* @throws UnsupportedParamTypeInConfigException
1815
*/
1916
protected function isFlagSet(Type $type): bool
2017
{
2118
if (!$type instanceof ConstantIntegerType) {
2219
throw new UnsupportedParamTypeException();
2320
}
2421
foreach ($this->getType()->getConstantScalarValues() as $value) {
25-
if (!is_int($value)) {
26-
throw new UnsupportedParamTypeInConfigException($this->getPosition(), $this->getName(), gettype($value) . ' of ' . $this->getType()->describe(VerbosityLevel::precise()));
27-
}
28-
if (($value & $type->getValue()) !== 0) {
22+
if (is_int($value) && ($value & $type->getValue()) !== 0) {
2923
return true;
3024
}
3125
}

‎tests/Allowed/AllowedPathTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Reflection\ReflectionProvider;
1212
use PHPStan\ShouldNotHappenException;
1313
use PHPStan\Testing\PHPStanTestCase;
14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use Spaze\PHPStan\Rules\Disallowed\File\FilePath;
1516
use Traits\TestClass;
1617
use Traits\TestTrait;
@@ -44,6 +45,7 @@ protected function setUp(): void
4445
/**
4546
* @dataProvider pathProvider
4647
*/
48+
#[DataProvider('pathProvider')]
4749
public function testMatches(string $allowedPath, string $file, string $fileWithRootDir): void
4850
{
4951
$context = ScopeContext::create($file);

‎tests/Calls/FunctionCallsNamedParamsTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
use PHPStan\Rules\Rule;
77
use PHPStan\ShouldNotHappenException;
88
use PHPStan\Testing\RuleTestCase;
9+
use PHPUnit\Framework\Attributes\RequiresPhp;
910
use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory;
1011
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors;
1112

1213
/**
1314
* @requires PHP >= 8.0
1415
*/
16+
#[RequiresPhp('>= 8.0')]
1517
class FunctionCallsNamedParamsTest extends RuleTestCase
1618
{
1719

‎tests/Calls/FunctionCallsTypeStringParamsInvalidFlagsConfigTest.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33

44
namespace Spaze\PHPStan\Rules\Disallowed\Calls;
55

6-
use PHPStan\Rules\Rule;
76
use PHPStan\ShouldNotHappenException;
8-
use PHPStan\Testing\RuleTestCase;
7+
use PHPStan\Testing\PHPStanTestCase;
98
use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory;
10-
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeInConfigException;
119
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors;
1210

13-
class FunctionCallsTypeStringParamsInvalidFlagsConfigTest extends RuleTestCase
11+
class FunctionCallsTypeStringParamsInvalidFlagsConfigTest extends PHPStanTestCase
1412
{
1513

1614
/**
1715
* @throws ShouldNotHappenException
1816
*/
19-
protected function getRule(): Rule
17+
public function testException(): void
2018
{
19+
$this->expectException(ShouldNotHappenException::class);
20+
$this->expectExceptionMessage("Foo\Bar\Waldo\intParam1(): Parameter #1 has an unsupported type string of 2|'bruh' specified in configuration");
2121
$container = self::getContainer();
22-
return new FunctionCalls(
22+
new FunctionCalls(
2323
$container->getByType(DisallowedCallsRuleErrors::class),
2424
$container->getByType(DisallowedCallFactory::class),
2525
$this->createReflectionProvider(),
@@ -38,14 +38,6 @@ protected function getRule(): Rule
3838
}
3939

4040

41-
public function testException(): void
42-
{
43-
$this->expectException(UnsupportedParamTypeInConfigException::class);
44-
$this->expectExceptionMessage("Parameter #1 has an unsupported type string of 2|'bruh' specified in configuration");
45-
$this->analyse([__DIR__ . '/../src/disallowed/functionCallsTypeStringParams.php'], []);
46-
}
47-
48-
4941
public static function getAdditionalConfigFiles(): array
5042
{
5143
return [

‎tests/DisallowedSuperglobalFactoryTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Generator;
77
use PHPStan\ShouldNotHappenException;
88
use PHPStan\Testing\PHPStanTestCase;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910

1011
class DisallowedSuperglobalFactoryTest extends PHPStanTestCase
1112
{
@@ -16,6 +17,7 @@ class DisallowedSuperglobalFactoryTest extends PHPStanTestCase
1617
* @param class-string|null $exceptionClass
1718
* @throws ShouldNotHappenException
1819
*/
20+
#[DataProvider('superglobalsProvider')]
1921
public function testNonSuperglobalInConfig(string $superglobal, ?string $exceptionClass)
2022
{
2123
if ($exceptionClass) {

‎tests/File/FilePathTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Generator;
77
use PHPStan\File\FileHelper;
88
use PHPStan\Testing\PHPStanTestCase;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910

1011
class FilePathTest extends PHPStanTestCase
1112
{
@@ -28,6 +29,7 @@ protected function setUp(): void
2829
/**
2930
* @dataProvider pathProvider
3031
*/
32+
#[DataProvider('pathProvider')]
3133
public function testFnMatch(string $path, string $file, string $fileWithRootDir): void
3234
{
3335
$this->assertTrue($this->filePath->fnMatch($path, $file));

‎tests/Identifier/IdentifierTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Generator;
77
use PHPStan\Testing\PHPStanTestCase;
8+
use PHPUnit\Framework\Attributes\DataProvider;
89

910
class IdentifierTest extends PHPStanTestCase
1011
{
@@ -26,6 +27,7 @@ protected function setUp(): void
2627
* @return void
2728
* @dataProvider matchesProvider
2829
*/
30+
#[DataProvider('matchesProvider')]
2931
public function testMatches(string $pattern, string $value, ?array $excludes): void
3032
{
3133
$this->assertTrue($this->identifier->matches($pattern, $value, $excludes));
@@ -39,6 +41,7 @@ public function testMatches(string $pattern, string $value, ?array $excludes): v
3941
* @return void
4042
* @dataProvider doesNotMatchProvider
4143
*/
44+
#[DataProvider('doesNotMatchProvider')]
4245
public function testDoesNotMatch(string $pattern, string $value, ?array $excludes): void
4346
{
4447
$this->assertFalse($this->identifier->matches($pattern, $value, $excludes));

‎tests/Usages/ClassConstantEnumUsagesTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Enums\Enum;
88
use PHPStan\Rules\Rule;
99
use PHPStan\Testing\RuleTestCase;
10+
use PHPUnit\Framework\Attributes\RequiresPhp;
1011
use Spaze\PHPStan\Rules\Disallowed\DisallowedConstantFactory;
1112
use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter;
1213
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedConstantRuleErrors;
@@ -15,6 +16,7 @@
1516
/**
1617
* @requires PHP >= 8.1
1718
*/
19+
#[RequiresPhp('>= 8.1')]
1820
class ClassConstantEnumUsagesTest extends RuleTestCase
1921
{
2022

‎tests/Usages/NamespaceUsagesTypesTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
use PHPStan\Rules\Rule;
77
use PHPStan\Testing\RuleTestCase;
8+
use PHPUnit\Framework\Attributes\RequiresPhp;
89
use Spaze\PHPStan\Rules\Disallowed\DisallowedNamespaceFactory;
910
use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer;
1011
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedNamespaceRuleErrors;
1112

1213
/**
1314
* @requires PHP >= 8.1
1415
*/
16+
#[RequiresPhp('>= 8.1')]
1517
class NamespaceUsagesTypesTest extends RuleTestCase
1618
{
1719

0 commit comments

Comments
 (0)
Please sign in to comment.