jubeki/laravel-code-style
Composer 安装命令:
composer require jubeki/laravel-code-style
包简介
Combine Custom Fixers with the ruleset of Laravel Pint to fix your code style in Laravel Applications/Packages.
README 文档
README
Laravel Code Style
Combine Custom Fixers with the ruleset of Laravel Pint
Introduction
This package provides automatic code style checking and formatting for Laravel applications and packages using the same ruleset as Laravel Pint. This package is built on top of PHP-CS-Fixer and therefor gives you the ability to add custom fixers. (which is one of the shortcomings of Laravel Pint)
Installation
composer require jubeki/laravel-code-style --dev
Once the package is installed you should publish the configuration.
php artisan vendor:publish --provider="Jubeki\LaravelCodeStyle\ServiceProvider"
Publishing the config will add a .php-cs-fixer.dist.php configuration file to the root of your project. You may customize this file as needed and then commit it to your version control system.
A cache file will be written to .php-cs-fixer.cache in the project root the first time you run the fixer. You should ignore this file so it is not added to your version control system.
echo '.php-cs-fixer.cache' >> .gitignore
Usage
Once the package is installed you can check and fix your code formatting with the on subcommand of vendor/bin/php-cs-fixer.
Automatically fix the code style
To automatically fix the code style of your project you may use the following command:
vendor/bin/php-cs-fixer fix
By default only the file names of every file fixed will be shown. To see a full diff of every change append the --diff flag.
Checking for code style violations
If you would like to check the formatting without actually altering any files you should use the fix command with the --dry-run flag.
vendor/bin/php-cs-fixer fix --dry-run --diff
In dry-run mode any violations will cause the command to return a non-zero exit code. You can use this command to fail a CI build or git commit hook.
Composer script
To make checking and fixing code style easier for contributors to your project it's recommended to add the commands as a composer script:
{
"scripts": {
"check-style": "php-cs-fixer fix --dry-run --diff",
"fix-style": "php-cs-fixer fix"
}
}
More Options
For a complete list of options please consult the PHP-CS-Fixer documentation.
Configuration
The default configuration is published as .php-cs-fixer.dist.php in the project root. You can customize this file to change options such as the paths searched or the fixes applied.
Paths
You can change the paths searched for PHP files by chaining method calls onto the PhpCsFixer\Finder instance being passed to the Jubeki\LaravelCodeStyle\Config::setFinder method.
For example, to search the examples directory you would append ->in('examples'):
<?php require __DIR__ . '/vendor/autoload.php'; return (new Jubeki\LaravelCodeStyle\Config()) ->setFinder( PhpCsFixer\Finder::create() ->in(app_path()) // ... ->in('examples') ) // ...
The default paths are setup for a Laravel application. If you are writing a package the path helper functions will not available and you will need to change the paths as necessary, i.e. PhpCsFixer\Finder::create()->in(__DIR__).
For a complete list of options refer to the Symfony Finder documentation.
Rules
By default only the Laravel Pint preset is enabled. This preset enforces many different rules which can be found in Jubeki\LaravelCodeStyle\Config
It is possible to override a specific rule from the preset. For example, you could disable the no_unused_imports rule like this:
return (new Jubeki\LaravelCodeStyle\Config()) ->setFinder( // ... ) ->setRules([ 'no_unused_imports' => false, ]);
For a complete list of available rules please refer to the php-cs-fixer documentation.
Releases
A major version bump only occurs should there be a big change to the Laravel Pint project.
Otherwise each rule change according to Laravel Pint is only a minor version bump. (This means there can be rules added, changed or removed).
Changelog
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Credits
- Julius Kiekbusch
- Matt Allan (Original Creator)
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
jubeki/laravel-code-style 适用场景与选型建议
jubeki/laravel-code-style 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 563.2k 次下载、GitHub Stars 达 56, 最近一次更新时间为 2022 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「php-cs-fixer」 「code-style」 「Pint」 「custom-fixers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jubeki/laravel-code-style 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jubeki/laravel-code-style 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jubeki/laravel-code-style 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HiDev plugin for PHP-CS-Fixer
Taptima PHP-CS-Fixer fixers
Axa Zara PHP Code style configuration for `php-cs-fixer` based on PSR-12.
Git hooks for PHP commits QA.
A generic package for implementing Laravel Pint coding standards across Laravel packages
Custom cs-fixer rules
统计信息
- 总下载量: 563.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 56
- 点击次数: 35
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-19