単方向依存を実現する静的解析ライブラリのご紹介 / Analyze PHP Dependencies

単方向依存を実現する静的解析ライブラリのご紹介 / Analyze PHP Dependencies

クリーンアーキテクチャや独立したコアレイヤパターンなどのアーキテクチャ設計の広まりや、PHPがstaticに構造を持ち始めた時代を背景に、PHPの依存関係を静的解析するライブラリを作りましたのでご紹介しました。

是非使ってみてください!
https://packagist.org/packages/nazonohito51/dependency-analyzer

B989cc865d53d8e26fdadac99727113c?s=128

Satoshi Kawashima

March 31, 2019
Tweet

Transcript

  1. 6.
  2. 7.

    ゖ❣㰆׊יַ׾ؠٚت؅⪒י䧸ׅ׻  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } }
  3. 21.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } }
  4. 22.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } UZQFIJOUJOH
  5. 23.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } SFUVSOWBMVFUZQF
  6. 24.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } OFXPCKFDU
  7. 25.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } DBMMQVCMJDNFUIPE
  8. 26.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } QVCMJDQSPQFSUZGFUDI
  9. 27.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } QVCMJDDPOTUBOUGFUDI
  10. 28.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } QIQEPD
  11. 29.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } FYUFOET
  12. 30.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } JNQMFNFOUT
  13. 31.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } VTFUSBJU
  14. 32.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } UISPX
  15. 33.

    ❆ֻף׆סؠٚتס㕙⺬  class SomeClass extends ParentClass implements SomeInterface { use

    SomeTrait; private $someClass1; public function __construct() { $this->someClass1 = new SomeClass1(SomeClass1::STATUS_OK); } public function someMethod(SomeClass1 $someClass1): SomeClass3 { try { $unknownClass = $someClass1->someMethod1($this->someClass1->property); if (!$unknownClass instanceof SomeClass2) { throw new SomeException(); } return $unknownClass->getSomeClass3(); } catch (SomeException $e) { // TODO: error handling } } /** * @return SomeClass2[] */ public function returnValueTypeByPhpDoc(): array { return [new SomeClass2(), new SomeClass2()]; } } DBUDI
  16. 36.

    ⪒ؠٚتס❣㰆꞊➟؅꥗״յ  %FQFOEFS %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFS %FQFOEFF

    %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFS %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFS %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFS %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFS %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF %FQFOEFF
  17. 42.

    ❣㰆ٜ٭ٜס䧗㲊亠嫎  <?php return [ 'Layer dependency rule' => [

    'controller_layer' => [ 'define' => ['\App\\', '!\App\Providers\\'], ], 'application_layer' => [ 'define' => ['\Acme\Application\\'], 'depender' => ['controller_layer'], ], 'domain_layer' => [ 'define' => ['\Acme\Domain\\'], 'depender' => ['application_layer'] ] ] ];
  18. 43.

    <?php return [ 'Layer dependency rule' => [ 'controller_layer' =>

    [ 'define' => ['\App\\', '!\App\Providers\\'], ], 'application_layer' => [ 'define' => ['\Acme\Application\\'], 'depender' => ['controller_layer'], ], 'domain_layer' => [ 'define' => ['\Acme\Domain\\'], 'depender' => ['application_layer'] ] ] ]; ❣㰆ٜ٭ٜס䧗㲊亠嫎  ٜ٭ٜ⺲
  19. 44.

    <?php return [ 'Layer dependency rule' => [ 'controller_layer' =>

    [ 'define' => ['\App\\', '!\App\Providers\\'], ], 'application_layer' => [ 'define' => ['\Acme\Application\\'], 'depender' => ['controller_layer'], ], 'domain_layer' => [ 'define' => ['\Acme\Domain\\'], 'depender' => ['application_layer'] ] ] ]; ❣㰆ٜ٭ٜס䧗㲊亠嫎  ؤ٤َ٭ؾ٤عס㲊紶 ⺲⯥狜ꝴך䧗㲊
  20. 45.

    <?php return [ 'Layer dependency rule' => [ 'controller_layer' =>

    [ 'define' => ['\App\\', '!\App\Providers\\'], ], 'application_layer' => [ 'define' => ['\Acme\Application\\'], 'depender' => ['controller_layer'], ], 'domain_layer' => [ 'define' => ['\Acme\Domain\\'], 'depender' => ['application_layer'] ] ] ]; ❣㰆ٜ٭ٜס䧗㲊亠嫎  ؤ٤َ٭ؾ٤عס❣㰆ٜ٭ٜס㲊紶 EFQFOEFS❣㰆׈׿י׵荁ַؤ٤َ٭ؾ٤ع EQFFOEFF❣㰆׊י׵荁ַؤ٤َ٭ؾ٤ع
  21. 47.

    <?php return [ 'Layer dependency rule' => [ 'controller_layer' =>

    [ 'define' => ['\App\\', '!\App\Providers\\'], ], 'application_layer' => [ 'define' => ['\Acme\Application\\'], 'depender' => ['controller_layer'], ], 'domain_layer' => [ 'define' => ['\Acme\Domain\\'], 'depender' => ['application_layer'] ] ] ]; ❣㰆ٜ٭ٜס䧗㲊亠嫎  ׆סٜ٭ٜنٜؒؕ舅⛮ֿյ אסَٛةعٛמֽׄ׾ 錃銶䧗ꄠס辐伺כ׊י䣽ֻ׾
  22. 48.

    QIQEPDמ׻׾❣㰆ٜ٭ٜס䧗㲊  <?php declare(strict_types=1); namespace Acme\Domain\ValueObjects; /** * @canOnlyUsedBy \Acme\Domain\Entities\User

    * @canOnlyUsedBy \Acme\Domain\Repositories\UserRepository */ class UserName { // ... } !DBO0OMZ6TFE#Z ך׆סؠٚتמ❣㰆׊י׵荁ַؠٚت؅꡾㲊⴫
  23. 50.

    <?php $controllerDefine = ['\App\\', '!\App\Providers\\']; $applicationDefine = ['\Acme\Application\\']; $domainDefine =

    ['\Acme\Domain\\']; return [ '<error>Facadeܯ࡯ͩɺखΛ্͛Ζʂʂ </error>' => [ 'Sanctuary' => [ 'define' => array_merge($controllerDefine, $applicationDefine, $domainDefine), 'dependee' => ['!Facade'] ], 'Facade' => [ 'define' => [ '\App','\Artisan','\Auth','\Blade','\Broadcast','\Bus','\Cache','\Config', '\Cookie','\Crypt','\DB','\Event','\File','\Gate','\Hash','\Lang','\Log', '\Mail','\Notification','\Password','\Queue','\Redirect','\Request','\Response', '\Route','\Schema','\Session','\Storage','\URL','\Validator','\View' ] ] ] ]; 'BDBEF閛㴔׵ך׀׾ 