Skip to content
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

Remove dead code #112

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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();
}
}