opositatest/php-cs-fixer-config 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

opositatest/php-cs-fixer-config

Composer 安装命令:

composer require opositatest/php-cs-fixer-config

包简介

PHP CS Fixer configuration for OpositaTest projects

README 文档

README

This repository contains the common code style configuration for all OpositaTest PHP projects.

It's based on the ideas of refinery29/php-cs-fixer-config.

Installation

composer require --dev opositatest/php-cs-fixer-config

Usage

Configuration

Create a configuration file called .php_cs.dist in the project root with the following contents:

<?php

$config = new Opositatest\PhpCsFixerConfig\OpositatestConfig();
$config->getFinder()
    ->in(__DIR__ . "/src")
    ->in(__DIR__ . "/tests");
return $config;

Manual execution

To execute the fixes manually, you must run the php-cs-fixer (usually located at /vendor/bin or /bin):

$ ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php

The --verbose and --diff options can be useful to see what changes are being actually made. To avoid applying changes automatically, the --dry-run option can be used:

$ ./vendor/bin/php-cs-fixer fix --config=.php_cs.dist --verbose --diff --dry-run

Limiting scope

In large projects, the first time you run the tool you may end up with many changes, making it difficult to spot potential regressions. The tool makes use of the Symfony Finder component, so you can use any of the filters provided by the component to limit by directory, file names, etc. For example:

Apply only to given subdirectory

$config->getFinder()
    ->in(__DIR__ . "/src/Model");

Apply only to PHP files which name ends in Controller

$config->getFinder()
    ->in("/src")
    ->name("*Controller.php");

Exclude directory

$config->getFinder()
    ->in("/src")
    ->exclude("third-party")

Pre-commit hook

It is possible to configure a pre-commit hook to format the code automatically before each commit.

Run touch .git/hooks/pre-commit to create a new hook, make it executable with chmod +x .git/hooks/pre-commit and paste the following script into .git/pre-commit:

#!/usr/bin/env bash

echo "Running php-cs-fixer..."

CURRENT_DIRECTORY=`pwd`
GIT_HOOKS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

PROJECT_DIRECTORY="$GIT_HOOKS_DIR/../.."

cd $PROJECT_DIRECTORY;
PHP_CS_FIXER="vendor/bin/php-cs-fixer"

git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do
    ${PHP_CS_FIXER} fix --config=.php_cs --verbose ${line};
    git add "$line";
done

cd $CURRENT_DIRECTORY;
echo "Done."

opositatest/php-cs-fixer-config 适用场景与选型建议

opositatest/php-cs-fixer-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.84k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 08 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 opositatest/php-cs-fixer-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 opositatest/php-cs-fixer-config 我们能提供哪些服务?
定制开发 / 二次开发

基于 opositatest/php-cs-fixer-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 10
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-01