如何在Yii2项目中安装Yii2代码标准?

如何在Yii2项目中安装Yii2代码标准?,yii2,yii2-advanced-app,Yii2,Yii2 Advanced App,$./vendor/bin/phpcs backend/controllers/AdvertisementController.php --颜色 接下来,在项目根目录上创建phpcs.xml.dist文件,请参阅 PHP_CodeSniffer文档:使用默认配置文件 <?xml version="1.0"?> <ruleset name="Yii2 App Basic Standard"> <description>Yii2 App Basic cod

$./vendor/bin/phpcs backend/controllers/AdvertisementController.php --颜色

接下来,在项目根目录上创建phpcs.xml.dist文件,请参阅 PHP_CodeSniffer文档:使用默认配置文件

<?xml version="1.0"?>
<ruleset name="Yii2 App Basic Standard">
    <description>Yii2 App Basic coding standard</description>

    <exclude-pattern>/runtime/*</exclude-pattern>
    <exclude-pattern>/web/assets/*</exclude-pattern>
    <exclude-pattern>/vendor/*</exclude-pattern>
    <exclude-pattern>/requirements.php</exclude-pattern>

    <rule ref="vendor/yiisoft/yii2-coding-standards/Yii2"/>

    <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
        <exclude-pattern>/migrations/*</exclude-pattern>
    </rule>
    <rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
        <exclude-pattern>/migrations/*</exclude-pattern>
    </rule>
</ruleset>
接下来,在项目根目录上创建一个
phpcs.xml.dist
文件,请参阅
PHP\u CodeSniffer
文档:使用默认配置文件

<?xml version="1.0"?>
<ruleset name="Yii2 App Basic Standard">
    <description>Yii2 App Basic coding standard</description>

    <exclude-pattern>/runtime/*</exclude-pattern>
    <exclude-pattern>/web/assets/*</exclude-pattern>
    <exclude-pattern>/vendor/*</exclude-pattern>
    <exclude-pattern>/requirements.php</exclude-pattern>

    <rule ref="vendor/yiisoft/yii2-coding-standards/Yii2"/>

    <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
        <exclude-pattern>/migrations/*</exclude-pattern>
    </rule>
    <rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
        <exclude-pattern>/migrations/*</exclude-pattern>
    </rule>
</ruleset>
这引发了一个错误vendor/bin/phpcs--encoding=utf-8 --extensions=php


我如何将Yi2安装为编码标准

首先,您尝试安装扩展,您应该知道它的用途为什么要使用它,以及何时使用

以下代码样式用于Yii 2.x core和official 扩展开发。如果要将请求代码拉入 核心,考虑使用它。

我们不会强迫您在应用程序中使用这种代码样式。 你可以自由选择更适合你的

何时使用 它仅在您开发
Yii2
而不使用时使用Yii2意味着仅当您要为框架的核心功能做出贡献时,才使用此扩展

何时忽视 如果您正在使用
Yii2框架进行项目,则无需安装此扩展,因为在这种情况下,如果您安装了PHPC,则PHPC可以直接工作,PHPC中已经使用的所有标准没有太大差异


你不需要这个扩展,别管它,PHPC可以直接做这项工作。

@MuhammadOmerAslam Bro请看这个为什么你要使用这个扩展?PHPC需要代码站在我的项目中运行。如果我使用PEAR、PSR-1或PSR-2,Zend It要求我提供文件名和类名的标记。因此,我通过安装Yii2代码标准完成了这项工作,并使用thers命令vendor/bin/phpcs--encoding=utf-8--extensions=php backend--colors将php.xml.dist文件添加到root@Sajid你看过我的答案了吗?我已经告诉过你你不需要它,PHPCS也不要求你安装Yii2代码标准。
 "require-dev": {
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-coding-standards": "2.*"
    }
<?xml version="1.0"?>
<ruleset name="Yii2 App Basic Standard">
    <description>Yii2 App Basic coding standard</description>

    <exclude-pattern>/runtime/*</exclude-pattern>
    <exclude-pattern>/web/assets/*</exclude-pattern>
    <exclude-pattern>/vendor/*</exclude-pattern>
    <exclude-pattern>/requirements.php</exclude-pattern>

    <rule ref="vendor/yiisoft/yii2-coding-standards/Yii2"/>

    <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
        <exclude-pattern>/migrations/*</exclude-pattern>
    </rule>
    <rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
        <exclude-pattern>/migrations/*</exclude-pattern>
    </rule>
</ruleset>
php composer.phar install --dev
vendor/bin/phpcs --encoding=utf-8 --extensions=php .
 coding standard is not installed. The installed coding standards are
 MySource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend