mirror of
https://github.com/danog/psalm-plugin-phpunit.git
synced 2024-11-30 04:29:08 +01:00
Merge pull request #79 from vladyslavstartsev/cleanup-package
Cleanup package (close #76)
This commit is contained in:
commit
88d464841d
@ -16,13 +16,13 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^7.1.3",
|
"php": "^7.1.3",
|
||||||
"ext-simplexml": "*",
|
"ext-simplexml": "*",
|
||||||
"composer/semver": "^1.4 || ^2.0 || ^3.0",
|
|
||||||
"ocramius/package-versions": "^1.3",
|
"ocramius/package-versions": "^1.3",
|
||||||
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
|
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
|
||||||
"vimeo/psalm": "^3.6.2 || dev-master"
|
"vimeo/psalm": "^3.6.2 || dev-master"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"codeception/codeception": "^4.0.3",
|
"codeception/codeception": "^4.0.3",
|
||||||
|
"composer/semver": "^1.4 || ^2.0 || ^3.0",
|
||||||
"squizlabs/php_codesniffer": "^3.3.1",
|
"squizlabs/php_codesniffer": "^3.3.1",
|
||||||
"weirdan/codeception-psalm-module": "^0.7.1"
|
"weirdan/codeception-psalm-module": "^0.7.1"
|
||||||
},
|
},
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Psalm\PhpUnitPlugin\Exception;
|
|
||||||
|
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
class UnsupportedPsalmVersion extends RuntimeException
|
|
||||||
{
|
|
||||||
}
|
|
@ -12,7 +12,6 @@ use Psalm\Codebase;
|
|||||||
use Psalm\DocComment;
|
use Psalm\DocComment;
|
||||||
use Psalm\Exception\DocblockParseException;
|
use Psalm\Exception\DocblockParseException;
|
||||||
use Psalm\FileSource;
|
use Psalm\FileSource;
|
||||||
use Psalm\Internal\PhpVisitor\ReflectorVisitor;
|
|
||||||
use Psalm\IssueBuffer;
|
use Psalm\IssueBuffer;
|
||||||
use Psalm\Issue;
|
use Psalm\Issue;
|
||||||
use Psalm\Plugin\Hook\AfterClassLikeAnalysisInterface;
|
use Psalm\Plugin\Hook\AfterClassLikeAnalysisInterface;
|
||||||
@ -21,8 +20,7 @@ use Psalm\Plugin\Hook\AfterCodebasePopulatedInterface;
|
|||||||
use Psalm\StatementsSource;
|
use Psalm\StatementsSource;
|
||||||
use Psalm\Storage\ClassLikeStorage;
|
use Psalm\Storage\ClassLikeStorage;
|
||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic\TIterable;
|
use RuntimeException;
|
||||||
use Psalm\Type\Union;
|
|
||||||
|
|
||||||
class TestCaseHandler implements
|
class TestCaseHandler implements
|
||||||
AfterClassLikeVisitInterface,
|
AfterClassLikeVisitInterface,
|
||||||
@ -127,7 +125,7 @@ class TestCaseHandler implements
|
|||||||
foreach ($class_storage->declaring_method_ids as $method_name_lc => $declaring_method_id) {
|
foreach ($class_storage->declaring_method_ids as $method_name_lc => $declaring_method_id) {
|
||||||
$method_name = $codebase->getCasedMethodId($class_storage->name . '::' . $method_name_lc);
|
$method_name = $codebase->getCasedMethodId($class_storage->name . '::' . $method_name_lc);
|
||||||
$method_storage = $codebase->methods->getStorage($declaring_method_id);
|
$method_storage = $codebase->methods->getStorage($declaring_method_id);
|
||||||
list($declaring_method_class, $declaring_method_name) = explode('::', (string) $declaring_method_id);
|
[$declaring_method_class, $declaring_method_name] = explode('::', (string) $declaring_method_id);
|
||||||
$declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_method_class);
|
$declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_method_class);
|
||||||
|
|
||||||
$declaring_class_node = $class_node;
|
$declaring_class_node = $class_node;
|
||||||
@ -198,7 +196,7 @@ class TestCaseHandler implements
|
|||||||
|
|
||||||
// methodExists also can mark methods as used (weird, but handy)
|
// methodExists also can mark methods as used (weird, but handy)
|
||||||
$provider_method_exists = $codebase->methodExists(
|
$provider_method_exists = $codebase->methodExists(
|
||||||
(string) $provider_method_id,
|
$provider_method_id,
|
||||||
$provider_docblock_location,
|
$provider_docblock_location,
|
||||||
(string) $declaring_method_id
|
(string) $declaring_method_id
|
||||||
);
|
);
|
||||||
@ -295,7 +293,7 @@ class TestCaseHandler implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
$checkParam =
|
$checkParam =
|
||||||
function (
|
static function (
|
||||||
Type\Union $potential_argument_type,
|
Type\Union $potential_argument_type,
|
||||||
Type\Union $param_type,
|
Type\Union $param_type,
|
||||||
bool $is_optional,
|
bool $is_optional,
|
||||||
@ -422,12 +420,12 @@ class TestCaseHandler implements
|
|||||||
if (method_exists($union, 'getAtomicTypes')) {
|
if (method_exists($union, 'getAtomicTypes')) {
|
||||||
/** @var non-empty-array<string, Type\Atomic> annotated for versions missing the method */
|
/** @var non-empty-array<string, Type\Atomic> annotated for versions missing the method */
|
||||||
return $union->getAtomicTypes();
|
return $union->getAtomicTypes();
|
||||||
} else {
|
|
||||||
/** @psalm-suppress DeprecatedMethod annotated for newer versions that deprecated the method */
|
|
||||||
$types = $union->getTypes();
|
|
||||||
assert(!empty($types));
|
|
||||||
return $types;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @psalm-suppress DeprecatedMethod annotated for newer versions that deprecated the method */
|
||||||
|
$types = $union->getTypes();
|
||||||
|
assert(!empty($types));
|
||||||
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function unionizeIterables(Codebase $codebase, Type\Union $iterables): Type\Atomic\TIterable
|
private static function unionizeIterables(Codebase $codebase, Type\Union $iterables): Type\Atomic\TIterable
|
||||||
@ -440,7 +438,7 @@ class TestCaseHandler implements
|
|||||||
|
|
||||||
foreach (self::getAtomics($iterables) as $type) {
|
foreach (self::getAtomics($iterables) as $type) {
|
||||||
if (!$type->isIterable($codebase)) {
|
if (!$type->isIterable($codebase)) {
|
||||||
throw new \RuntimeException('should be iterable');
|
throw new RuntimeException('should be iterable');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type instanceof Type\Atomic\TArray) {
|
if ($type instanceof Type\Atomic\TArray) {
|
||||||
@ -450,18 +448,18 @@ class TestCaseHandler implements
|
|||||||
$key_types[] = $type->getGenericKeyType();
|
$key_types[] = $type->getGenericKeyType();
|
||||||
$value_types[] = $type->getGenericValueType();
|
$value_types[] = $type->getGenericValueType();
|
||||||
} elseif ($type instanceof Type\Atomic\TNamedObject || $type instanceof Type\Atomic\TIterable) {
|
} elseif ($type instanceof Type\Atomic\TNamedObject || $type instanceof Type\Atomic\TIterable) {
|
||||||
list($key_types[], $value_types[]) = $codebase->getKeyValueParamsForTraversableObject($type);
|
[$key_types[], $value_types[]] = $codebase->getKeyValueParamsForTraversableObject($type);
|
||||||
} elseif ($type instanceof Type\Atomic\TList) {
|
} elseif ($type instanceof Type\Atomic\TList) {
|
||||||
$key_types[] = Type::getInt();
|
$key_types[] = Type::getInt();
|
||||||
$value_types[] = $type->type_param;
|
$value_types[] = $type->type_param;
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException('unexpected type');
|
throw new RuntimeException('unexpected type');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$combine =
|
$combine =
|
||||||
/** @param null|Type\Union $a */
|
/** @param null|Type\Union $a */
|
||||||
function ($a, Type\Union $b) use ($codebase): Type\Union {
|
static function ($a, Type\Union $b) use ($codebase): Type\Union {
|
||||||
return $a ? Type::combineUnionTypes($a, $b, $codebase) : $b;
|
return $a ? Type::combineUnionTypes($a, $b, $codebase) : $b;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -503,6 +501,7 @@ class TestCaseHandler implements
|
|||||||
|
|
||||||
if ($docblock) {
|
if ($docblock) {
|
||||||
try {
|
try {
|
||||||
|
/** @psalm-suppress DeprecatedMethod */
|
||||||
$parsed_comment = DocComment::parse(
|
$parsed_comment = DocComment::parse(
|
||||||
(string)$docblock->getReformattedText(),
|
(string)$docblock->getReformattedText(),
|
||||||
self::getCommentLine($docblock)
|
self::getCommentLine($docblock)
|
||||||
@ -512,7 +511,7 @@ class TestCaseHandler implements
|
|||||||
}
|
}
|
||||||
if (isset($parsed_comment['specials'])) {
|
if (isset($parsed_comment['specials'])) {
|
||||||
return array_map(
|
return array_map(
|
||||||
function (array $lines): array {
|
static function (array $lines): array {
|
||||||
return array_map('trim', $lines);
|
return array_map('trim', $lines);
|
||||||
},
|
},
|
||||||
$parsed_comment['specials']
|
$parsed_comment['specials']
|
||||||
@ -538,6 +537,7 @@ class TestCaseHandler implements
|
|||||||
private static function getCommentLine(Doc $docblock): int
|
private static function getCommentLine(Doc $docblock): int
|
||||||
{
|
{
|
||||||
if (method_exists($docblock, 'getStartLine')) {
|
if (method_exists($docblock, 'getStartLine')) {
|
||||||
|
//typecasting is done on purpose, compatability with psalm old versions
|
||||||
return (int) $docblock->getStartLine();
|
return (int) $docblock->getStartLine();
|
||||||
}
|
}
|
||||||
/** @psalm-suppress DeprecatedMethod */
|
/** @psalm-suppress DeprecatedMethod */
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
namespace Psalm\PhpUnitPlugin;
|
namespace Psalm\PhpUnitPlugin;
|
||||||
|
|
||||||
use Composer\Semver\Comparator;
|
|
||||||
use Composer\Semver\VersionParser;
|
|
||||||
use PackageVersions\Versions;
|
|
||||||
use SimpleXMLElement;
|
use SimpleXMLElement;
|
||||||
use Psalm\Plugin\PluginEntryPointInterface;
|
use Psalm\Plugin\PluginEntryPointInterface;
|
||||||
use Psalm\Plugin\RegistrationInterface;
|
use Psalm\Plugin\RegistrationInterface;
|
||||||
@ -13,7 +10,7 @@ use Psalm\Plugin\RegistrationInterface;
|
|||||||
class Plugin implements PluginEntryPointInterface
|
class Plugin implements PluginEntryPointInterface
|
||||||
{
|
{
|
||||||
/** @return void */
|
/** @return void */
|
||||||
public function __invoke(RegistrationInterface $psalm, SimpleXMLElement $config = null)
|
public function __invoke(RegistrationInterface $psalm, SimpleXMLElement $config = null): void
|
||||||
{
|
{
|
||||||
$psalm->addStubFile(__DIR__ . '/../stubs/Assert_75.phpstub');
|
$psalm->addStubFile(__DIR__ . '/../stubs/Assert_75.phpstub');
|
||||||
$psalm->addStubFile(__DIR__ . '/../stubs/TestCase.phpstub');
|
$psalm->addStubFile(__DIR__ . '/../stubs/TestCase.phpstub');
|
||||||
@ -24,16 +21,4 @@ class Plugin implements PluginEntryPointInterface
|
|||||||
class_exists(Hooks\TestCaseHandler::class, true);
|
class_exists(Hooks\TestCaseHandler::class, true);
|
||||||
$psalm->registerHooksFromClass(Hooks\TestCaseHandler::class);
|
$psalm->registerHooksFromClass(Hooks\TestCaseHandler::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function packageVersionIs(string $package, string $op, string $ref): bool
|
|
||||||
{
|
|
||||||
$currentVersion = (string) explode('@', Versions::getVersion($package))[0];
|
|
||||||
|
|
||||||
$parser = new VersionParser();
|
|
||||||
|
|
||||||
$currentVersion = $parser->normalize($currentVersion);
|
|
||||||
$ref = $parser->normalize($ref);
|
|
||||||
|
|
||||||
return Comparator::compare($currentVersion, $op, $ref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use PackageVersions\Versions;
|
|||||||
|
|
||||||
class Acceptance extends \Codeception\Module
|
class Acceptance extends \Codeception\Module
|
||||||
{
|
{
|
||||||
/** @var array<string,string */
|
/** @var array<string,string> */
|
||||||
public const VERSION_OPERATORS = [
|
public const VERSION_OPERATORS = [
|
||||||
'newer than' => '>',
|
'newer than' => '>',
|
||||||
'older than' => '<',
|
'older than' => '<',
|
||||||
|
Loading…
Reference in New Issue
Block a user