narrowspark/php-cs-fixer-config
最新稳定版本:v6.3.4
Composer 安装命令:
composer require narrowspark/php-cs-fixer-config
包简介
Provides a configuration for friendsofphp/php-cs-fixer, used within Narrowspark and Anolilab.
README 文档
README
This repository provides a configuration for https://github.com/FriendsOfPHP/PHP-CS-Fixer, which we use to verify and enforce a single coding standard for PHP code within Narrowspark and Anolilab.Installation
Via Composer
$ composer require narrowspark/php-cs-fixer-config
Usage
Create a configuration file .php_cs in the root of your project:
<?php declare(strict_types=1); use Narrowspark\CS\Config\Config; $config = new Config(); $config->getFinder() ->files() ->in(__DIR__) ->exclude('.build') ->exclude('vendor') ->name('*.php') ->ignoreDotFiles(true) ->ignoreVCS(true); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.cache'); return $config;
Git
All configuration examples use the caching feature, and if you want to use it as well, you add the cache directory to .gitignore:
+ /.build/
/vendor/
💡 personally, I prefer to use a .build directory for storing build artifacts.
Configuration with header
💡 optionally specify a header:
<?php declare(strict_types=1); use Narrowspark\CS\Config\Config; +$header = <<<EOF +Copyright (c) 2020 Narrowspark + +For the full copyright and license information, please view +the LICENSE file that was distributed with this source code. +EOF; -$config = new Narrowspark\CS\Config\Config(); +$config = new Narrowspark\CS\Config\Config($header); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.cache'); return $config;
This will turn on and configure the HeaderCommentFixer, so that
file headers will be added to PHP files, for example:
Configuration with override rules
💡 optionally override rules from a rule set by passing in an array of rules to be merged in:
<?php declare(strict_types=1); use Narrowspark\CS\Config\Config; - $config = new Config(); + $config = new Config(null /* if you dont need a header */, [ 'mb_str_functions' => false, 'strict_comparison' => false, ]); $config->getFinder() ->files() ->in(__DIR__) ->exclude('.build') ->exclude('vendor') ->name('*.php') ->ignoreDotFiles(true) ->ignoreVCS(true); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.cache'); return $config;
Composer
If you like composer scripts, add a coding-standards script to composer.json:
{
"name": "foo/bar",
"require": {
"php": "^7.3",
},
"require-dev": {
"narrowspark/php-cs-fixer-config": "~1.0.0"
+ },
+ "scripts": {
+ "cs:check": [
+ "mkdir -p .build/php-cs-fixer",
+ "php-cs-fixer fix --diff --diff-format=udiff --verbose"
+ ]
}
}
Run
$ composer cs:check
To automatically fix coding standard violations.
Travis
If you like Travis CI, add a coding-standards stage to your jobs:
language: php
cache:
directories:
- $HOME/.composer/cache
+ - .build/php-cs-fixer
jobs:
include:
+ - stage: "Coding Standards"
+
+ php: 7.3
+
+ install:
+ - composer install --no-interaction --no-progress --no-suggest
+
+ before_script:
+ - mkdir -p .build/php-cs-fixer
+
+ script:
+ - vendor/bin/php-cs-fixer fix --config=.php_cs --diff --dry-run --verbose
GitHub Actions
If you like GitHub Actions, add a coding-standards job to your workflow:
on:
pull_request:
push:
branches:
- master
tags:
- "**"
name: "Continuous Integration"
jobs:
+ coding-standards:
+ name: "Coding Standards"
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: "Checkout"
+ uses: actions/checkout@v1.1.0
+
+ - name: "Disable Xdebug"
+ run: php7.3 --ini | grep xdebug | sed 's/,$//' | xargs sudo rm
+
+ - name: "Cache dependencies installed with composer"
+ uses: actions/cache@v1.0.2
+ with:
+ path: ~/.composer/cache
+ key: php7.3-composer-locked-${{ hashFiles('**/composer.lock') }}
+ restore-keys: |
+ php7.3-composer-locked-
+
+ - name: "Install locked dependencies with composer"
+ run: php7.3 $(which composer) install --no-interaction --no-progress --no-suggest
+
+ - name: "Create cache directory for friendsofphp/php-cs-fixer"
+ run: mkdir -p .build/php-cs-fixer
+
+ - name: "Cache cache directory for friendsofphp/php-cs-fixer"
+ uses: actions/cache@v1.0.2
+ with:
+ path: ~/.build/php-cs-fixer
+ key: php7.3-php-cs-fixer-${{ hashFiles('**/composer.lock') }}
+ restore-keys: |
+ php7.3-php-cs-fixer-
+
+ - name: "Run friendsofphp/php-cs-fixer"
+ run: php7.3 vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --dry-run --verbose
Testing
$ vendor/bin/phpunit
Contributing
If you would like to help take a look at the list of issues and check our Contributing guild.
Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Credits
License
The Narrowspark http-emitter is open-sourced software licensed under the MIT license
narrowspark/php-cs-fixer-config 适用场景与选型建议
narrowspark/php-cs-fixer-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60.66k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「config」 「cs」 「narrowspark」 「php-cs-fixer」 「cs-fixer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 narrowspark/php-cs-fixer-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 narrowspark/php-cs-fixer-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 narrowspark/php-cs-fixer-config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Emitting psr-7 responses.
PHP MIME Types Guesser and extension mapping.
HiDev plugin for PHP-CS-Fixer
The Narrowspark Coding Standard is a set of phpstan, psalm, infection, rector and php-cs-fixer rules applied to all Narrowspark projects.
A Collections library for PHP.
Taptima PHP-CS-Fixer fixers
统计信息
- 总下载量: 60.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 30
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-21