Easy Coding Standard 使用教程
项目的目录结构及介绍
Easy Coding Standard (ECS) 是一个用于 PHP 项目的代码风格检查和格式化工具。以下是其基本目录结构:
easy-coding-standard/
├── bin/
├── build/
├── config/
├── docs/
├── patches/
├── src/
├── templates/
├── tests-released/
├── tests/
├── .editorconfig
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── ecs.php
├── full_ecs_build.sh
├── phpstan.neon
├── phpunit.xml
├── prefix-code.sh
├── rector.php
├── scoper.php
目录介绍
bin/
: 包含可执行文件。build/
: 构建相关文件。config/
: 配置文件。docs/
: 文档文件。patches/
: 补丁文件。src/
: 源代码文件。templates/
: 模板文件。tests-released/
: 已发布的测试文件。tests/
: 测试文件。.editorconfig
: 编辑器配置文件。.gitattributes
: Git 属性配置文件。.gitignore
: Git 忽略配置文件。LICENSE
: 许可证文件。README.md
: 项目说明文件。composer.json
: Composer 配置文件。ecs.php
: ECS 配置文件。full_ecs_build.sh
: 完整构建脚本。phpstan.neon
: PHPStan 配置文件。phpunit.xml
: PHPUnit 配置文件。prefix-code.sh
: 前缀代码脚本。rector.php
: Rector 配置文件。scoper.php
: Scoper 配置文件。
项目的启动文件介绍
ECS 的启动文件是 ecs.php
,它位于项目的根目录下。这个文件用于配置 ECS 的规则和检查路径。
启动文件示例
<?php
declare(strict_types=1);
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return static function (ECSConfig $ecsConfig): void {
$ecsConfig->sets([SetList::SYMPLIFY]);
};
启动命令
vendor/bin/ecs check
项目的配置文件介绍
ECS 的配置文件是 ecs.php
,它允许你定义检查规则和路径。
配置文件示例
<?php
declare(strict_types=1);
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return static function (ECSConfig $ecsConfig): void {
$ecsConfig->sets([SetList::SYMPLIFY]);
$ecsConfig->paths([__DIR__ . '/src', __DIR__ . '/tests']);
};
配置项
sets
: 定义使用的规则集。paths
: 定义检查的路径。
通过这些配置,你可以自定义 ECS 的行为,以适应你的项目需求。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考