-
Notifications
You must be signed in to change notification settings - Fork 574
Fix phpstan/phpstan#14366: call-to-function is deprecated, depending on PHP_VERSION #5295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Rules\RestrictedUsage; | ||
|
|
||
| use Nette\Utils\Strings; | ||
| use PHPStan\Php\PhpVersions; | ||
| use PHPStan\Reflection\AttributeReflection; | ||
| use PHPStan\Type\IntegerRangeType; | ||
| use function sprintf; | ||
| use function strtolower; | ||
|
|
||
| final class DeprecatedSinceVersionHelper | ||
| { | ||
|
|
||
| /** | ||
| * @param list<AttributeReflection> $attributes | ||
| */ | ||
| public static function isScopeVersionBeforeDeprecation(array $attributes, PhpVersions $phpVersions): bool | ||
| { | ||
| $sinceVersionId = self::getDeprecatedSincePhpVersionId($attributes); | ||
| if ($sinceVersionId === null) { | ||
| return false; | ||
| } | ||
|
|
||
| return !IntegerRangeType::fromInterval($sinceVersionId, null)->isSuperTypeOf($phpVersions->getType())->yes(); | ||
|
Check warning on line 25 in src/Rules/RestrictedUsage/DeprecatedSinceVersionHelper.php
|
||
| } | ||
|
|
||
| /** | ||
| * @param list<AttributeReflection> $attributes | ||
| */ | ||
| private static function getDeprecatedSincePhpVersionId(array $attributes): ?int | ||
| { | ||
| foreach ($attributes as $attribute) { | ||
| if (strtolower($attribute->getName()) !== 'deprecated') { | ||
| continue; | ||
| } | ||
| $argumentTypes = $attribute->getArgumentTypes(); | ||
| if (!isset($argumentTypes['since'])) { | ||
| continue; | ||
| } | ||
| $sinceType = $argumentTypes['since']; | ||
| foreach ($sinceType->getConstantStrings() as $constantString) { | ||
| $matches = Strings::match($constantString->getValue(), '#^(\d+)\.(\d+)(?:\.(\d+))?$#'); | ||
| if ($matches !== null) { | ||
| $major = (int) $matches[1]; | ||
| $minor = (int) $matches[2]; | ||
| $patch = (int) ($matches[3] ?? 0); | ||
| return (int) sprintf('%d%02d%02d', $major, $minor, $patch); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Rules\RestrictedUsage; | ||
|
|
||
| use PHPStan\Rules\Rule; | ||
| use PHPStan\Testing\RuleTestCase; | ||
|
|
||
| /** | ||
| * @extends RuleTestCase<RestrictedFunctionUsageRule> | ||
| */ | ||
| class Bug14366Test extends RuleTestCase | ||
| { | ||
|
|
||
| protected function getRule(): Rule | ||
| { | ||
| return new RestrictedFunctionUsageRule( | ||
| self::getContainer(), | ||
| self::createReflectionProvider(), | ||
| ); | ||
| } | ||
|
|
||
| public function testRule(): void | ||
| { | ||
| $this->analyse([__DIR__ . '/data/bug-14366.php'], [ | ||
| [ | ||
| 'Call to deprecated function curl_close().', | ||
| 28, | ||
| ], | ||
| ]); | ||
| } | ||
|
|
||
| public static function getAdditionalConfigFiles(): array | ||
| { | ||
| return [ | ||
| __DIR__ . '/bug-14366.neon', | ||
| ...parent::getAdditionalConfigFiles(), | ||
| ]; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| parameters: | ||
| phpVersion: 80500 | ||
|
|
||
| includes: | ||
| - ../../../../vendor/phpstan/phpstan-deprecation-rules/rules.neon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deprecations is only one use-case of Restricted* classes. we should not mix this use-case into the this abstract base-classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the initial
make phpstanrun which failed due to the dead method detection. The re-run after adding@apipassed cleanly, and the commit has been pushed.