juliangut/easy-coding-standard-config
Composer 安装命令:
composer require juliangut/easy-coding-standard-config
包简介
easy-coding-standard configuration
README 文档
README
easy-coding-standard-config
Opinionated as can be configuration defaults for Easy-Coding-Standard
Installation
Composer
composer require --dev juliangut/easy-coding-standard-config
Usage
Create ecs.php file at your project's root directory
<?php use Jgut\ECS\ConfigSet82; return (new ConfigSet82()) ->setHeader(<<<'HEADER' Easy Coding Standard config. @license BSD-3-Clause @link https://github.com/juliangut/easy-coding-standard-config HEADER) ->configureBuilder() ->withPaths([ __FILE__, __DIR__ . '/src', ]);
Use one of the provided configurations depending on the PHP version you want to support:
Jgut\ECS\ConfigSet83, PHP >= 8.3Jgut\ECS\ConfigSet82, PHP >= 8.2Jgut\ECS\ConfigSet81, PHP >= 8.1Jgut\ECS\ConfigSet80, PHP >= 8.0
Configurations
Header
Provide a header string, it will be prepended to every file analysed by php-cs-fixer.
The string {{year}} will be replaced by the current year, and the string {{package}} will be replaced by your package name
(new ConfigSet82()) ->setHeader(<<<'HEADER' (c) 2021-{{year}} Julián Gutiérrez <juliangut@gmail.com> This file is part of package {{package}} HEADER);
--- Original +++ New <?php +/* + * (c) 2021-2024 Julián Gutiérrez <juliangut@gmail.com> + * + * This file is part of package juliangut/php-cs-fixer-config + */ + declare(strict_types=1); namespace App;
If {{year}} is preceded by current year it will be combined into a single date
// Assuming current year is 2024 (new ConfigSet82()) ->setHeader(<<<'HEADER' (c) 2023-{{year}} Julián Gutiérrez <juliangut@gmail.com> This file is part of package {{package}} HEADER);
--- Original +++ New <?php +/* + * (c) 2024 Julián Gutiérrez <juliangut@gmail.com> + * + * This file is part of package juliangut/php-cs-fixer-config + */ + declare(strict_types=1); namespace App;
PHPUnit
If you work with PHPUnit
(new ConfigSet82()) ->enablePhpUnitRules();
Doctrine
If you work with Doctrine
(new ConfigSet82()) ->enableDoctrineRules();
Type Inference
If you're in the middle of "type hinting everything", try enabling type inference rules and let php-cs-fixer migrate types from annotations into properties, parameters and return types
Be aware these rules are experimental and will need human supervision after fixing, so you are advised NOT to permanently enable type inference
(new ConfigSet82()) ->enableTypeInferRules();
--- Original +++ New <?php declare(strict_types=1); namespace App; class Foo { - /** - * @var string|null - */ - protected $foo + protected ?string $foo - /** - * @var Bar - */ - protected $bar + protected Bar $bar - /** - * @var bool - */ - protected $baz + protected bool $baz /** * Foo constructor. - * - * @param string|null $foo - * @param Bar $bar - * @param bool $baz */ - public function __construct($foo, $bar, $baz = false) + public function __construct(?string $foo, Bar $bar, bool $baz = false) { $this->foo = $foo; $this->bar = $bar; $this->baz = $baz; } - /** - * @return bool - * - public function isBaz() + public function isBaz(): bool { return $this->baz; } }
Additional rules
If you need to add a few additional rules, this rules can be new or override rules already set, the easiest way is using setAdditionalRules method
It is preferred to identify fixers by their class name, anyway using fixer names will work as well
(new ConfigSet82()) ->setAdditionalRules([ SingleLineThrowFixer::class => true, ]);
Custom config
If you need more control over applied rules or prefer a cleaner setup, you can easily create your custom fixer config instead of setting additional rules
use Jgut\ECS\ConfigSet82; use PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer; class CustomConfigSet extends ConfigSet82 { protected function getRules(): array { // Return your custom rules, or add/remove rules from parent's getRules() return array_merge( parent::getRules(), [ SingleLineThrowFixer::class => true, ] ); } }
Contributing
Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before.
See file CONTRIBUTING.md
License
See file LICENSE included with the source code for a copy of the license terms.
juliangut/easy-coding-standard-config 适用场景与选型建议
juliangut/easy-coding-standard-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.7k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 juliangut/easy-coding-standard-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 juliangut/easy-coding-standard-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2022-09-26