Skip to content

Commit

Permalink
Merge pull request #5 from DeGraciaMathieu/added-component-analyze
Browse files Browse the repository at this point in the history
Added component command
  • Loading branch information
DeGraciaMathieu authored Nov 17, 2024
2 parents af2727c + 803eb61 commit 7dc90f4
Show file tree
Hide file tree
Showing 109 changed files with 2,023 additions and 433 deletions.
50 changes: 50 additions & 0 deletions app/Application/Analyze/AnalyzeMetric.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Application\Analyze;

class AnalyzeMetric
{
public function __construct(
private readonly array $metric,
) {}

public function name(): string
{
return $this->metric['name'];
}

public function dependencies(): array
{
return $this->metric['dependencies'];
}

public function abstract(): bool
{
return $this->metric['abstract'];
}

public function efferentCoupling(): float
{
return $this->metric['coupling']['efferent'];
}

public function afferentCoupling(): float
{
return $this->metric['coupling']['afferent'];
}

public function instability(): float
{
return $this->metric['coupling']['instability'];
}

public function numberOfAbstractDependencies(): int
{
return $this->metric['abstractness']['numberOfAbstractDependencies'];
}

public function abstractnessRatio(): float
{
return $this->metric['abstractness']['ratio'];
}
}
11 changes: 9 additions & 2 deletions app/Application/Analyze/AnalyzeResponseMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ public function from(DependencyAggregator $dependencyAggregator): AnalyzeRespons
{
return new AnalyzeResponse(
count: $dependencyAggregator->count(),
metrics: $dependencyAggregator->toArray(),
metrics: $this->map($dependencyAggregator),
);
}
}

private function map(DependencyAggregator $dependencyAggregator): array
{
return array_map(function (array $metric) {
return new AnalyzeMetric($metric);
}, $dependencyAggregator->toArray());
}
}
14 changes: 13 additions & 1 deletion app/Commands/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@

abstract class AbstractCommand extends Command
{
public function stringToList(string $key): array
public function optionToList(string $key): array
{
$value = $this->option($key);

return $this->stringToList($value);
}

public function argumentToList(string $key): array
{
$value = $this->argument($key);

return $this->stringToList($value);
}

private function stringToList(?string $value): array
{
return $value === null ? [] : explode(',', $value);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Commands\Analyze;
namespace App\Commands\Analyze\Class;

use App\Commands\AbstractCommand;
use App\Application\Analyze\AnalyzeAction;
Expand All @@ -9,8 +9,7 @@

class AnalyzeCommand extends AbstractCommand
{
protected $signature = 'analyze {path}
{--components=}
protected $signature = 'analyze:class {path}
{--graph}
{--only=}
{--exclude=}
Expand All @@ -35,8 +34,8 @@ private function makeRequest(): AnalyzeRequest
{
return new AnalyzeRequest(
path: $this->argument('path'),
only: $this->stringToList('only'),
exclude: $this->stringToList('exclude'),
only: $this->optionToList('only'),
exclude: $this->optionToList('exclude'),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace App\Commands\Analyze\Graph;
namespace App\Commands\Analyze\Class\Graph;

use App\Presenter\Analyze\Graph\GraphView;
use LaravelZero\Framework\Commands\Command;
use App\Commands\Analyze\TransformerFactory;
use App\Presenter\Analyze\Graph\GraphPresenter;
use App\Presenter\Analyze\Graph\Ports\GraphMapper;
use App\Commands\Analyze\Graph\GraphSettingsFactory;
use App\Presenter\Analyze\Class\Graph\GraphView;
use App\Commands\Analyze\Class\TransformerFactory;
use App\Presenter\Analyze\Class\Graph\GraphMapper;
use App\Presenter\Analyze\Class\Graph\GraphPresenter;
use App\Commands\Analyze\Class\Graph\GraphSettingsFactory;

class GraphPresenterFactory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace App\Commands\Analyze\Graph;
namespace App\Commands\Analyze\Class\Graph;

use LaravelZero\Framework\Commands\Command;
use App\Presenter\Analyze\Graph\GraphSettings;
use App\Presenter\Analyze\Class\Graph\GraphSettings;

class GraphSettingsFactory
{
Expand Down
33 changes: 33 additions & 0 deletions app/Commands/Analyze/Class/PresenterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Commands\Analyze\Class;

use Illuminate\Console\Command;
use App\Application\Analyze\AnalyzePresenter;
use App\Commands\Analyze\Class\Graph\GraphPresenterFactory;
use App\Commands\Analyze\Class\Summary\SummaryPresenterFactory;

class PresenterFactory
{
public function __construct(
private readonly GraphPresenterFactory $graphPresenterFactory,
private readonly SummaryPresenterFactory $summaryPresenterFactory,
) {}

public function make(Command $command): AnalyzePresenter
{
return $command->option('graph')
? $this->makeGraphPresenter($command)
: $this->makeSummaryPresenter($command);
}

private function makeGraphPresenter(Command $command): AnalyzePresenter
{
return $this->graphPresenterFactory->make($command);
}

private function makeSummaryPresenter(Command $command): AnalyzePresenter
{
return $this->summaryPresenterFactory->make($command);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace App\Commands\Analyze\Summary;
namespace App\Commands\Analyze\Class\Summary;

use LaravelZero\Framework\Commands\Command;
use App\Commands\Analyze\TransformerFactory;
use App\Presenter\Analyze\Summary\SummaryView;
use App\Presenter\Analyze\Summary\SummaryMapper;
use App\Presenter\Analyze\Summary\SummaryPresenter;
use App\Commands\Analyze\Summary\SummarySettingsFactory;
use App\Commands\Analyze\Class\TransformerFactory;
use App\Presenter\Analyze\Class\Summary\SummaryView;
use App\Presenter\Analyze\Class\Summary\SummaryMapper;
use App\Presenter\Analyze\Class\Summary\SummaryPresenter;
use App\Commands\Analyze\Class\Summary\SummarySettingsFactory;

class SummaryPresenterFactory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace App\Commands\Analyze\Summary;
namespace App\Commands\Analyze\Class\Summary;

use LaravelZero\Framework\Commands\Command;
use App\Presenter\Analyze\Summary\SummarySettings;
use App\Presenter\Analyze\Class\Summary\SummarySettings;

class SummarySettingsFactory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace App\Commands\Analyze;
namespace App\Commands\Analyze\Class;

use LaravelZero\Framework\Commands\Command;
use App\Presenter\Analyze\Filters\Contracts\Transformer;
use App\Presenter\Analyze\Filters\Transformers\NullTransformer;
use App\Presenter\Analyze\Filters\Transformers\TargetTransformer;
use App\Presenter\Analyze\Shared\Filters\Contracts\Transformer;
use App\Presenter\Analyze\Shared\Filters\Transformers\NullTransformer;
use App\Presenter\Analyze\Shared\Filters\Transformers\TargetTransformer;

class TransformerFactory
{
Expand Down
41 changes: 41 additions & 0 deletions app/Commands/Analyze/Component/ComponentCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Commands\Analyze\Component;

use App\Commands\AbstractCommand;
use App\Application\Analyze\AnalyzeAction;
use App\Application\Analyze\AnalyzeRequest;
use App\Application\Analyze\AnalyzePresenter;
use App\Commands\Analyze\Component\Factories\PresenterFactory;

class ComponentCommand extends AbstractCommand
{
protected $signature = 'analyze:component {path} {components}
{--graph}
{--debug}
{--info}
{--human-readable : Display human readable metrics}
';

protected $description = '';

public function handle(AnalyzeAction $action): void
{
$action->execute(
request: $this->makeRequest(),
presenter: $this->makePresenter(),
);
}

private function makeRequest(): AnalyzeRequest
{
return new AnalyzeRequest(
path: $this->argument('path'),
);
}

private function makePresenter(): AnalyzePresenter
{
return app(PresenterFactory::class)->make($this);
}
}
33 changes: 33 additions & 0 deletions app/Commands/Analyze/Component/Factories/PresenterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Commands\Analyze\Component\Factories;

use Illuminate\Console\Command;
use App\Application\Analyze\AnalyzePresenter;
use App\Commands\Analyze\Component\Graph\GraphPresenterFactory;
use App\Commands\Analyze\Component\Summary\SummaryPresenterFactory;

class PresenterFactory
{
public function __construct(
private readonly GraphPresenterFactory $graphPresenterFactory,
private readonly SummaryPresenterFactory $summaryPresenterFactory,
) {}

public function make(Command $command): AnalyzePresenter
{
return $command->option('graph')
? $this->makeGraphPresenter($command)
: $this->makeSummaryPresenter($command);
}

private function makeGraphPresenter(Command $command): AnalyzePresenter
{
return $this->graphPresenterFactory->make($command);
}

private function makeSummaryPresenter(Command $command): AnalyzePresenter
{
return $this->summaryPresenterFactory->make($command);
}
}
17 changes: 17 additions & 0 deletions app/Commands/Analyze/Component/Factories/TransformerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Commands\Analyze\Component\Factories;

use LaravelZero\Framework\Commands\Command;
use App\Presenter\Analyze\Shared\Filters\Contracts\Transformer;
use App\Presenter\Analyze\Shared\Filters\Transformers\ComponentTransformer;

class TransformerFactory
{
public static function make(Command $command): Transformer
{
return app(ComponentTransformer::class, [
'targetedComponents' => $command->argumentToList('components'),
]);
}
}
31 changes: 31 additions & 0 deletions app/Commands/Analyze/Component/Graph/GraphPresenterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Commands\Analyze\Component\Graph;

use LaravelZero\Framework\Commands\Command;
use App\Application\Analyze\AnalyzePresenter;
use App\Presenter\Analyze\Component\Graph\GraphView;
use App\Presenter\Analyze\Component\Graph\GraphMapper;
use App\Presenter\Analyze\Component\Graph\GraphPresenter;
use App\Commands\Analyze\Component\Graph\GraphSettingsFactory;
use App\Commands\Analyze\Component\Factories\TransformerFactory;

class GraphPresenterFactory
{
public function __construct(
private readonly GraphView $view,
private readonly GraphMapper $mapper,
private readonly TransformerFactory $transformerFactory,
private readonly GraphSettingsFactory $settingsFactory,
) {}

public function make(Command $command): AnalyzePresenter
{
return new GraphPresenter(
view: $this->view,
mapper: $this->mapper,
transformer: $this->transformerFactory->make($command),
settings: $this->settingsFactory->make($command),
);
}
}
18 changes: 18 additions & 0 deletions app/Commands/Analyze/Component/Graph/GraphSettingsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Commands\Analyze\Component\Graph;

use LaravelZero\Framework\Commands\Command;
use App\Presenter\Analyze\Component\Graph\GraphSettings;

class GraphSettingsFactory
{
public function make(Command $command): GraphSettings
{
return new GraphSettings(
components: $command->argumentToList('components'),
info: $command->option('info'),
debug: $command->option('debug'),
);
}
}
Loading

0 comments on commit 7dc90f4

Please sign in to comment.