#6 Composer 2 support

Отворено
fgm жели да споји 2 комит(е) из fgm/composer2 у fgm/main

+ 2 - 1
.gitignore

@@ -1,5 +1,6 @@
 /.idea/
 /.phpunit.cache
 /composer.lock
-/coverage
+/coverage/*
+!/coverage/.gitkeep
 /vendor/

+ 4 - 1
README.md

@@ -3,10 +3,13 @@
 ## License
 
 The plugin is licensed under the General Public License version 2.0 or later,
-just like the Drupal code it embeds.
+just like the Drupal derived code it embeds in `MergeParamsCommand`.
 
 ## Changes
 
+- 0.2.0
+  - Composer 2 compatibility in addition to Composer 1
+  - PHP 8 support
 - 0.1.3 
   - `mergeDeepArray` moved from `NestedArray` to `MergeParamsCommand` to
     avoid confusion with the Drupal version.

+ 6 - 5
composer.json

@@ -25,16 +25,17 @@
   "name": "fgm/drupal_composer_builder",
   "prefer-stable": true,
   "require": {
-    "composer-plugin-api": "^1.1",
-    "composer/installers": "^1.2"
+    "php": "^7.4 || ^8",
+    "composer-plugin-api": "^1.1 || ^2.0.0",
+    "composer/installers": "^1.12"
   },
   "require-dev": {
-    "composer/composer": "^1",
+    "composer/composer": "^2.1",
     "dealerdirect/phpcodesniffer-composer-installer": "dev-master",
-    "drupal/coder": "^8.3.6",
+    "drupal/coder": "^8.3.13",
     "phpstan/phpstan": "^0.12.99",
     "phpunit/phpunit": "^9.5",
-    "squizlabs/php_codesniffer": "^3.0@dev",
+    "squizlabs/php_codesniffer": "^3.6",
     "twig/twig": "^1"
   },
   "scripts": {

+ 0 - 0
coverage/.gitkeep


+ 9 - 5
src/BaseBuilderCommand.php

@@ -4,6 +4,8 @@ declare(strict_types=1);
 
 namespace Fgm\Drupal\Composer;
 
+require_once __DIR__ . '/../../../../vendor/autoload.php';
+
 use Composer\Command\BaseCommand;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
@@ -45,7 +47,7 @@ abstract class BaseBuilderCommand extends BaseCommand {
    * @param \Symfony\Component\Console\Output\OutputInterface $output
    *   Command output.
    * @param string $buildName
-   *   The nature of the build: services, settings, etc.
+   *   The template name as a composer.json extra section.
    *
    * @return array
    *   - string Template name
@@ -59,10 +61,12 @@ abstract class BaseBuilderCommand extends BaseCommand {
     $conf = $this->getComposer()->getPackage()->getExtra()[Builder::NAME] ?? [];
     $templateName = $conf['templates'][$buildName] ?? '';
     if (empty($templateName)) {
-      $output->writeln(sprintf(
-        'Could not build file %s: no such template in composer.json extra section',
-        $buildName
-      ));
+      $output->writeln(
+        sprintf(
+          'Could not build file %s: no such template in composer.json extra section',
+          $buildName
+        )
+      );
       return ["", 1];
     }
     return [$templateName, 0];

+ 14 - 1
src/Builder.php

@@ -1,6 +1,6 @@
 <?php
 
-declare(strict_types = 1);
+declare(strict_types=1);
 
 namespace Fgm\Drupal\Composer;
 
@@ -99,4 +99,17 @@ class Builder implements Capable, Capability, EventSubscriberInterface, PluginIn
     }
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function deactivate(Composer $composer, IOInterface $io) {
+    parent::deactivate($composer, $io);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function uninstall(Composer $composer, IOInterface $io) {
+  }
+
 }

+ 3 - 3
src/MergeParamsCommand.php

@@ -79,7 +79,7 @@ EOT
    *
    * {@inheritDoc}
    */
-  public function execute(InputInterface $input, OutputInterface $output) {
+  public function execute(InputInterface $input, OutputInterface $output): int {
     $settingsPath = $this->getSettingsPath();
     $yaml = new Yaml();
 
@@ -149,8 +149,8 @@ EOT
         // PHP automatically converts array keys that are integer strings
         // (e.g., '1') to integers.
         if (is_int($key)) {
-          // When an indexed array is overrided, the new values replace
-          // all overrided values (no merge).
+          // When an indexed array is overridden, the new values replace
+          // all overridden values (no merge).
           if ($key === 0) {
             $result = [];
           }

+ 11 - 8
src/PhpMemcacheAdminConfigCommand.php

@@ -65,11 +65,9 @@ class PhpMemcacheAdminConfigCommand extends BaseBuilderCommand {
     $this
       ->setName('build:phpmemcacheadmin')
       ->setDescription('Build the PhpMemcacheAdmin configuration.')
-      ->setDefinition(
-        new InputDefinition([
-          new InputArgument(static::ARG_FILE, InputArgument::OPTIONAL, '', static::BUILD_NAME),
-        ])
-      )
+      ->setDefinition(new InputDefinition([
+        new InputArgument(static::ARG_FILE, InputArgument::OPTIONAL, '', static::BUILD_NAME),
+      ]))
       ->setHelp(
         <<<EOT
 The build:phpmemcacheadmin command uses the memcache section of the site parameters
@@ -143,9 +141,14 @@ EOT
       ->getRepositoryManager()
       ->getLocalRepository()
       ->getPackages();
-    $package = current(array_filter($packages, function (PackageInterface $package) {
-      return $package->getName() === static::PACKAGE;
-    }));
+    $package = current(
+      array_filter(
+        $packages,
+        function (PackageInterface $package) {
+          return $package->getName() === static::PACKAGE;
+        }
+      )
+    );
     $targetBase = $composer
       ->getInstallationManager()
       ->getInstallPath($package);

+ 1 - 1
tests/MergeParamsCommandTest.php

@@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase;
 final class MergeParamsCommandTest extends TestCase {
 
   /**
-   * Test MergeParamsCommand::merge().
+   * Test MergeParamsCommand::mergeDeepArray().
    *
    * @covers \Fgm\Drupal\Composer\MergeParamsCommand::mergeDeepArray
    */