PHP code example of nazonohito51 / dependency-analyzer

1. Go to this page and download the library: Download nazonohito51/dependency-analyzer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nazonohito51 / dependency-analyzer example snippets



// ./your_rule_file.php

return [
    'layer dependency rule' => [                // name of your rule
        'domain_layer' => [                     // component name
            'define' => ['\Acme\Domain\\'],     // component definition by FQSEN
            'depender' => ['application_layer'] // rule of component dependency, for depender
        ],
        'application_layer' => [
            'define' => ['\Acme\Application\\'],
            'depender' => ['controller_layer']
        ],
        'controller_layer' => [
            'define' => ['\App\\', '!\App\Providers\\']
        ]
    ],
//    'some more rules' => [
//        'SomeComponent' => ['...'],
//        '...' => []
//    ]
];


namespace Acme\Domain\Entities;

/**
 * Don't touch this class in \App\.
 * @da-internal !\App\
 */
class User
{
    /**
     * Don't use `new User();` in places other than Repository.
     * @da-internal \Acme\Domain\Repositories\
     */
    public function __construct()
    {
        // ...
    }

    /**
     * Don't touch password in places other than authenticate functions.
     * @da-internal \Acme\Application\Authenticator
     * @da-internal \Acme\Application\UseCases\UpdatePasswordInteractor
     */
    public function getPassword()
    {
        // ...
    }
}
bash
php vendor/bin/analyze-deps verify --rule ./your_rule_file.php ./some/analyze/dir1 ./some/analyze/dir2
bash
php vendor/bin/analyze-deps detect-cycle ./some/analyze/dir