Problem/Motivation

Composer package install for drupal/coder could be more complete by configuring the PHP Code Sniffer installed paths and default standard. Simplifying install encourages more people to use the standards checking tools, thereby improving the overall quality of contributed Drupal code.

Proposed resolution

  1. Use existing Composer Installer Plugins to configure PHP CodeSniffer.
  2. Update the README.

Remaining tasks

  1. Update the Drupal Handbook and Project pages to reflect the change.
  2. Add an example CircleCI and Travis build configuration to the Handbook.
CommentFileSizeAuthor
#2 configure_php_code-2848532-2.patch4.35 KBchOP
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chOP created an issue. See original summary.

chOP’s picture

I've raised a Pull Request against the Packagist source repository for drupal/coder. You can see that here:

Github klausi/coder #22

I can also paste the patch here for discussion. Not sure if you're using the Drupal/CVS workflow or Git/Github workflow.

chOP’s picture

Status: Active » Needs review
chOP’s picture

I've made some further changes to the initial patch, so refer to Github klausi/coder #22 for the up-to-date code.

chOP’s picture

I've closed that Pull Request, opting instead to use existing Composer Installer Plugins for the job. We could support use of this:

https://github.com/DealerDirect/phpcodesniffer-composer-installer

The Plugin does the configuration after install by looking for packages with the type: "phpcodesniffer-standard"

diff --git a/composer.json b/composer.json
index f80ac5a..08f54d3 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
 {
     "name": "drupal/coder",
-    "type": "library",
+    "type": "phpcodesniffer-standard",
     "description": "Coder is a library to review Drupal code.",
     "homepage": "https://www.drupal.org/project/coder",
     "support": {

Thoughts anyone? I'm using it now with this in my composer.json

  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/christopher-hopper/coder"
    },
    {
      "type": "vcs",
      "url": "https://github.com/christopher-hopper/phpcodesniffer-composer-installer"
    }
  ],
  "require": {
    "php": ">=5.4"
  },
  "require-dev": {
    "dealerdirect/phpcodesniffer-composer-installer": "dev-master",
    "drupal/coder": "dev-8.x-2.x"
  }
chOP’s picture

Issue summary: View changes
klausi’s picture

Thanks for the suggestions, this is a complicated topic. Solution in Drupal core: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Composer/Com...

Of course that is a per project solution, so does not help for a global install.

Your composer plugin would require that we move directories around in Coder, right? That might break configured existing installations, so would be something for Coder 9.

chOP’s picture

@klausi I managed to find a Composer Installer Plugin that does not require any change to the directory structure of Coder. It's called dealerdirect/phpcodesniffer-composer-installer and is very well supported and maintained. Works a treat.

The maintainers helped me/us out by accepting my pull request to get it working with Drupal Coder. This plugin (like any Composer Installer Plugin) requires that Coder use a Composer package type that it will recognise.

Change required

Changing the package type from "library" to "phpcodesniffer-standard" is all we'd need to do. One line in the composer.json. I'll submit a pull request for your consideration.

Changing the Composer package type for Coder should not affect users who aren't using an installer plugin.

Testing the change

Here's working examples to show how it works with the Coder package type changed. The custom repository is a clone of Drupal Coder, with the package type changed. Note the repositories additions below will not be required if the package type in Coder is changed as described above.

Project installs

To test for a project installation use a composer.json like this:

{
  "name": "example/project",
  "type": "metapackage",
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/christopher-hopper/coder"
    }
  ],
  "require": {
    "php": ">=5.4"
  },
  "require-dev": {
    "dealerdirect/phpcodesniffer-composer-installer": "dev-master",
    "drupal/coder": "dev-8.x-2.x"
  }
}

Global installs

To test the global installer follow these steps:

  1. Add the following to your global Composer ~/.composer/config.json file:
    {
        "config": {
            "preferred-install": "dist"
        },
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/christopher-hopper/coder"
            }
        ]
    }
    
  2. Run these Composer commands:
    composer global require "dealerdirect/phpcodesniffer-composer-installer:dev-master"
    composer global require "drupal/coder:dev-8.x-2.x"
    
chOP’s picture

I've opened a pull request for the required change to Drupal Coder.

klausi/coder #24

I'm now asking the dealerdirect/phpcodesniffer-composer-installer maintainers to bump a new release version so that the `dev-master` version constraint can be more like ^0.2.2 and to ensure the plugin can be used when Composer minimum stability is set to stable.

klausi’s picture

Status: Needs review » Needs work

Makes sense, committed the PR to change the project type.

Now we should probably update our README?

  • klausi committed 7f64ac7 on 8.x-2.x authored by chOP
    feat(composer): Set Composer package type to phpcodesniffer-standard for...
chOP’s picture

I'll provide a pull request with suggested updates to README.

chOP’s picture

Status: Needs work » Needs review

See the following Pull Request for suggested updates to the README that document usage with Composer Installer Plugins.

klausi/coder #27

chOP’s picture

See the following Pull Request for suggested updates to the README that document usage with Composer Installer Plugins.

pfrenssen/coder #1

  • pfrenssen committed f8b0214 on 8.x-2.x authored by chOP
    Issue #2848532 by chOP: Update Composer information in README
    

pfrenssen’s picture

Status: Needs review » Fixed

Thanks!

pfrenssen’s picture

pfrenssen’s picture

No idea how I can "uncredit" myself, this feature must be new :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.