Skip to content

Commit

Permalink
Update dev dependencies (#254)
Browse files Browse the repository at this point in the history
Support nikic/php-parser 5 and PHPUnit 11.
  • Loading branch information
spaze committed Mar 19, 2024
2 parents d363d00 + e3f6e67 commit bcd693f
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 23 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"require-dev": {
"nette/neon": "^3.2",
"nikic/php-parser": "^4.13",
"phpunit/phpunit": "^8.5 || ^10.1",
"nikic/php-parser": "^4.13 || ^5.0",
"phpunit/phpunit": "^8.5 || ^10.1 || ^11.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"php-parallel-lint/php-console-highlighter": "^1.0",
"spaze/coding-standard": "^1.7"
Expand Down
9 changes: 9 additions & 0 deletions src/Allowed/Allowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use Spaze\PHPStan\Rules\Disallowed\DisallowedWithParams;
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeException;
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeInConfigException;
Expand All @@ -25,6 +26,7 @@
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueCaseInsensitiveExcept;
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueExcept;
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueExceptAny;
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueFlag;
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueFlagExcept;
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueFlagSpecific;
use Spaze\PHPStan\Rules\Disallowed\Params\ParamValueSpecific;
Expand Down Expand Up @@ -302,6 +304,13 @@ private function paramFactory(string $class, $key, $value): ParamValue
} else {
throw new UnsupportedParamTypeInConfigException($paramPosition, $paramName, gettype($paramValue));
}
if (is_subclass_of($class, ParamValueFlag::class)) {
foreach ($type->getConstantScalarValues() as $value) {
if (!is_int($value)) {
throw new UnsupportedParamTypeInConfigException($paramPosition, $paramName, gettype($value) . ' of ' . $type->describe(VerbosityLevel::precise()));
}
}
}
return new $class($paramPosition, $paramName, $type);
}

Expand Down
8 changes: 1 addition & 7 deletions src/Params/ParamValueFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@

use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeException;
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeInConfigException;

abstract class ParamValueFlag extends ParamValue
{

/**
* @throws UnsupportedParamTypeException
* @throws UnsupportedParamTypeInConfigException
*/
protected function isFlagSet(Type $type): bool
{
if (!$type instanceof ConstantIntegerType) {
throw new UnsupportedParamTypeException();
}
foreach ($this->getType()->getConstantScalarValues() as $value) {
if (!is_int($value)) {
throw new UnsupportedParamTypeInConfigException($this->getPosition(), $this->getName(), gettype($value) . ' of ' . $this->getType()->describe(VerbosityLevel::precise()));
}
if (($value & $type->getValue()) !== 0) {
if (is_int($value) && ($value & $type->getValue()) !== 0) {
return true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Allowed/AllowedPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\ShouldNotHappenException;
use PHPStan\Testing\PHPStanTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use Spaze\PHPStan\Rules\Disallowed\File\FilePath;
use Traits\TestClass;
use Traits\TestTrait;
Expand Down Expand Up @@ -44,6 +45,7 @@ protected function setUp(): void
/**
* @dataProvider pathProvider
*/
#[DataProvider('pathProvider')]
public function testMatches(string $allowedPath, string $file, string $fileWithRootDir): void
{
$context = ScopeContext::create($file);
Expand Down
2 changes: 2 additions & 0 deletions tests/Calls/FunctionCallsNamedParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory;
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors;

/**
* @requires PHP >= 8.0
*/
#[RequiresPhp('>= 8.0')]
class FunctionCallsNamedParamsTest extends RuleTestCase
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

namespace Spaze\PHPStan\Rules\Disallowed\Calls;

use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
use PHPStan\Testing\RuleTestCase;
use PHPStan\Testing\PHPStanTestCase;
use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory;
use Spaze\PHPStan\Rules\Disallowed\Exceptions\UnsupportedParamTypeInConfigException;
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors;

class FunctionCallsTypeStringParamsInvalidFlagsConfigTest extends RuleTestCase
class FunctionCallsTypeStringParamsInvalidFlagsConfigTest extends PHPStanTestCase
{

/**
* @throws ShouldNotHappenException
*/
protected function getRule(): Rule
public function testException(): void
{
$this->expectException(ShouldNotHappenException::class);
$this->expectExceptionMessage("Foo\Bar\Waldo\intParam1(): Parameter #1 has an unsupported type string of 2|'bruh' specified in configuration");
$container = self::getContainer();
return new FunctionCalls(
new FunctionCalls(
$container->getByType(DisallowedCallsRuleErrors::class),
$container->getByType(DisallowedCallFactory::class),
$this->createReflectionProvider(),
Expand All @@ -38,14 +38,6 @@ protected function getRule(): Rule
}


public function testException(): void
{
$this->expectException(UnsupportedParamTypeInConfigException::class);
$this->expectExceptionMessage("Parameter #1 has an unsupported type string of 2|'bruh' specified in configuration");
$this->analyse([__DIR__ . '/../src/disallowed/functionCallsTypeStringParams.php'], []);
}


public static function getAdditionalConfigFiles(): array
{
return [
Expand Down
2 changes: 2 additions & 0 deletions tests/DisallowedSuperglobalFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Generator;
use PHPStan\ShouldNotHappenException;
use PHPStan\Testing\PHPStanTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class DisallowedSuperglobalFactoryTest extends PHPStanTestCase
{
Expand All @@ -16,6 +17,7 @@ class DisallowedSuperglobalFactoryTest extends PHPStanTestCase
* @param class-string|null $exceptionClass
* @throws ShouldNotHappenException
*/
#[DataProvider('superglobalsProvider')]
public function testNonSuperglobalInConfig(string $superglobal, ?string $exceptionClass)
{
if ($exceptionClass) {
Expand Down
2 changes: 2 additions & 0 deletions tests/File/FilePathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Generator;
use PHPStan\File\FileHelper;
use PHPStan\Testing\PHPStanTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class FilePathTest extends PHPStanTestCase
{
Expand All @@ -28,6 +29,7 @@ protected function setUp(): void
/**
* @dataProvider pathProvider
*/
#[DataProvider('pathProvider')]
public function testFnMatch(string $path, string $file, string $fileWithRootDir): void
{
$this->assertTrue($this->filePath->fnMatch($path, $file));
Expand Down
3 changes: 3 additions & 0 deletions tests/Identifier/IdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Generator;
use PHPStan\Testing\PHPStanTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class IdentifierTest extends PHPStanTestCase
{
Expand All @@ -26,6 +27,7 @@ protected function setUp(): void
* @return void
* @dataProvider matchesProvider
*/
#[DataProvider('matchesProvider')]
public function testMatches(string $pattern, string $value, ?array $excludes): void
{
$this->assertTrue($this->identifier->matches($pattern, $value, $excludes));
Expand All @@ -39,6 +41,7 @@ public function testMatches(string $pattern, string $value, ?array $excludes): v
* @return void
* @dataProvider doesNotMatchProvider
*/
#[DataProvider('doesNotMatchProvider')]
public function testDoesNotMatch(string $pattern, string $value, ?array $excludes): void
{
$this->assertFalse($this->identifier->matches($pattern, $value, $excludes));
Expand Down
2 changes: 2 additions & 0 deletions tests/Usages/ClassConstantEnumUsagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Enums\Enum;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
use Spaze\PHPStan\Rules\Disallowed\DisallowedConstantFactory;
use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter;
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedConstantRuleErrors;
Expand All @@ -15,6 +16,7 @@
/**
* @requires PHP >= 8.1
*/
#[RequiresPhp('>= 8.1')]
class ClassConstantEnumUsagesTest extends RuleTestCase
{

Expand Down
2 changes: 2 additions & 0 deletions tests/Usages/NamespaceUsagesTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
use Spaze\PHPStan\Rules\Disallowed\DisallowedNamespaceFactory;
use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer;
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedNamespaceRuleErrors;

/**
* @requires PHP >= 8.1
*/
#[RequiresPhp('>= 8.1')]
class NamespaceUsagesTypesTest extends RuleTestCase
{

Expand Down

0 comments on commit bcd693f

Please sign in to comment.