定制 maagiline/maagiline-phpcs 二次开发

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

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

maagiline/maagiline-phpcs

Composer 安装命令:

composer require maagiline/maagiline-phpcs

包简介

Maagiline PHP coding standard

README 文档

README

Use this coding standard in your local development environment, as well as in CI pipelines.

Add to your project

First, install via composer:

composer require maagiline/maagiline-phpcs

Then, create a ruleset in you project directory. The ruleset should:

  • Refer to the maagiline-phpcs ruleset for instructions
  • Specify which files / directories to scan

Here's an example of a ruleset.xml that you should use for a Laravel project:

<?xml version="1.0"?>
<ruleset>
    <!-- For setup guide refer to vendor/maagiline/maagiline-phpcs/readme.md-->
    <rule ref="./vendor/maagiline/maagiline-phpcs"/>

    <!-- Don't scan these directories -->
    <exclude-pattern type="relative">./bin/</exclude-pattern>
    <exclude-pattern type="relative">./bootstrap/</exclude-pattern>
    <exclude-pattern type="relative">./config/</exclude-pattern>
    <exclude-pattern type="relative">./public/</exclude-pattern>
    <exclude-pattern type="relative">./resources/</exclude-pattern>
    <exclude-pattern type="relative">./storage/</exclude-pattern>
    <exclude-pattern type="relative">./vendor/</exclude-pattern>

    <!-- Dont require namespace in migrations -->
    <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
        <exclude-pattern>./database/</exclude-pattern>
    </rule>
</ruleset>

Set up in PhpStorm

Set up code sniffing

Code sniffing will instruct your editor to display style issues in your code.

  1. In PhpStorm settings, navigate to Languages & Frameworks > PHP > Quality Tools
  2. For PHP Codesniffer path, enter: vendor/bin/phpcs
  3. In PhpStorm settings, navigate to Editor > Inspections > Quality tools > PHP_Codesniffer validation
  4. Check this option
  5. Set Severity to "Error"
  6. In Coding standard, select custom and select ./ruleset.xml (pointing to the ruleset.xml that you created in your project root)

Codesniffer settings in PhpStorm

Set up code beautifier

Some errors can be fixed automatically by phpcbf. Wanna go full-on badass? Set up PhpStorm to fix your style issues automatically.

Set up phpcbf as external tool

First, add phpcbf under "External tools".

  1. In PhpStorm settings, navigate to Tools > External Tools
  2. Add a new tool (click plus sign in bottom of window)
  3. Enter following info
Name:               phpcbf
Description:        Fixed phpcs issues automatically
Program:            $ProjectFileDir$/vendor/squizlabs/php_codesniffer/bin/phpcbf
Arguments:          --standard=$ProjectFileDir$/ruleset.xml $FileDir$/$FileName$
Working directory:  $ProjectFileDir$

Under 'Advanced options', uncheck "Open console for tool output".

phpcbf external tool in PhpStorm

Trigger phpcbf from keyboard shortcut

After clicking "Apply" in the previous menu, do this:

  1. In PhpStorm settings, navigate to Keymap
  2. Search for "phpcbf"
  3. Assign a shortcut. I like to use cmd+shift+B

Now, whenever in a file that has errors, tap this to run phpcbf. All errors that can be fixed automatically will be fixed.

Trigger phpcbf on file save

(NOT TESTED). If you wish to run phpcbf automatically whenever a file is saved, you can create a File Watcher in PhpStorm settings. The settings should be similar to those outlined in the previous section. Be brave!

Command line tools

To list errors:

./vendor/bin/phpcs --standard=./ruleset.xml

Some errors can be fixed automatically. To fix automatically:

./vendor/bin/phpcbf --standard=./ruleset.xml

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固