定制 gtjamesa/php-standards 二次开发

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

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

gtjamesa/php-standards

最新稳定版本:v2.0.1

Composer 安装命令:

composer require gtjamesa/php-standards

包简介

James' shared PHP style rules for PHP-CS-Fixer

README 文档

README

This package defines my FriendsOfPHP/PHP-CS-Fixer coding standards to be used across multiple projects. For details regarding the rules used, you may use php-cs-fixer-configurator.

Usage

Install the package by requiring php-cs-fixer and php-standards:

composer require --dev friendsofphp/php-cs-fixer gtjamesa/php-standards

Next, create a .php-cs-fixer.dist.php file in the root of your project with the following content:

<?php

use PhpCsFixer\Finder;

$project_path = getcwd();
$finder = Finder::create()
    ->notPath('bootstrap/*')
    ->notPath('storage/*')
    ->notPath('resources/view/mail/*')
    ->in([
        $project_path . '/app',
        $project_path . '/config',
        $project_path . '/database',
        $project_path . '/resources',
        $project_path . '/routes',
        $project_path . '/tests',
    ])
    ->name('*.php')
    ->notName('*.blade.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

return JamesAusten\styles($finder);

The file above assumes a Laravel project, but the configuration can be edited for any PHP 7.0+ project.

Add the following entries to your .gitignore file:

.php_cs.cache
.php-cs-fixer.cache

Configuration

The php-cs-fixer rules can be found in ./src/rules.php. These were taken from laravel-shift/.php_cs.laravel.php and modified to suit my coding style. The following configuration parameters can be specified to the styles function. The function returns a \PhpCsFixer\Config instance, so you may also chain additional configuration parameters after the function call.

// Define rules to override the defaults
$rules = [
    'method_argument_space' => true,
    'phpdoc_summary' => false,
];

// Specify whether to enable caching (default: `true`)
// https://github.com/FriendsOfPHP/PHP-CS-Fixer#caching
$useCache = false;

return JamesAusten\styles($finder, $rules, $useCache)
    ->setCacheFile(__DIR__ . '.php_cs.cache'); // Set the cache file

Run the fixer

To run the fixer, run the following command:

./vendor/bin/php-cs-fixer fix

统计信息

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

GitHub 信息

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

其他信息

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