承接 kep/cs-fixer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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)
  • Grouping imports by type:

    • Classes (class)
    • Constants (const)
    • Functions (function)
  • 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, while Monolog\... form the "Monolog" group, and a blank line will be inserted between these groups.

Requirements

  • PHP CS Fixer
  • PHP 8.3 or higher

Installation

  1. Add the modified OrderedImportsGroupFixer class to your project (e.g., in the CustomFixer directory):
   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
  1. 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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-11