kep/cs-fixer
Composer 安装命令:
composer require kep/cs-fixer
包简介
Customized php cs fixer
关键字:
README 文档
README
This fixer is a modified version of OrderedImportsGroupFixer for PHP CS Fixer. It not only orders imports according to specified rules but also allows you to insert blank lines between import groups and set namespace priorities.
Features
-
Sorting imports by:
- Alphabetical order (
alpha) - Length (
length) - None (
none) - With predefined namespace priorities (
namespace_priority)
- Alphabetical order (
-
Grouping imports by type:
- Classes (
class) - Constants (
const) - Functions (
function)
- Classes (
-
Inserting blank lines between import groups:
- Groups are determined by the first segment of the namespace.
For example, imports from
Doctrine\...form the "Doctrine" group, whileMonolog\...form the "Monolog" group, and a blank line will be inserted between these groups.
- Groups are determined by the first segment of the namespace.
For example, imports from
Requirements
- PHP CS Fixer
- PHP 8.3 or higher
Installation
- Add the modified
OrderedImportsGroupFixerclass to your project (e.g., in theCustomFixerdirectory):
mkdir -p src/CustomFixer
copy OrderedImportsGroupFixer.php to src/CustomFixer/ (or another dir) (do not forget to configure yor composer autoload if you need it)
OR
- run, with dev-master (WIP)
composer require --dev kep/cs-fixer
Examples
Config file
<?php use PhpCsFixer\Config; use PhpCsFixer\Finder; use KepCustomFixer\CustomFixer\OrderedImportsGroupFixer; $finder = Finder::create() ->in(__DIR__ . '/src'); return (new Config()) ->setRiskyAllowed(true) ->setRules([ '@PSR12' => true, 'single_blank_line_before_namespace' => true, 'OrderedImportsGroupFixer' => [ 'sort_algorithm' => 'alpha', 'imports_order' => ['const', 'class', 'function'], 'case_sensitive' => false, 'namespace_priority' => [ 'Doctrine\\' => -3, 'Monolog\\' => -4, 'DI\\' => 1 ], ], ]) ->registerCustomFixers([new OrderedImportsGroupFixer()]) ->setFinder($finder);
Input
use Doctrine\DBAL\Types\Type; use DI\ContainerBuilder; use Doctrine\ORM\EntityManager; use Monolog\Logger;
Output
use DI\ContainerBuilder; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManager; use Monolog\Logger;
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-11