Skip to content

Commit 8daa796

Browse files
committed
Drop composer 1.x support
1 parent ab7cf5e commit 8daa796

File tree

7 files changed

+48
-111
lines changed

7 files changed

+48
-111
lines changed

.github/workflows/CI.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ jobs:
3636
sudo apt-add-repository ppa:ondrej/php -y
3737
sudo apt-fast install -y --no-install-recommends php${{ matrix.php }}-ast
3838
39-
- name: Use Composer v1
40-
run: composer require --dev --no-update composer/composer:^1.1
41-
42-
- name: Print Composer version
43-
run: composer --version
44-
45-
- name: composer install
46-
run: composer update --no-interaction --no-progress --ansi
47-
48-
- run: composer test
49-
5039
- name: Use Composer v2
5140
run: composer require --dev --no-update composer/composer:^2.0
5241

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Composer Merge Plugin 1.4.x (and older) requires Composer 1.x.
2828

2929
Composer Merge Plugin 2.0.x (and newer) is compatible with both Composer 2.x and 1.x.
3030

31+
Composer Merge Plugin 3.0.x (and newer) is requires Composer 2.x.
32+
3133
```
3234
$ composer require wikimedia/composer-merge-plugin
3335
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"prefer-stable": true,
1414
"require": {
1515
"php": ">=7.4.0",
16-
"composer-plugin-api": "^1.1||^2.0"
16+
"composer-plugin-api": "^2.0"
1717
},
1818
"require-dev": {
1919
"ext-json": "*",

src/ExtraPackage.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ protected function mergeOrDefer(
326326
}
327327
}
328328

329-
if (!$state->isComposer1()) {
330-
Intervals::clear();
331-
}
329+
Intervals::clear();
332330

333331
return $origin;
334332
}
@@ -348,18 +346,14 @@ protected function mergeConstraints(Link $origin, Link $merge, PluginState $stat
348346
$oldPrettyString = $origin->getConstraint()->getPrettyString();
349347
$newPrettyString = $merge->getConstraint()->getPrettyString();
350348

351-
if ($state->isComposer1()) {
352-
$constraintClass = MultiConstraint::class;
353-
} else {
354-
$constraintClass = \Composer\Semver\Constraint\MultiConstraint::class;
349+
$constraintClass = \Composer\Semver\Constraint\MultiConstraint::class;
355350

356-
if (Intervals::isSubsetOf($origin->getConstraint(), $merge->getConstraint())) {
357-
return $origin;
358-
}
351+
if (Intervals::isSubsetOf($origin->getConstraint(), $merge->getConstraint())) {
352+
return $origin;
353+
}
359354

360-
if (Intervals::isSubsetOf($merge->getConstraint(), $origin->getConstraint())) {
361-
return $merge;
362-
}
355+
if (Intervals::isSubsetOf($merge->getConstraint(), $origin->getConstraint())) {
356+
return $merge;
363357
}
364358

365359
$newConstraint = $constraintClass::create([

src/MergePlugin.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,13 @@ public function onPostInstallOrUpdate(ScriptEvent $event)
343343

344344
$lockBackup = null;
345345
$lock = null;
346-
if (!$this->state->isComposer1()) {
347-
$file = Factory::getComposerFile();
348-
$lock = Factory::getLockFile($file);
349-
if (file_exists($lock)) {
350-
$lockBackup = file_get_contents($lock);
351-
}
346+
$file = Factory::getComposerFile();
347+
$lock = Factory::getLockFile($file);
348+
if (file_exists($lock)) {
349+
$lockBackup = file_get_contents($lock);
352350
}
353351

352+
354353
$config = $this->composer->getConfig();
355354
$preferSource = $config->get('preferred-install') === 'source';
356355
$preferDist = $config->get('preferred-install') === 'dist';
@@ -371,17 +370,10 @@ public function onPostInstallOrUpdate(ScriptEvent $event)
371370
);
372371

373372
$installer->setUpdate(true);
374-
375-
if ($this->state->isComposer1()) {
376-
// setUpdateWhitelist() only exists in composer 1.x. Configure as to run phan against composer 2.x
377-
// @phan-suppress-next-line PhanUndeclaredMethod
378-
$installer->setUpdateWhitelist($requirements);
379-
} else {
380-
$installer->setUpdateAllowList($requirements);
381-
}
373+
$installer->setUpdateAllowList($requirements);
382374

383375
$status = $installer->run();
384-
if (( $status !== 0 ) && $lockBackup && $lock && !$this->state->isComposer1()) {
376+
if (( $status !== 0 ) && $lockBackup && $lock) {
385377
$this->logger->log(
386378
"\n".'<error>'.
387379
'Update to apply merge settings failed, reverting '.$lock.' to its original content.'.

src/PluginState.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ class PluginState
2525
*/
2626
protected $composer;
2727

28-
/**
29-
* @var bool $isComposer1
30-
*/
31-
protected $isComposer1;
32-
3328
/**
3429
* @var array $includes
3530
*/
@@ -138,17 +133,6 @@ class PluginState
138133
public function __construct(Composer $composer)
139134
{
140135
$this->composer = $composer;
141-
$this->isComposer1 = version_compare(PluginInterface::PLUGIN_API_VERSION, '2.0.0', '<');
142-
}
143-
144-
/**
145-
* Test if this plugin runs within Composer 1.
146-
*
147-
* @return bool
148-
*/
149-
public function isComposer1()
150-
{
151-
return $this->isComposer1;
152136
}
153137

154138
/**

tests/phpunit/MergePluginTest.php

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -596,24 +596,16 @@ function ($args) use ($that, $io) {
596596

597597
$config = new Config();
598598
$mockIO = $io->reveal();
599-
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
600-
return new VcsRepository(
601-
$args[1],
602-
$mockIO,
603-
$config
604-
);
605-
} else {
606-
$httpDownloader = new HttpDownloader(
607-
$mockIO,
608-
$config
609-
);
610-
return new VcsRepository(
611-
$args[1],
612-
$mockIO,
613-
$config,
614-
$httpDownloader
615-
);
616-
}
599+
$httpDownloader = new HttpDownloader(
600+
$mockIO,
601+
$config
602+
);
603+
return new VcsRepository(
604+
$args[1],
605+
$mockIO,
606+
$config,
607+
$httpDownloader
608+
);
617609
}
618610
);
619611
$repoManager->prependRepository(Argument::any())->will(
@@ -688,25 +680,17 @@ function ($args) use ($that, $io) {
688680

689681
$config = new Config();
690682
$mockIO = $io->reveal();
691-
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
692-
return new VcsRepository(
693-
$args[1],
694-
$mockIO,
695-
$config
696-
);
697-
} else {
698-
$httpDownloader = new HttpDownloader(
699-
$mockIO,
700-
$config
701-
);
702-
703-
return new VcsRepository(
704-
$args[1],
705-
$mockIO,
706-
$config,
707-
$httpDownloader
708-
);
709-
}
683+
$httpDownloader = new HttpDownloader(
684+
$mockIO,
685+
$config
686+
);
687+
688+
return new VcsRepository(
689+
$args[1],
690+
$mockIO,
691+
$config,
692+
$httpDownloader
693+
);
710694
}
711695
);
712696
$repoManager->prependRepository(Argument::any())->will(
@@ -1268,25 +1252,17 @@ public function testHasBranchAlias($fireInit)
12681252
)->will(function ($args) use ($io) {
12691253
$config = new Config();
12701254
$mockIO = $io->reveal();
1271-
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
1272-
return new VcsRepository(
1273-
$args[1],
1274-
$mockIO,
1275-
$config
1276-
);
1277-
} else {
1278-
$httpDownloader = new HttpDownloader(
1279-
$mockIO,
1280-
$config
1281-
);
1255+
$httpDownloader = new HttpDownloader(
1256+
$mockIO,
1257+
$config
1258+
);
12821259

1283-
return new VcsRepository(
1284-
$args[1],
1285-
$mockIO,
1286-
$config,
1287-
$httpDownloader
1288-
);
1289-
}
1260+
return new VcsRepository(
1261+
$args[1],
1262+
$mockIO,
1263+
$config,
1264+
$httpDownloader
1265+
);
12901266
});
12911267
$repoManager->prependRepository(Argument::any())->shouldBeCalled();
12921268
$this->composer->getRepositoryManager()->will(

0 commit comments

Comments
 (0)