sweetchuck/robo-cdd

Robo task wrapper for the Circular Dependency Detector

v0.1.0 2019-12-31 22:52 UTC

This package is auto-updated.

Last update: 2024-12-17 18:37:30 UTC


README

CircleCI codecov

@todo

Install

composer require --dev sweetchuck/robo-cdd

Usage

RoboFile.php

<?php

use Robo\Collection\CollectionBuilder;
use Robo\State\Data as RoboStateData;
use Sweetchuck\Robo\cdd\CircularDependencyTaskLoader;

class RoboFile extends \Robo\Tasks
{
    use CircularDependencyTaskLoader;

    /**
     * @command validate:module-dependencies
     */
    public function validateModuleDependencies(): CollectionBuilder
    {
        return $this
            ->collectionBuilder()
            ->addCode(function (RoboStateData $data): int {
                $data['moduleDependencies'] = $this->collectModuleDependencies();

                return 0;
            })
            ->addTask(
                $this
                    ->taskCircularDependencyDetector()
                    ->setItemLabel('module')
                    ->deferTaskConfiguration('setItems', 'moduleDependencies')
            );
    }

    protected function collectModuleDependencies(): array
    {
        return [
            'a' => ['b'],
            'b' => ['c'],
            'c' => ['a'],
            'd' => ['e'],
            'e' => ['d'],
        ];
    }
}

CLI command

vendor/bin/robo validate:module-dependencies

Output is something like this:

 [Circular Dependency Detector] Detect dependencies among 5 of module items
 [Sweetchuck\Robo\cdd\Task\CircularDependencyDetectorTask]
c
    a
        b
            c

e
    d
        e
 [Sweetchuck\Robo\cdd\Task\CircularDependencyDetectorTask]  Exit code 1