1
0
Fork 0

Add types to `Plugin` (#10194)

pull/10211/head
Martin Herndl 2021-10-25 11:02:54 +02:00 committed by GitHub
parent a921d9b233
commit aa4c2ab63c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 19 deletions

View File

@ -45,8 +45,8 @@ class CommandEvent extends Event
* @param string $commandName The command name * @param string $commandName The command name
* @param InputInterface $input * @param InputInterface $input
* @param OutputInterface $output * @param OutputInterface $output
* @param array $args Arguments passed by the user * @param mixed[] $args Arguments passed by the user
* @param array $flags Optional flags to pass data not as argument * @param mixed[] $flags Optional flags to pass data not as argument
*/ */
public function __construct($name, $commandName, $input, $output, array $args = array(), array $flags = array()) public function __construct($name, $commandName, $input, $output, array $args = array(), array $flags = array())
{ {

View File

@ -73,6 +73,8 @@ class PluginManager
/** /**
* Loads all plugins from currently installed plugin packages * Loads all plugins from currently installed plugin packages
*
* @return void
*/ */
public function loadInstalledPlugins() public function loadInstalledPlugins()
{ {
@ -91,7 +93,7 @@ class PluginManager
/** /**
* Gets all currently active plugin instances * Gets all currently active plugin instances
* *
* @return array plugins * @return array<PluginInterface> plugins
*/ */
public function getPlugins() public function getPlugins()
{ {
@ -118,6 +120,8 @@ class PluginManager
* @param bool $failOnMissingClasses By default this silently skips plugins that can not be found, but if set to true it fails with an exception * @param bool $failOnMissingClasses By default this silently skips plugins that can not be found, but if set to true it fails with an exception
* @param bool $isGlobalPlugin Set to true to denote plugins which are installed in the global Composer directory * @param bool $isGlobalPlugin Set to true to denote plugins which are installed in the global Composer directory
* *
* @return void
*
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
public function registerPackage(PackageInterface $package, $failOnMissingClasses = false, $isGlobalPlugin = false) public function registerPackage(PackageInterface $package, $failOnMissingClasses = false, $isGlobalPlugin = false)
@ -242,6 +246,8 @@ class PluginManager
* *
* @param PackageInterface $package * @param PackageInterface $package
* *
* @return void
*
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
public function deactivatePackage(PackageInterface $package) public function deactivatePackage(PackageInterface $package)
@ -276,6 +282,8 @@ class PluginManager
* *
* @param PackageInterface $package * @param PackageInterface $package
* *
* @return void
*
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
public function uninstallPackage(PackageInterface $package) public function uninstallPackage(PackageInterface $package)
@ -318,7 +326,10 @@ class PluginManager
* to do it. * to do it.
* *
* @param PluginInterface $plugin plugin instance * @param PluginInterface $plugin plugin instance
* @param bool $isGlobalPlugin
* @param ?PackageInterface $sourcePackage Package from which the plugin comes from * @param ?PackageInterface $sourcePackage Package from which the plugin comes from
*
* @return void
*/ */
public function addPlugin(PluginInterface $plugin, $isGlobalPlugin = false, PackageInterface $sourcePackage = null) public function addPlugin(PluginInterface $plugin, $isGlobalPlugin = false, PackageInterface $sourcePackage = null)
{ {
@ -346,6 +357,8 @@ class PluginManager
* to do it. * to do it.
* *
* @param PluginInterface $plugin plugin instance * @param PluginInterface $plugin plugin instance
*
* @return void
*/ */
public function removePlugin(PluginInterface $plugin) public function removePlugin(PluginInterface $plugin)
{ {
@ -369,6 +382,8 @@ class PluginManager
* to do it. * to do it.
* *
* @param PluginInterface $plugin plugin instance * @param PluginInterface $plugin plugin instance
*
* @return void
*/ */
public function uninstallPlugin(PluginInterface $plugin) public function uninstallPlugin(PluginInterface $plugin)
{ {
@ -386,6 +401,9 @@ class PluginManager
* call this method as early as possible. * call this method as early as possible.
* *
* @param RepositoryInterface $repo Repository to scan for plugins to install * @param RepositoryInterface $repo Repository to scan for plugins to install
* @param bool $isGlobalRepo
*
* @return void
* *
* @throws \RuntimeException * @throws \RuntimeException
*/ */
@ -409,11 +427,11 @@ class PluginManager
/** /**
* Recursively generates a map of package names to packages for all deps * Recursively generates a map of package names to packages for all deps
* *
* @param InstalledRepository $installedRepo Set of local repos * @param InstalledRepository $installedRepo Set of local repos
* @param array $collected Current state of the map for recursion * @param array<string, PackageInterface> $collected Current state of the map for recursion
* @param PackageInterface $package The package to analyze * @param PackageInterface $package The package to analyze
* *
* @return array Map of package names to packages * @return array<string, PackageInterface> Map of package names to packages
*/ */
private function collectDependencies(InstalledRepository $installedRepo, array $collected, PackageInterface $package) private function collectDependencies(InstalledRepository $installedRepo, array $collected, PackageInterface $package)
{ {
@ -479,7 +497,7 @@ class PluginManager
* @param PluginInterface $plugin * @param PluginInterface $plugin
* @param class-string<CapabilityClass> $capabilityClassName The fully qualified name of the API interface which the plugin may provide * @param class-string<CapabilityClass> $capabilityClassName The fully qualified name of the API interface which the plugin may provide
* an implementation of. * an implementation of.
* @param array $ctorArgs Arguments passed to Capability's constructor. * @param array<mixed> $ctorArgs Arguments passed to Capability's constructor.
* Keeping it an array will allow future values to be passed w\o changing the signature. * Keeping it an array will allow future values to be passed w\o changing the signature.
* @return null|Capability * @return null|Capability
* @phpstan-param class-string<CapabilityClass> $capabilityClassName * @phpstan-param class-string<CapabilityClass> $capabilityClassName
@ -512,7 +530,7 @@ class PluginManager
* @template CapabilityClass of Capability * @template CapabilityClass of Capability
* @param class-string<CapabilityClass> $capabilityClassName The fully qualified name of the API interface which the plugin may provide * @param class-string<CapabilityClass> $capabilityClassName The fully qualified name of the API interface which the plugin may provide
* an implementation of. * an implementation of.
* @param array $ctorArgs Arguments passed to Capability's constructor. * @param array<mixed> $ctorArgs Arguments passed to Capability's constructor.
* Keeping it an array will allow future values to be passed w\o changing the signature. * Keeping it an array will allow future values to be passed w\o changing the signature.
* @return CapabilityClass[] * @return CapabilityClass[]
*/ */

View File

@ -92,6 +92,8 @@ class PreFileDownloadEvent extends Event
* Sets the processed URL that will be downloaded. * Sets the processed URL that will be downloaded.
* *
* @param string $processedUrl New processed URL * @param string $processedUrl New processed URL
*
* @return void
*/ */
public function setProcessedUrl($processedUrl) public function setProcessedUrl($processedUrl)
{ {
@ -112,6 +114,8 @@ class PreFileDownloadEvent extends Event
* Sets a custom package cache key for this download. * Sets a custom package cache key for this download.
* *
* @param string|null $customCacheKey New cache key * @param string|null $customCacheKey New cache key
*
* @return void
*/ */
public function setCustomCacheKey($customCacheKey) public function setCustomCacheKey($customCacheKey)
{ {
@ -146,7 +150,7 @@ class PreFileDownloadEvent extends Event
* *
* Only available for events with type metadata, for packages set the transport options on the package itself. * Only available for events with type metadata, for packages set the transport options on the package itself.
* *
* @return array * @return mixed[]
*/ */
public function getTransportOptions() public function getTransportOptions()
{ {
@ -158,7 +162,9 @@ class PreFileDownloadEvent extends Event
* *
* Only available for events with type metadata, for packages set the transport options on the package itself. * Only available for events with type metadata, for packages set the transport options on the package itself.
* *
* @param array $options * @param mixed[] $options
*
* @return void
*/ */
public function setTransportOptions(array $options) public function setTransportOptions(array $options)
{ {

View File

@ -160,6 +160,8 @@ class PrePoolCreateEvent extends Event
/** /**
* @param BasePackage[] $packages * @param BasePackage[] $packages
*
* @return void
*/ */
public function setPackages(array $packages) public function setPackages(array $packages)
{ {
@ -168,6 +170,8 @@ class PrePoolCreateEvent extends Event
/** /**
* @param BasePackage[] $packages * @param BasePackage[] $packages
*
* @return void
*/ */
public function setUnacceptableFixedPackages(array $packages) public function setUnacceptableFixedPackages(array $packages)
{ {

View File

@ -144,7 +144,7 @@ class PluginInstallerTest extends TestCase
$installer->install($this->repository, $this->packages[0]); $installer->install($this->repository, $this->packages[0]);
$plugins = $this->pm->getPlugins(); $plugins = $this->pm->getPlugins();
$this->assertEquals('installer-v1', $plugins[0]->version); $this->assertEquals('installer-v1', $plugins[0]->version); // @phpstan-ignore-line
$this->assertEquals('activate v1'.PHP_EOL, $this->io->getOutput()); $this->assertEquals('activate v1'.PHP_EOL, $this->io->getOutput());
} }
@ -160,10 +160,10 @@ class PluginInstallerTest extends TestCase
$installer->install($this->repository, $this->packages[3]); $installer->install($this->repository, $this->packages[3]);
$plugins = $this->pm->getPlugins(); $plugins = $this->pm->getPlugins();
$this->assertEquals('plugin1', $plugins[0]->name); $this->assertEquals('plugin1', $plugins[0]->name); // @phpstan-ignore-line
$this->assertEquals('installer-v4', $plugins[0]->version); $this->assertEquals('installer-v4', $plugins[0]->version); // @phpstan-ignore-line
$this->assertEquals('plugin2', $plugins[1]->name); $this->assertEquals('plugin2', $plugins[1]->name); // @phpstan-ignore-line
$this->assertEquals('installer-v4', $plugins[1]->version); $this->assertEquals('installer-v4', $plugins[1]->version); // @phpstan-ignore-line
$this->assertEquals('activate v4-plugin1'.PHP_EOL.'activate v4-plugin2'.PHP_EOL, $this->io->getOutput()); $this->assertEquals('activate v4-plugin1'.PHP_EOL.'activate v4-plugin2'.PHP_EOL, $this->io->getOutput());
} }
@ -184,7 +184,7 @@ class PluginInstallerTest extends TestCase
$plugins = $this->pm->getPlugins(); $plugins = $this->pm->getPlugins();
$this->assertCount(1, $plugins); $this->assertCount(1, $plugins);
$this->assertEquals('installer-v2', $plugins[1]->version); $this->assertEquals('installer-v2', $plugins[1]->version); // @phpstan-ignore-line
$this->assertEquals('activate v1'.PHP_EOL.'deactivate v1'.PHP_EOL.'activate v2'.PHP_EOL, $this->io->getOutput()); $this->assertEquals('activate v1'.PHP_EOL.'deactivate v1'.PHP_EOL.'activate v2'.PHP_EOL, $this->io->getOutput());
} }
@ -224,7 +224,7 @@ class PluginInstallerTest extends TestCase
$installer->update($this->repository, $this->packages[1], $this->packages[2]); $installer->update($this->repository, $this->packages[1], $this->packages[2]);
$plugins = $this->pm->getPlugins(); $plugins = $this->pm->getPlugins();
$this->assertEquals('installer-v3', $plugins[1]->version); $this->assertEquals('installer-v3', $plugins[1]->version); // @phpstan-ignore-line
$this->assertEquals('activate v2'.PHP_EOL.'deactivate v2'.PHP_EOL.'activate v3'.PHP_EOL, $this->io->getOutput()); $this->assertEquals('activate v2'.PHP_EOL.'deactivate v2'.PHP_EOL.'activate v3'.PHP_EOL, $this->io->getOutput());
} }
@ -242,7 +242,7 @@ class PluginInstallerTest extends TestCase
$plugins = $this->pm->getPlugins(); $plugins = $this->pm->getPlugins();
$this->assertCount(1, $plugins); $this->assertCount(1, $plugins);
$this->assertEquals('installer-v1', $plugins[0]->version); $this->assertEquals('installer-v1', $plugins[0]->version); // @phpstan-ignore-line
$this->assertEquals('activate v1'.PHP_EOL, $this->io->getOutput()); $this->assertEquals('activate v1'.PHP_EOL, $this->io->getOutput());
} }