dealerdirect/phpcodesniffer-composer-installer
Composer 安装命令:
composer require dealerdirect/phpcodesniffer-composer-installer
包简介
PHP_CodeSniffer Standards Composer Installer Plugin
关键字:
README 文档
README
This composer installer plugin makes installation of PHP_CodeSniffer coding standards (rulesets) straight-forward.
No more symbolic linking of directories, checking out repositories on specific locations or manually changing the phpcs configuration.
Usage
Installation can be done with Composer, by requiring this package as a development dependency:
composer require --dev dealerdirect/phpcodesniffer-composer-installer:"^1.0"
Since Composer 2.2, Composer will ask for your permission to allow this plugin to execute code. For this plugin to be functional, permission needs to be granted.
When permission has been granted, the following snippet will automatically be added to your composer.json file by Composer:
{
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
You can safely add the permission flag (to avoid Composer needing to ask), by running:
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
That's it.
Compatibility
This plugin is compatible with:
- PHP 5.4+, 7.x, and 8.x (Support for PHP v8 is available since
v0.7.0) - Composer 2.2+ (Support for Composer v2 is available since
v0.7.0; support for Composer < 2.2 was dropped inv1.1.0) - PHP_CodeSniffer 3.x and 4.x(Support for PHP_CodeSniffer v4 is available since
v0.7.0, support for PHP_CodeSniffer v2 was dropped inv1.2.0)
How it works
Basically, this plugin executes the following steps:
- This plugin searches for
phpcodesniffer-standardpackages 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_pathsoption.
Example project
The following is an example Composer project and has included
multiple phpcodesniffer-standard packages.
{
"name": "example/project",
"description": "Just an example project",
"type": "project",
"require": {},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "*",
"phpcompatibility/php-compatibility": "*",
"wp-coding-standards/wpcs": "*"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
After running composer install PHP_CodeSniffer just works:
$ ./vendor/bin/phpcs -i The installed coding standards are PEAR, PSR1, PSR2, PSR12, Squiz, Zend, PHPCompatibility, Modernize, NormalizedArrays, Universal, PHPCSUtils, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra
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": [
"PHPCSStandards\\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": [
"PHPCSStandards\\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",
"squizlabs/php_codesniffer" : "^3.13"
},
"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
typemust bephpcodesniffer-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-devthis 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.
Remember that Composer treats unstable minors as majors and will not be able to resolve one config requiring this plugin at version
^0.7, while another requires it at version^1.0. 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.4.1 || ^0.5 || ^0.6 || ^0.7 || ^1.0"
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 authors and/or contributors, check the contributors page.
Funding
This project is included in the projects supported via the PHP_CodeSniffer Open Collective.
If you use this plugin, financial contributions to the Open Collective are encouraged and appreciated.
License
The MIT License (MIT)
Copyright (c) 2016-2022 Dealerdirect B.V. and contributors Copyright (c) 2022- PHPCSStandards and contributors
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.
dealerdirect/phpcodesniffer-composer-installer 适用场景与选型建议
dealerdirect/phpcodesniffer-composer-installer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 173.82M 次下载、GitHub Stars 达 598, 最近一次更新时间为 2016 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「installer」 「plugin」 「composer」 「tests」 「quality」 「standards」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dealerdirect/phpcodesniffer-composer-installer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dealerdirect/phpcodesniffer-composer-installer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dealerdirect/phpcodesniffer-composer-installer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Installs Aura packages to the Aura system "package" directory.
Install WordPress must-use plugins with Composer
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Arikam CMS installers
统计信息
- 总下载量: 173.82M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 606
- 点击次数: 27
- 依赖项目数: 2087
- 推荐数: 37
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-22