greynoise-design/laravel-coding-standard

Laravel 5 编码标准,适用于 PHP_CodeSniffer 3.

1.0.2 2017-12-08 16:20 UTC

This package is not auto-updated.

Last update: 2024-09-15 03:24:08 UTC


README

版本 1.0.2

要求

PHP_CodeSniffer 3. (3.1.1 或更高版本)。

全局安装(推荐)

使用以下各种方法之一全局安装 PHP_CodeSniffer。 (如果您已经安装了它,则跳过此步骤。)

完成后,您应该在命令行上能够执行 phpcs -i

您应该看到类似以下内容:

已安装的编码标准是 MySource, PEAR, PSR1, PSR2, Squiz 和 Zend。

(推荐)使用 composer...

composer global require greynoise-design/laravel-coding-standard

或克隆此仓库...

git clone -b master --depth 1 https://github.com/greynoise-design/laravel-coding-standard.git.

或下载。

注意安装的路径。

(推荐)在 'php_codesniffer/src/Standards/' 中创建 'laravel-coding-standard/GreynoiseLaravel' 目录的符号链接,例如。

ln -s ~/Documents/Projects/laravel-coding-standard/GreynoiseLaravel ~/.composer/vendor/squizlabs/php_codesniffer/src/Standards/GreynoiseLaravel

或将 GreynoiseLaravel 目录复制到 php_codesniffer/src/Standards/

现在执行 phpcs -i 应该会显示已安装 GreynoiseLaravel,例如。

已安装的编码标准是 GreynoiseLaravel, MySource, PEAR, PSR1, PSR2, Squiz 和 Zend。

现在您可以在您选择的插件/编辑器/IDE中将 'GreynoiseLaravel' 设置为 phpcs 标准。

单个项目的 composer 安装

cd /Path/To/MyProject

composer require greynoise-design/laravel-coding-standard

在您的编辑器/插件配置中设置 'phpcs 标准路径' 和 'phpcbf 标准路径' 为

'/Path/To/MyProject/vendor/laravel-coding-standard/GreynoiseLaravel/ruleset.xml'

命令行使用

检测错误和警告(报告)。

单个文件...

phpcs /Path/To/MyFile.php --standard='/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml'

或如果全局安装。

phpcs /Path/To/MyFile.php --standard=GreynoiseLaravel

目录(递归)。

phpcs /Path/To/MyProject --standard='/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml'

或如果全局安装。

phpcs /Path/To/MyProject --standard=GreynoiseLaravel

修复可修复的错误。

单个文件。

phpcbf /Path/To/MyFile.php --standard='/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml'

或如果全局安装。

phpcbf /Path/To/MyFile.php --standard=GreynoiseLaravel

目录(递归)。

phpcbf /Path/To/MyProject --standard='/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml'

或如果全局安装。

phpcbf /Path/To/MyProject --standard=GreynoiseLaravel

示例编辑器配置

SublimeText 项目配置

项目 > 编辑项目

设置为您的偏好。

{
    "SublimeLinter":
    {
        "linters":
        {
            "phpcs":
            {
                "@disable": false,
                "cmd": "/Path/To/php_codesniffer/bin/phpcs",
                // Or if installed globally. "cmd": "phpcs",
                "standard": "/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml",
                // Exclude folders and files in the linting environment.
                // (Matches exclude-patterns in ruleser.xml).
                "excludes":
                [
                    "*/config/*",
                    "*/cache/*",
                    "*/database/*",
                    "*/docs/*",
                    "*/migrations/*",
                    "*/public/index.php",
                    "*/vendor/*",
                    "*/storage/*",
                    "*/*.blade.php",
                    "*/*.css",
                    "*/*.js",
                    "*/*.xml",
                    "*/autoload.php",
                    "*/Middleware/*",
                    "*/Console/Kernel.php",
                    "*/Exceptions/Handler.php",
                    "*/Http/Kernel.php",
                    "*/Providers/*"
                ],
            }
        }
    },
    "folders":
    [
        {
            "path": "/Path/To/MyProject"
        }
    ],
    "settings":
    {
        "phpcs":
        {
            "extensions_to_execute":
            [
                "php"
            ],
            "phpcs_executable_path": "/Path/To/php_codesniffer/bin/phpcs",
            // Or if installed globally. "phpcbf_executable_path": "phpcs",
            "phpcs_additional_args":
            {
                "--standard": "/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml",
                // Optional don't show warnings
                // "-n": ""
            },
            "phpcbf_executable_path": "/Path/To/php_codesniffer/bin/phpcbf",
            // Or if installed globally. "phpcbf_executable_path": "phpcbf",
            "phpcbf_additional_args":
            {
                "--standard": "/Path/To/laravel-coding-standard/GreynoiseLaravel/ruleset.xml",
                // Optional don't fix warnings (if they're fixable)
                // "-n": ""
            },
            // Execute the sniffer on file save. (Using contextual menu instead)
            "phpcs_execute_on_save": false,
            // Show the error list after save. (Using sublime linter instead)
            "phpcs_show_errors_on_save": false,
            // Show the errors in the quick panel so you can then goto line. (Gets annoying)
            "phpcs_show_quick_panel": false,
            // Turn the debug output on/off.
            "show_debug": false
        }
    }
}