php dependency analysis
1.0.0
PHP DAは、プロジェクト内のチェックおよびサポートの依存関係を明確にするためのツールです。
例えば:
[
' dependencies ' => [
' Domain ' => null ,
' Application ' => [ ' Domain ' ],
' Infrastructure ' => [ ' Domain ' , ' Application ' ]
]
];つまり、 Domain NameSpaceのすべてのクラスは、この名前空間からのクラスのみを使用し、場合によってはベンダー(設定)を使用する必要があります。
アプリケーションのすべてのクラスは、ドメインおよびアプリケーションの名前空間からのクラスを使用できますが、インフラストラクチャなどでは使用できません。
依存関係が定義された依存関係グラフを満たさない場合の一部のクラスは、レポートのエラーを示します。
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を使用してライブラリをインストールします
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 、configファイルへの相対パスを備えた必須オプションです議論:
[files filter]分析のためのファイルのリスト、CIで使用することは有用です---ディフ 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