Skip to content

Commit

Permalink
Fix phpstan feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Dec 8, 2020
1 parent 76d45b0 commit 26f3f0f
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 47 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"composer/semver": "^1 || ^3",
"symfony/phpunit-bridge": "^4.2 || ^5",
"phpstan/phpstan": "^0.12.55",
"symfony/process": "^2.3"
"symfony/process": "^2.3",
"phpstan/phpstan-phpunit": "^0.12.16"
},
"scripts": {
"test": "SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit",
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ parameters:
paths:
- src
- tests

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
4 changes: 2 additions & 2 deletions src/Composer/Installers/BaseInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function getInstallPath(PackageInterface $package, $frameworkType = '')
/**
* For an installer to override to modify the vars per installer.
*
* @param array{name: string, vendor: string, type: string} $vars
* @return array{name: string, vendor: string, type: string}
* @param array<string, string> $vars This will normally receive array{name: string, vendor: string, type: string}
* @return array<string, string>
*/
public function inflectPackageVars($vars)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Composer/Installers/Test/BitrixInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ final function setUp()
}

/**
* @param string $vars
* @param string $expectedVars
* @param string[] $vars
* @param string[] $expectedVars
*
* @covers ::inflectPackageVars
*
Expand Down
9 changes: 7 additions & 2 deletions tests/Composer/Installers/Test/CakePHPInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@

class CakePHPInstallerTest extends TestCase
{
/**
* @var Composer
*/
private $composer;
private $io;
/**
* @var Package
*/
private $package;

/**
* setUp
Expand All @@ -23,7 +29,6 @@ class CakePHPInstallerTest extends TestCase
public function setUp()
{
$this->package = new Package('CamelCased', '1.0', '1.0');
$this->io = $this->getMockBuilder('Composer\IO\PackageInterface')->getMock();
$this->composer = new Composer();
$this->composer->setConfig(new Config(false));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/Installers/Test/CiviCrmInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class CiviCrmInstallerTest extends BaseTestCase
{
/**
* @var VgmcpInstaller
* @var CiviCrmInstaller
*/
private $installer;

Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/Installers/Test/GravInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testInflectPackageVars()
}

/**
* @param $package \Composer\Package\PackageInterface
* @param \Composer\Package\PackageInterface $package
*/
public function getPackageVars($package)
{
Expand Down
22 changes: 0 additions & 22 deletions tests/Composer/Installers/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,26 +660,4 @@ public function dataForTestDisabledInstallers()
array(array("drupal", "true"), "cakephp-plugin", true),
);
}

/**
* @param string $exception
* @param string|null $message
* @param int|null $code
* @return void
*/
public function setExpectedException($exception, $message = null, $code = null)
{
if (!class_exists('PHPUnit\Framework\Error\Notice')) {
$exception = str_replace('PHPUnit\\Framework\\Error\\', 'PHPUnit_Framework_Error_', $exception);
}
if (method_exists($this, 'expectException')) {
$this->expectException($exception);
if (null !== $message) {
$this->expectExceptionMessage($message);
}
} else {
/** @phpstan-ignore-next-line */
parent::setExpectedException($exception, $message, $code);
}
}
}
2 changes: 1 addition & 1 deletion tests/Composer/Installers/Test/PimcoreInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class PimcoreInstallerTest extends TestCase
{
private $composer;
private $io;
private $package;

/**
* setUp
Expand All @@ -18,7 +19,6 @@ class PimcoreInstallerTest extends TestCase
public function setUp()
{
$this->package = new Package('CamelCased', '1.0', '1.0');
$this->io = $this->getMockBuilder('Composer\IO\PackageInterface')->getMock();
$this->composer = new Composer();
}

Expand Down
6 changes: 0 additions & 6 deletions tests/Composer/Installers/Test/PiwikInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ class PiwikInstallerTest extends TestCase
*/
private $composer;

/**
* @var PackageInterface
*/
private $io;

/**
* @var Package
*/
Expand All @@ -36,7 +31,6 @@ class PiwikInstallerTest extends TestCase
public function setUp()
{
$this->package = new Package('VisitSummary', '1.0', '1.0');
$this->io = $this->getMockBuilder('Composer\IO\PackageInterface')->getMock();
$this->composer = new Composer();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/Installers/Test/SiteDirectInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testInstallPath($data, $expected)
}

/**
* @param $data
* @param string[] $data
* @return string
*/
private function createPackage($data)
Expand Down
26 changes: 24 additions & 2 deletions tests/Composer/Installers/Test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Composer\Package\Version\VersionParser;
use Composer\Package\Package;
use Composer\Package\AliasPackage;
use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Semver\Constraint\Constraint;
use Composer\Util\Filesystem;
use PHPUnit\Framework\TestCase as BaseTestCase;

Expand All @@ -34,7 +34,7 @@ protected static function getVersionParser()

protected function getVersionConstraint($operator, $version)
{
return new VersionConstraint(
return new Constraint(
$operator,
self::getVersionParser()->normalize($version)
);
Expand Down Expand Up @@ -62,4 +62,26 @@ protected function ensureDirectoryExistsAndClear($directory)
}
mkdir($directory, 0777, true);
}

/**
* @param string $exception
* @param string|null $message
* @param int|null $code
* @return void
*/
public function setExpectedException($exception, $message = null, $code = null)
{
if (!class_exists('PHPUnit\Framework\Error\Notice')) {
$exception = str_replace('PHPUnit\\Framework\\Error\\', 'PHPUnit_Framework_Error_', $exception);
}
if (method_exists($this, 'expectException')) {
$this->expectException($exception);
if (null !== $message) {
$this->expectExceptionMessage($message);
}
} else {
/** @phpstan-ignore-next-line */
parent::setExpectedException($exception, $message, $code);
}
}
}
6 changes: 0 additions & 6 deletions tests/Composer/Installers/Test/YawikInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ class YawikInstallerTest extends TestCase
*/
private $composer;

/**
* @var PackageInterface
*/
private $io;

/**
* @var Package
*/
Expand All @@ -36,7 +31,6 @@ class YawikInstallerTest extends TestCase
public function setUp()
{
$this->package = new Package('YawikCompanyRegistration', '1.0', '1.0');
$this->io = $this->getMockBuilder('Composer\IO\PackageInterface')->getMock();
$this->composer = new Composer();
}

Expand Down

0 comments on commit 26f3f0f

Please sign in to comment.