All Projects → Dealerdirect → Phpcodesniffer Composer Installer

Dealerdirect / Phpcodesniffer Composer Installer

Licence: mit
Composer installer for PHP_CodeSniffer coding standards

Projects that are alternatives of or similar to Phpcodesniffer Composer Installer

Codor
Custom PHPCS sniffs to find Code Smells
Stars: ✭ 40 (-86.25%)
Mutual labels:  php-codesniffer
composer-cost
Displays cost/size of each composer package installed.
Stars: ✭ 31 (-89.35%)
Mutual labels:  composer-plugin
wp-translation-downloader
Composer plugin to download WordPress translations
Stars: ✭ 35 (-87.97%)
Mutual labels:  composer-plugin
symfony-clean-tags-composer-plugin
No description or website provided.
Stars: ✭ 24 (-91.75%)
Mutual labels:  composer-plugin
laminas-dependency-plugin
Replace zendframework and zfcampus packages with their Laminas Project equivalents.
Stars: ✭ 32 (-89%)
Mutual labels:  composer-plugin
composer-ignore-plugin
The composer plugin to remove useless files by yourself
Stars: ✭ 21 (-92.78%)
Mutual labels:  composer-plugin
drupal-composer-init
Initialise a Drupal composer setup
Stars: ✭ 43 (-85.22%)
Mutual labels:  composer-plugin
Acf Pro Installer
A composer install helper for Advanced Custom Fields PRO
Stars: ✭ 265 (-8.93%)
Mutual labels:  composer-plugin
composer-patches-plugin
Plugin for composer to apply patches onto dependencies.
Stars: ✭ 75 (-74.23%)
Mutual labels:  composer-plugin
codeclimate-phpcodesniffer
Code Climate Engine for PHP Code Sniffer
Stars: ✭ 27 (-90.72%)
Mutual labels:  php-codesniffer
composer-repl
A REPL for PHP built into Composer (using PsySH)
Stars: ✭ 81 (-72.16%)
Mutual labels:  composer-plugin
sniff
Simpler PHP code sniffer built on top of PHP-CS-Fixer.
Stars: ✭ 14 (-95.19%)
Mutual labels:  php-codesniffer
composer-velocita
Velocita - Composer plugin for transparent caching
Stars: ✭ 26 (-91.07%)
Mutual labels:  composer-plugin
composer-localdev-plugin
Composer Plugin for local development
Stars: ✭ 31 (-89.35%)
Mutual labels:  composer-plugin
vscode-php-sniffer
Visual Studio Code extension for PHP_Codesniffer validation and formatting.
Stars: ✭ 41 (-85.91%)
Mutual labels:  php-codesniffer
php-toolbox
🐳 A Docker image designed for PHP developers that care about code quality.
Stars: ✭ 18 (-93.81%)
Mutual labels:  php-codesniffer
composer-diff
Compares composer.lock changes and generates Markdown report so you can use it in PR description.
Stars: ✭ 51 (-82.47%)
Mutual labels:  composer-plugin
Coding Standard
[READ-ONLY] 20+ Coding Standard checkers for PHP projects with focus on Clean Architecture
Stars: ✭ 268 (-7.9%)
Mutual labels:  php-codesniffer
composer-inheritance-plugin
Opinionated version of Wikimedia composer-merge-plugin to work in pair with Bamarni composer-bin-plugin.
Stars: ✭ 20 (-93.13%)
Mutual labels:  composer-plugin
cyclonedx-php-composer
Create CycloneDX Software Bill of Materials (SBOM) from PHP Composer projects
Stars: ✭ 20 (-93.13%)
Mutual labels:  composer-plugin

PHP_CodeSniffer Standards Composer Installer Plugin

Project Stage Last Commit Awesome License

Travis Scrutinizer Latest Version on Packagist Packagist

Contributor Covenant

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 searches 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.

Changing the Coding Standards search depth

By default, this plugin searches up for Coding Standards up to three directories deep. In most cases, this should be sufficient. However, this plugin allows you to customize the search depth setting if needed.

{
    "extra": {
        "phpcodesniffer-search-depth": 5
    }
}

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 another 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" : "^3.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.

Requiring the plugin from within your coding standard

If your coding standard itself depends on additional external PHPCS standards, this plugin can make life easier on your end-users by taking care of the installation of all standards - yours and your dependencies - for them.

This can help reduce the number of support questions about setting the installed_paths, as well as simplify your standard's installation instructions.

For this to work, make sure your external standard adds this plugin to the composer.json config via require, not require-dev.

⚠️ Your end-user may already require-dev this plugin and/or other external standards used by your end-users may require this plugin as well.

To prevent your end-users getting into "dependency hell", make sure to make the version requirement for this plugin flexible.

As, for now, this plugin is still regarded as "unstable" (version < 1.0), remember that Composer treats unstable minors as majors and will not be able to resolve one config requiring this plugin at version ^0.5, while another requires it at version ^0.6. Either allow multiple minors or use * as the version requirement.

Some examples of flexible requirements which can be used:

composer require dealerdirect/phpcodesniffer-composer-installer:"*"
composer require dealerdirect/phpcodesniffer-composer-installer:"0.*"
composer require dealerdirect/phpcodesniffer-composer-installer:"^0.4 || ^0.5 || ^0.6"

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 of all author and/or contributors, check the contributors page.

License

The MIT License (MIT)

Copyright (c) 2016-2020 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].