kvush / layer-violation-psalm-plugin
检测层依赖违规的 psalm-plugin
v0.2.1
2022-11-16 09:30 UTC
Requires
- php: >=7.1
- ext-simplexml: *
- vimeo/psalm: ^4.13
Requires (Dev)
- codeception/codeception: ^4.1
- phpunit/phpunit: ^9.5.5
- psalm/plugin-phpunit: ^0.16.0
- squizlabs/php_codesniffer: ^3.3
- weirdan/codeception-psalm-module: ^0.13.1
- weirdan/prophecy-shim: ^2.0
This package is auto-updated.
Last update: 2024-09-16 13:43:08 UTC
README
安装
composer require --dev kvush/layer-violation-psalm-plugin
vendor/bin/psalm-plugin enable kvush/layer-violation-psalm-plugin
功能
- 基于提供的配置检测层依赖违规
- 配置可以由多个 xml 文件分割
- 能够配置嵌套命名空间或保持严格匹配
配置
简单配置
<?xml version="1.0"?> <psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" totallyTyped="true" > <!-- project configuration --> <plugins> <pluginClass class="Kvush\LayerViolationPsalmPlugin\Plugin"> <context> <common> <acceptable name="JetBrains\PhpStorm" /> </common> <layer name="App"> <acceptable name="Symfony" /> </layer> <layer name="App\Domain\ContextA\*"> <acceptable name="App\Domain\ContextA\*" /> <acceptable name="App\DateTime" /> <acceptable name="App\EntityId" /> </layer> <layer name="App\Domain\ContextB\*"> <acceptable name="App\Domain\ContextB\*" /> <acceptable name="App\EntityId" /> </layer> </context> </pluginClass> </plugins> </psalm>
提取到任意命名的 xml 文件中
<?xml version="1.0"?> <psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" xmlns:xi="http://www.w3.org/2001/XInclude" totallyTyped="true" > <!-- project configuration --> <plugins> <pluginClass class="Kvush\LayerViolationPsalmPlugin\Plugin"> <xi:include href="path/to/root.xml"/> <xi:include href="path/to/common.xml"/> <xi:include href="path/to/contextA.xml"/> <xi:include href="path/to/contextB.xml"/> </pluginClass> </plugins> </psalm>
例如,Kernel 类可以由 root.xml 处理
<?xml version="1.0" encoding="UTF-8"?> <layer name="App"> <acceptable name="Symfony" /> </layer>
common.xml 中的某些常见规则
<?xml version="1.0" encoding="UTF-8"?> <common> <acceptable name="JetBrains\PhpStorm" /> </common>
分割上下文规则 contextA.xml
<?xml version="1.0" encoding="UTF-8"?> <context> <layer name="App\Domain\ContextA\*"> <acceptable name="App\Domain\ContextA\*" /> <acceptable name="App\DateTime" /> <acceptable name="App\EntityId" /> </layer> </context>
contextB.xml
<?xml version="1.0" encoding="UTF-8"?> <context> <layer name="App\Domain\ContextB\*"> <acceptable name="App\Domain\ContextB\*" /> <acceptable name="App\EntityId" /> </layer> </context>