Skip to content

Commit 8adf2a1

Browse files
jasnyDavertMik
authored andcommitted
Only run installer on an operation on c3 (#29)
Checks '*/c3' and not 'codeception/c3' so forks will keep working.
1 parent 47842d2 commit 8adf2a1

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Diff for: Installer.php

+19-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Composer\Plugin\PluginInterface;
77
use Composer\Script\Event;
88
use Composer\Script\ScriptEvents;
9+
use Composer\Installer\PackageEvent;
910

1011
class Installer implements PluginInterface, EventSubscriberInterface
1112
{
@@ -18,7 +19,14 @@ public function activate(Composer $composer, IOInterface $io)
1819
{
1920
$this->io = $io;
2021
}
21-
22+
23+
protected function isOperationOnC3(PackageEvent $event)
24+
{
25+
list(, $name) = explode('/', $event->getOperation()->getPackage()->getName());
26+
27+
return $name === 'c3';
28+
}
29+
2230
public static function getSubscribedEvents()
2331
{
2432
return [
@@ -40,8 +48,11 @@ public static function copyC3ToRoot(Event $event)
4048
$event->getIO()->write("<warning>Please remove current \"post-install-cmd\" and \"post-update-cmd\" hooks from your composer.json</warning>");
4149
}
4250

43-
public function copyC3()
51+
public function copyC3(PackageEvent $event)
4452
{
53+
if (!$this->isOperationOnC3($event)) {
54+
return;
55+
}
4556
if ($this->c3NotChanged()) {
4657
$this->io->write("<comment>[codeception/c3]</comment> c3.php is already up-to-date");
4758
return;
@@ -52,9 +63,9 @@ public function copyC3()
5263
$this->io->write("<comment>[codeception/c3]</comment> Include c3.php into index.php in order to collect codecoverage from server scripts");
5364
}
5465

55-
public function askForUpdate()
66+
public function askForUpdate(PackageEvent $event)
5667
{
57-
if ($this->c3NotChanged()) {
68+
if (!$this->isOperationOnC3($event) || $this->c3NotChanged()) {
5869
return;
5970
}
6071
if (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'c3.php')) {
@@ -72,12 +83,14 @@ private function c3NotChanged()
7283
md5_file(__DIR__ . DIRECTORY_SEPARATOR . 'c3.php') === md5_file(getcwd() . DIRECTORY_SEPARATOR . 'c3.php');
7384
}
7485

75-
public function deleteC3()
86+
public function deleteC3(PackageEvent $event)
7687
{
88+
if (!$this->isOperationOnC3($event)) {
89+
return;
90+
}
7791
if (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'c3.php')) {
7892
$this->io->write("<comment>[codeception/c3]</comment> Deleting c3.php from the root of your project...");
7993
unlink(getcwd() . DIRECTORY_SEPARATOR . 'c3.php');
8094
}
8195
}
8296
}
83-

0 commit comments

Comments
 (0)