php dependency analysis
1.0.0
PHP DA是您项目内部检查和支持依赖项的工具。
例如:
[
' dependencies ' => [
' Domain ' => null ,
' Application ' => [ ' Domain ' ],
' Infrastructure ' => [ ' Domain ' , ' Application ' ]
]
];这意味着域名空间中的所有类都应仅使用此名称空间中的类,甚至应使用供应商(已配置)。
应用程序中的所有类都可以使用域和应用程序名称空间的类,而不是基础结构等
如果某些使用依赖项不满足定义依赖关系图的类,则会在报告中给出错误:
Have been analyzed 4 files
You have dependency problems in 2 files in your project:
Class ApplicationTrackingService have errors:
- Class ApplicationTrackingService using class InfrastructureShipImplementation which not satisfy dependency graph
Class DomainCargo have errors:
- Class DomainCargo using class ApplicationTrackingService which not satisfy dependency graph
- Class DomainCargo using class InfrastructureShipImplementation which not satisfy dependency graph
在某些情况下,它可能很有用:
使用作曲家安装库
composer require paglliac/dependency-analysis
将配置文件config.php添加到项目的根源:
return [
/**
* REQUIRED
* Dependencies Graph
*
* Description of valid dependencies in project
*
* This config means
*
* Package (every class in namespace) Domain can use only classes from namespace Domain or vendor dependencies
* Package Application can use only classes from namespaces Domain, Application or vendor dependencies
* Package Infrastructure can use only classes from namespaces Domain, Application, Infrastructure or vendor dependencies
*/
' dependencies ' => [
' Domain ' => null ,
' Application ' => [ ' Domain ' ],
' Infrastructure ' => [ ' Domain ' , ' Application ' ]
],
/**
* REQUIRED
* Source path where dependencies will be analyzed
*/
' path ' => __DIR__ ,
/**
* OPTIONAL
*
* Make available to use vendor dependencies in whole project
*
* true - all project classes can use vendor dependencies
* false - all project can not use vendor dependencies
*/
' skip_vendor_dir ' => true ,
/**
* OPTIONAL
* Flag that define how to do when some files placed in namespaces not presented in Dependencies Graph
*
* true - mark class as having incorrect dependencies
* false - skip this file
*
* For example, in directory we have namespace SomeNamespace with class SomeNamespaceSomeClass
* if flag is true, it will be marked as incorrect file, if flag is true, this file wil be marked as correct
*/
' fail_on_non_presented_namespace ' => false ,
/**
* OPTIONAL
* Flag for php parser, correct values:
*
* PhpParserParserFactory::PREFER_PHP7 - 1 (default)
* PhpParserParserFactory::PREFER_PHP5 - 2
* PhpParserParserFactory::ONLY_PHP7 - 3
* PhpParserParserFactory::ONLY_PHP5 - 4
*/
' php_version ' => PhpParser ParserFactory:: PREFER_PHP7 ,
/**
* OPTIONAL
*
* List of allowed files extensions, all files with other extensions will be skipped from analysis
*
* Default - ['php']
*/
' allowed_extensions ' => [ ' php ' ]
];运行依赖性验证:
/vendor/bin/php-da -c config.php [files filter]
选项:
-c或--config是需要的选择参数:
[files filter]用于分析的文件列表,在CI中使用与-diff相结合很有用 Have been analyzed 4 files
You have dependency problems in 2 files in your project:
Class ApplicationTrackingService have errors:
- Class ApplicationTrackingService using class InfrastructureShipImplementation which not satisfy dependency graph
Class DomainCargo have errors:
- Class DomainCargo using class ApplicationTrackingService which not satisfy dependency graph
- Class DomainCargo using class InfrastructureShipImplementation which not satisfy dependency graph