PHPCS 不同目录的不同规则集

PHPCS different ruleset for different directories

我目前正在清理现有代码库,其中一个方面涉及使用 PHPCS。这是我目前的 phpcs.xml 文件:

<?xml version='1.0'?>
<ruleset name='MyApplication'>
    <arg name='encoding' value='utf-8'/>
    <arg name='extensions' value='php'/>
    <arg name='warning-severity' value='0'/>
    <arg name='colors'/>
    <arg value='p'/>

    <exclude-pattern>vendor/*</exclude-pattern>
    <exclude-pattern>node_modules/*</exclude-pattern>

    <rule ref='PSR1'></rule>
</ruleset>

我想修改它,以便将 PSR-2 应用于某些目录(例如 foo/bar/),同时根据 PSR-1 检查其余目录。

我在手册中找到了可以作为 <rule> 元素的子元素放置的 <exclude-pattern> 选项,但我需要相反的选项。

创建多个配置并使用 --standard 选项加载它们:

vendor/bin/phpcs source-to-check --standard first-settings.xml 
vendor/bin/phpcs another-to-check --standard second-settings.xml 
./vendor/bin/phpcs /project/path --standard=/other/path/phpcs.xml