worksome / phpinsights-coding-style-generator
此包已被放弃,不再维护。未建议替代包。
从php insights配置文件生成编码风格
dev-master
2020-04-28 10:44 UTC
Requires
- php: ^7.4
- nunomaduro/phpinsights: dev-master
- symfony/config: ^5.0
- symfony/console: ^5.0
- symfony/dependency-injection: ^5.0
- symfony/var-dumper: ^5.0
- tightenco/collect: ^7.0
- twig/twig: ^3.0
This package is auto-updated.
Last update: 2020-08-28 11:35:35 UTC
README
根据您的PHP Insights配置文件生成编码风格。
composer require worksome/phpinsights-coding-style-generator
使用方法
在composer的bin文件夹中,将有一个名为codingStyleGenerator
的文件。
工具的第一个参数是输出目录。
此文件接受以下参数
--config-path
:phpinsights配置文件的路径。--insight-config-path
:编码风格配置文件的路径。
运行工具的示例命令
codingStyleGenerator docs --config-path=config/insights.php --insight-config-path=config/codingStyle.php
工具将生成一个包含VuePress安装的文件夹。
在这里,一些文件将在每次生成编码风格时被覆盖。
要渲染VuePress安装,请执行以下操作
# install yarn global add vuepress # OR npm install -g vuepress # start writing vuepress dev # build to static files vuepress build
配置
配置文件被分为组、子组和洞察。
例如,一个组可以是通用PHP
或Laravel
,一个子组可以是函数
或代码
。
洞察是php insights使用的洞察。
return [ 'groups' => [ Group::GENERIC_PHP => [ 'groups' => [ SubGroup::CODE => [ 'insights' => [ \ObjectCalisthenics\Sniffs\ControlStructures\NoElseSniff::class => [ Property::TITLE => 'Avoid else', Property::DESCRIPTION => <<<DESC Else statements adds confusion and often does not contribute to more readable code. It is recommended to avoid else statements. Usage of early returns can often replace else statements, which also in return will result with the happy path being last. DESC, Property::BAD_CODE => /** @lang PHP */ <<<BAD_CODE if(\$state === 'approved') { return "Happy life"; } else { return "bad state"; } BAD_CODE, Property::GOOD_CODE => /** @lang PHP */ <<<GOOD_CODE if (\$state !== 'approved') { return "bad state"; } return "Happy life"; GOOD_CODE, ], ], ], ], ], Group::LARAVEL => [ 'groups' => [ 'Controllers' => [ 'insights' => [ 'Prefer array parameters when using view' => [ Property::ALWAYS_SHOW => true, Property::DESCRIPTION => <<<DESC When passing data to a blade file, it is done with the `view` method. In the case of passing data, always use the array syntax. DESC, Property::BAD_CODE => /** @lang PHP */ <<<BAD_CODE \$value = 'My value'; return view('view', compact('value')); BAD_CODE, Property::GOOD_CODE => /** @lang PHP */ <<<GOOD_CODE return view('view', ['value' => 'My value']); GOOD_CODE, ], ], ], ], ], ], ];