Skip to content

Commit

Permalink
Make properties private
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianfeldmann committed Dec 13, 2020
1 parent 62334fa commit 4ce2670
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/ConfiguredMediator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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>WARNING</warning>' . PHP_EOL .
' No GPG installation found! Use installed PHARs with care. ' . PHP_EOL .
Expand Down Expand Up @@ -77,7 +76,7 @@ private function createInstallerFromConfig(Config $config, PackageEvent $event):
{
return new Installer(
$config->package(),
$this->io,
$this->getIO(),
$event
);
}
Expand All @@ -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);
Expand All @@ -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 <info>%1$s</info>', $phar->pharName()));
$this->getIO()->write(sprintf(' - Removing phar <info>%1$s</info>', $phar->pharName()));
unlink($pharLocation);
}
}
Expand Down
22 changes: 19 additions & 3 deletions src/PluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 4ce2670

Please sign in to comment.