Skip to content

Commit

Permalink
Merge pull request #112 from weirdan/clean-up-deprecations
Browse files Browse the repository at this point in the history
Remove dead code
  • Loading branch information
weirdan committed Jun 18, 2021
2 parents 1ce1ef2 + 6ba908d commit 5dd3be0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 59 deletions.
6 changes: 5 additions & 1 deletion phpcs.xml.dist
@@ -1,5 +1,9 @@
<?xml version="1.0"?>
<ruleset name="phpunit-psalm-plugin">
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
name="phpunit-psalm-plugin"
>
<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>
Expand Down
66 changes: 8 additions & 58 deletions src/Hooks/TestCaseHandler.php
Expand Up @@ -12,7 +12,6 @@
use Psalm\Exception\DocblockParseException;
use Psalm\IssueBuffer;
use Psalm\Issue;
use Psalm\PhpUnitPlugin\VersionUtils;
use Psalm\Plugin\EventHandler\AfterClassLikeAnalysisInterface;
use Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface;
use Psalm\Plugin\EventHandler\AfterCodebasePopulatedInterface;
Expand Down Expand Up @@ -441,21 +440,7 @@ static function (
/** @return non-empty-array<string,Type\Atomic> */
private static function getAtomics(Type\Union $union): array
{
if (method_exists($union, 'getAtomicTypes')) {
/** @var non-empty-array<string, Type\Atomic> annotated for versions missing the method */
return $union->getAtomicTypes();
}

if (method_exists($union, 'getTypes')) {
/**
* @psalm-suppress DeprecatedMethod annotated for newer versions that deprecated the method
* @var non-empty-array<string, Type\Atomic> annotated for versions missing the method
*/
$types = $union->getTypes();
return $types;
}

throw new RuntimeException('Unexpected: union has no way to get it constituent types');
return $union->getAtomicTypes();
}

private static function unionizeIterables(Codebase $codebase, Type\Union $iterables): Type\Atomic\TIterable
Expand Down Expand Up @@ -553,40 +538,15 @@ function (array $lines) {
/** @return array{description:string, specials:array<string,array<int,string>>} */
private static function getParsedComment(Doc $comment): array
{
if (VersionUtils::packageVersionIs('vimeo/psalm', '>=', '3.11.6')) {
// explanation for the suppressions below
// Oldest supported psalm versions did not have parsePreservingLength() at all
// Versions between 3.6 and 3.11.6 had that, but it was returning array

/** @psalm-suppress UndefinedMethod for oldest versions */
$parsed_docblock = DocComment::parsePreservingLength($comment);

/**
* @psalm-suppress InvalidPropertyFetch
* @var string
*/
$description = $parsed_docblock->description;
$parsed_docblock = DocComment::parsePreservingLength($comment);

/**
* @psalm-suppress InvalidPropertyFetch
* @var array<string,array<int,string>>
*/
$specials = $parsed_docblock->tags;
$description = $parsed_docblock->description;
$specials = $parsed_docblock->tags;

return [
'description' => $description,
'specials' => $specials,
];
} else {
// before 3.11.6 parsePreservingLength() was returning array,
// but parse() wasn't deprecated, so we just use that

/** @psalm-suppress DeprecatedMethod for newer Psalm versions */
return DocComment::parse(
(string) $comment->getReformattedText(),
self::getCommentLine($comment)
);
}
return [
'description' => $description,
'specials' => $specials,
];
}

private static function queueClassLikeForScanning(
Expand All @@ -604,14 +564,4 @@ private static function queueClassLikeForScanning(
$codebase->scanner->queueClassLikeForScanning($fq_class_name, $file_path);
}
}

private static function getCommentLine(Doc $docblock): int
{
if (method_exists($docblock, 'getStartLine')) {
//typecasting is done on purpose, compatability with psalm old versions
return $docblock->getStartLine();
}
/** @psalm-suppress DeprecatedMethod */
return $docblock->getLine();
}
}

0 comments on commit 5dd3be0

Please sign in to comment.