psalm-plugin-phpunit/Plugin.php
2019-02-11 05:31:13 +02:00

38 lines
1.2 KiB
PHP
Executable File

<?php
namespace Psalm\PhpUnitPlugin;
use Composer\Semver\Comparator;
use Composer\Semver\VersionParser;
use Muglug\PackageVersions\Versions;
use SimpleXMLElement;
use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Plugin\RegistrationInterface;
class Plugin implements PluginEntryPointInterface
{
/** @return void */
public function __invoke(RegistrationInterface $psalm, SimpleXMLElement $config = null)
{
$psalm->addStubFile(__DIR__ . '/stubs/Assert.php');
if ($this->packageVersionIs('phpunit/phpunit', '>=', '7.5')) {
$psalm->addStubFile(__DIR__ . '/stubs/Assert_75.php');
}
$psalm->addStubFile(__DIR__ . '/stubs/TestCase.php');
$psalm->addStubFile(__DIR__ . '/stubs/MockBuilder.php');
$psalm->addStubFile(__DIR__ . '/stubs/InvocationMocker.php');
$psalm->addStubFile(__DIR__ . '/stubs/Prophecy.php');
}
private function packageVersionIs(string $package, string $op, string $ref): bool
{
$currentVersion = (string) Versions::getShortVersion($package);
$parser = new VersionParser();
$currentVersion = $parser->normalize($currentVersion);
$ref = $parser->normalize($ref);
return Comparator::compare($currentVersion, $op, $ref);
}
}