定制 weerd/php-style 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

weerd/php-style

最新稳定版本:v1.2.0

Composer 安装命令:

composer require weerd/php-style

包简介

Shareable pre-configured base style rules for the PHP Code Standards Fixer tool.

README 文档

README

This package provides a simple way to apply pre-configured base style rules for the PHP Code Standards Fixer tool, that can be easily shared across projects and packages using PHP 7+.

It can be configured using the default rules or you can specify a different supported base ruleset, along with any additional rules or overrides you would like to include.

Installation

$ composer require weerd/php-style

Usage

Add a .php_cs.dist in the root directory of your project or pacakge.

Within that file create a new instance of PhpCsFixer\Finder and configure what files and directories the PHP CS Fixer tool should be looking to fix code style.

Next, call the Weerd\PhpStyle\configure() function and pass the instance of the finder as the first argument.

Below are some examples along with variations utilizing the $options array:

Example using default ruleset

The following example returns a configuration with the default rules for PHP styles.

<?php

use PhpCsFixer\Finder;
use function Weerd\PhpStyle\configure;

$finder = Finder::create()
    ->in([
        __DIR__.'/src',
        __DIR__.'/tests',
    ]);

return configure($finder);

Example using default ruleset and additional rules

The following example returns a configuration with the default rules, along with two additional rules included in the final set of rules for PHP styles.

<?php

use PhpCsFixer\Finder;
use function Weerd\PhpStyle\configure;

$finder = Finder::create()
    ->in([
        __DIR__.'/src',
        __DIR__.'/tests',
    ]);

$options = [
  'rules' => [
    'single_quote' => true,
    'trim_array_spaces' => true,
  ],
];

return configure($finder, $options);

Example using laravel ruleset

The following example returns a configuration with the laravel rules for PHP styles.

<?php

use PhpCsFixer\Finder;
use function Weerd\PhpStyle\configure;

$finder = Finder::create()
    ->in([
        __DIR__.'/app',
        __DIR__.'/config',
        __DIR__.'/database',
        __DIR__.'/routes',
        __DIR__.'/tests',
    ])
    ->notName('*.blade.php');

return configure($finder, ['base' => 'laravel']);

Once you have the .php_cs.dist file setup, you can run the PHP CS Fixer tool by running:

$ vendor/bin/php-cs-fixer fix --allow-risky=yes

Or to make things easier, add that command to the composer.json file as a script:

// composer.json

{
    "scripts": {
        "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
    }
}

Now you can run the PHP CS Fixer tool with the following composer command:

$ composer format

Credits

🙌 Thanks to @Spatie and their Laravel Package Training course for introducing me to the PHP Code Standards Fixer tool and how to use it!

🙌 This package is heavily inspired by @timacdonald's great article on how to share PHP CS Fixer rules!

🙌 The complete set of Laravel specific rules are thanks to @laravel-shift and the compiled rules shared in a gist and used on Laravel Shift!

统计信息

  • 总下载量: 1.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固