diff --git a/src/ConfiguredMediator.php b/src/ConfiguredMediator.php
index 37b42d1..e8819e3 100644
--- a/src/ConfiguredMediator.php
+++ b/src/ConfiguredMediator.php
@@ -34,8 +34,7 @@ abstract protected function getDistributorConfig(): string;
public function uninstall(Composer $composer, IOInterface $io)
{
- $this->composer = $composer;
- $this->io = $io;
+ parent::uninstall($composer, $io);
$this->removePhars();
}
@@ -45,7 +44,7 @@ public function installOrUpdateFunction(PackageEvent $event): void
// we do not want to crash if no GnuPG was found
// but display a noticeable warning to the user
if ($gnuPG === null) {
- $this->io->write(
+ $this->getIO()->write(
PHP_EOL .
' WARNING' . PHP_EOL .
' No GPG installation found! Use installed PHARs with care. ' . PHP_EOL .
@@ -77,7 +76,7 @@ private function createInstallerFromConfig(Config $config, PackageEvent $event):
{
return new Installer(
$config->package(),
- $this->io,
+ $this->getIO(),
$event
);
}
@@ -99,7 +98,7 @@ private function createKeyDirectory(Config $config): KeyDirectory
private function removePhars(): void
{
- $binDir = $this->composer->getConfig()->get('bin-dir');
+ $binDir = $this->getComposer()->getConfig()->get('bin-dir');
foreach ($this->config->phars()->getList() as $phar) {
$this->deleteFile($phar, $binDir);
@@ -112,12 +111,12 @@ private function deleteFile(File $phar, string $binDir): void
if (is_file($pharLocation)) {
if (!is_writable($pharLocation)) {
- $this->io->write(
+ $this->getIO()->write(
sprintf(' - Can not remove phar \'%1$s\' (insufficient permissions)', $phar->pharName())
);
return;
}
- $this->io->write(sprintf(' - Removing phar %1$s', $phar->pharName()));
+ $this->getIO()->write(sprintf(' - Removing phar %1$s', $phar->pharName()));
unlink($pharLocation);
}
}
diff --git a/src/PluginBase.php b/src/PluginBase.php
index 65d41a8..05bd366 100644
--- a/src/PluginBase.php
+++ b/src/PluginBase.php
@@ -15,10 +15,12 @@
abstract class PluginBase implements PluginInterface, EventSubscriberInterface
{
/** @var \Composer\Composer */
- protected $composer;
+ private $composer;
/** @var \Composer\IO\IOInterface */
- protected $io;
+ private $io;
+
+ abstract public function installOrUpdateFunction(PackageEvent $event) : void;
public function activate(Composer $composer, IOInterface $io)
{
@@ -59,5 +61,19 @@ public function createInstaller(string $pluginName, PackageEvent $event) : Insta
);
}
- abstract public function installOrUpdateFunction(PackageEvent $event) : void;
+ protected function getIO(): IOInterface
+ {
+ if (!$this->io) {
+ throw new \RuntimeException('IO not set');
+ }
+ return $this->io;
+ }
+
+ protected function getComposer(): Composer
+ {
+ if (!$this->composer) {
+ throw new \RuntimeException('Composer not set');
+ }
+ return $this->composer;
+ }
}