Skip to content

mickaelperrin/phpcodesniffer-composer-installer

 
 

Repository files navigation

PHP_CodeSniffer Standards Composer Installer Plugin

Project Stage Last Commit Awesome License

Travis Scrutinizer Latest Version on Packagist Packagist

This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (rulesets).

No more symbolic linking of directories, checking out repositories on specific locations or changing the phpcs configuration.

Note: This plugin is compatible with both version 2.x and 3.x of PHP_CodeSniffer

Usage

Installation can be done with composer, by requiring this package as a development dependency:

composer require --dev dealerdirect/phpcodesniffer-composer-installer

That's it.

How it works

Basically, this plugin executes the following steps:

  • This plugin search for phpcodesniffer-standard packages in all of your currently installed Composer packages.
  • Matching packages and the project itself are scanned for PHP_CodeSniffer rulesets.
  • The plugin will call PHP_CodeSniffer and configure the installed_paths option.

Example project

The following is an example Composer project and has included multiple phpcodesniffer-standard packages.

{
    "name": "dealerdirect/example-project",
    "description": "Just an example project",
    "type": "project",
    "require": {},
    "require-dev": {
        "dealerdirect/phpcodesniffer-composer-installer": "*",
        "object-calisthenics/phpcs-calisthenics-rules": "*",
        "phpcompatibility/php-compatibility": "*",
        "wp-coding-standards/wpcs": "*"
    }
}

After running composer install PHP_CodeSniffer just works:

$ ./vendor/bin/phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz, Zend, PHPCompatibility, WordPress,
WordPress-Core, WordPress-Docs, WordPress-Extra and WordPress-VIP

Calling the plugin directly

In some circumstances, it is desirable to call this plugin's functionality directly. For instance, during development or in CI environments.

As the plugin requires Composer to work, direct calls need to be wired through a project's composer.json.

This is done by adding a call to the Plugin::run function in the script section of the composer.json:

{
    "scripts": {
        "install-codestandards": [
            "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
        ]
    }
}

The command can then be called using composer run-script install-codestandards or referenced from other script configurations, as follows:

{
    "scripts": {
        "install-codestandards": [
            "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
        ],
        "post-install-cmd": [
            "@install-codestandards"
        ]
    }
}

For more details about Composer scripts, please refer to the section on scripts in the Composer manual.

Caveats

When this plugin is installed globally, composer will load the global plugin rather than the one from the local repository. Despite this behavior being documented in the composer manual, it could potentially confuse as an other version of the plugin could be run and not the one specified by the project.

Developing Coding Standards

Coding standard can be developed normally, as documented by PHP_CodeSniffer, in the Coding Standard Tutorial.

Create a composer package of your coding standard by adding a composer.json file.

{
  "name" : "acme/phpcodesniffer-our-standards",
  "description" : "Package contains all coding standards of the Acme company",
  "require" : {
    "php" : ">=5.4.0,<8.0.0-dev",
    "squizlabs/php_codesniffer" : "^2.0"
  },
  "type" : "phpcodesniffer-standard"
}

Requirements:

  • The repository may contain one or more standards.
  • Each standard can have a separate directory no deeper than 3 levels from the repository root.
  • The package type must be phpcodesniffer-standard. Without this, the plugin will not trigger.

Changelog

This repository does not contain a CHANGELOG.md file, however, we do publish a changelog on each release using the GitHub releases functionality.

Contributing

This is an active open-source project. We are always open to people who want to use the code or contribute to it.

We've set up a separate document for our contribution guidelines.

Thank you for being involved! 😍

Authors & contributors

The original idea and setup of this repository is by Franck Nijhof, employee @ Dealerdirect.

For a full list off all author and/or contributors, check the contributors page.

Working @ Dealerdirect

Dealerdirect is always on the looking for energetic and hard working developers and devops engineers.

Interested in working at Dealerdirect? Then please be sure to check out our vacancies.

Did not find a matching vacancy? Just get in touch!

dealerdirect.com

License

The MIT License (MIT)

Copyright (c) 2016-2017 Dealerdirect B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Composer installer for PHP_CodeSniffer coding standards

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%