Skip to content

Commit

Permalink
fix deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
seferov committed Jul 7, 2023
1 parent 4739916 commit 31e1993
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 24 deletions.
19 changes: 2 additions & 17 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.7.3@38c452ae584467e939d55377aaf83b5a26f19dd1">
<file src="src/Plugin.php">
<UnusedPsalmSuppress occurrences="1">
<code>DeprecatedMethod</code>
</UnusedPsalmSuppress>
</file>
<files psalm-version="5.13.1@086b94371304750d1c673315321a55d15fc59015">
<file src="src/Twig/Context.php">
<UnnecessaryVarAnnotation occurrences="2">
<UnnecessaryVarAnnotation>
<code>int</code>
<code>string</code>
</UnnecessaryVarAnnotation>
</file>
<file src="src/Test/CodeceptionModule.php">
<UnusedPsalmSuppress occurrences="1">
<code>NonInvariantDocblockPropertyType</code>
</UnusedPsalmSuppress>
</file>
<file src="src/Symfony/ContainerMeta.php">
<PossiblyNullReference occurrences="1">
<code>attributes</code>
</PossiblyNullReference>
</file>
</files>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
cacheDirectory=".build/psalm"
errorBaseline="psalm-baseline.xml"
findUnusedCode="true"
findUnusedBaselineEntry="true"
>
<projectFiles>
<directory name="src" />
Expand Down
4 changes: 2 additions & 2 deletions src/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static function analyseArgument(array $args, StatementsSource $statement
}

$defaultParam = $normalizedParams['default'];
if ($defaultParam && (!$defaultParam->value instanceof Expr\ConstFetch || 'null' !== $defaultParam->value->name->parts[0])) {
if ($defaultParam && (!$defaultParam->value instanceof Expr\ConstFetch || 'null' !== $defaultParam->value->name->getFirst())) {
$returnTypes->removeType('null');
}

Expand Down Expand Up @@ -206,7 +206,7 @@ private static function analyseOption(array $args, StatementsSource $statements_
}

if ($defaultParam->value instanceof Expr\ConstFetch) {
switch ($defaultParam->value->name->parts[0]) {
switch ($defaultParam->value->name->getFirst()) {
case 'null':
$returnTypes->addType(new TNull());
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/HeaderBagHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)
*/
private static function makeReturnType(array $call_args): Union
{
if (3 === count($call_args) && (($arg = $call_args[2]->value) instanceof ConstFetch) && 'false' === $arg->name->parts[0]) {
if (3 === count($call_args) && (($arg = $call_args[2]->value) instanceof ConstFetch) && 'false' === $arg->name->getFirst()) {
return new Union([new TArray([new Union([new TInt()]), new Union([new TString()])])]);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function __invoke(RegistrationInterface $api, \SimpleXMLElement $config =
if (class_exists(AnnotationRegistry::class)) {
require_once __DIR__.'/Handler/DoctrineRepositoryHandler.php';
if (method_exists(AnnotationRegistry::class, 'registerLoader')) {
/** @psalm-suppress DeprecatedMethod */
AnnotationRegistry::registerLoader('class_exists');

Check failure on line 57 in src/Plugin.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP: 8, deps: lowest)

DeprecatedMethod

src/Plugin.php:57:17: DeprecatedMethod: The method Doctrine\Common\Annotations\AnnotationRegistry::registerLoader has been marked as deprecated (see https://psalm.dev/001)

Check failure on line 57 in src/Plugin.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (PHP: 8.1, deps: lowest)

DeprecatedMethod

src/Plugin.php:57:17: DeprecatedMethod: The method Doctrine\Common\Annotations\AnnotationRegistry::registerLoader has been marked as deprecated (see https://psalm.dev/001)
}
$api->registerHooksFromClass(DoctrineRepositoryHandler::class);
Expand All @@ -68,7 +67,8 @@ public function __invoke(RegistrationInterface $api, \SimpleXMLElement $config =
ContainerHandler::init($containerMeta);

try {
TemplateFileAnalyzer::initExtensions(array_filter(array_map(function (array $m) use ($containerMeta) {
/** @psalm-var list<class-string> $extensionClasses */
$extensionClasses = array_filter(array_map(function (array $m) use ($containerMeta) {
if ('addExtension' !== $m[0]) {
return null;
}
Expand All @@ -78,7 +78,8 @@ public function __invoke(RegistrationInterface $api, \SimpleXMLElement $config =
} catch (ServiceNotFoundException $e) {
return null;
}
}, $containerMeta->get('twig')->getMethodCalls())));
}, $containerMeta->get('twig')->getMethodCalls()));
TemplateFileAnalyzer::initExtensions($extensionClasses);
} catch (ServiceNotFoundException $e) {
}

Expand Down
4 changes: 3 additions & 1 deletion src/Twig/CachedTemplatesRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ private static function generateNames(string $baseName): \Generator
$oldNotation = $baseName;
}

if (null !== $oldNotation) {
if (null !== $oldNotation && false !== strpos($oldNotation, ':')) {
/** @psalm-suppress PossiblyUndefinedArrayOffset */
list($bundleName, $rest) = explode(':', $oldNotation, 2);
/** @psalm-suppress PossiblyUndefinedArrayOffset */
list($revTemplateName, $revRest) = explode(':', strrev($rest), 2);
$pathParts = explode('/', strrev($revRest));
$pathParts = array_merge($pathParts, explode('/', strrev($revTemplateName)));
Expand Down
4 changes: 4 additions & 0 deletions src/Twig/CachedTemplatesTainter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)
isset($call_args[1]) ? [$call_args[1]] : []
);

if (!isset($call_args[0])) {
return null;
}

try {
$templateName = TwigUtils::extractTemplateNameFromExpression($call_args[0]->value, $source);
} catch (TemplateNameUnresolvedException $exception) {
Expand Down
3 changes: 3 additions & 0 deletions src/Twig/TemplateFileAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class TemplateFileAnalyzer extends FileAnalyzer
*/
private static $extensionClasses = [];

/**
* @param list<class-string> $extensionClasses
*/
public static function initExtensions(array $extensionClasses): void
{
self::$extensionClasses = $extensionClasses;
Expand Down

0 comments on commit 31e1993

Please sign in to comment.