Skip to content

Commit ec47db9

Browse files
committed
feat: --rel-target option
1 parent 536b136 commit ec47db9

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

bin/php-class-diagram

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ $options = getopt('hv', [
3939
'exclude::',
4040
'rel-target-from::',
4141
'rel-target-to::',
42+
'rel-target::',
4243
'rel-target-depth::',
4344
], $rest_index);
4445
$arguments = array_slice($argv, $rest_index);
@@ -70,6 +71,8 @@ OPTIONS
7071
--exclude='wildcard' exclude target file pattern. You can specify multiple exclude patterns.
7172
--rel-target-from='clases' comma separated list of classes to filter dependencies from
7273
--rel-target-to='classes' comma separated list of classes to filter dependencies to
74+
--rel-target='classes' comma separated list of classes to filter dependencies from or to. this option overrides
75+
--rel-target-from and --rel-target-to if set.
7376
--rel-target-depth=integer max depth of dependencies to show when using --from or --to filters
7477
EOS;
7578

src/Config/Options.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ public function toClass(): array
191191
return explode(',', $this->opt['rel-target-to']);
192192
}
193193

194+
/**
195+
* @return array<string>
196+
*/
197+
public function targetClass(): array
198+
{
199+
if (!isset($this->opt['rel-target'])) {
200+
return [];
201+
}
202+
203+
return explode(',', $this->opt['rel-target']);
204+
}
205+
194206
public function depth(): int
195207
{
196208
return (int) ($this->opt['rel-target-depth'] ?? PHP_INT_MAX);

src/DiagramElement/RelationsFilter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public function filterRelations(array $relation_expressions): array
2929
$output = [];
3030
$fromClasses = $this->options->fromClass();
3131
$toClasses = $this->options->toClass();
32+
33+
if ([] !== $this->options->targetClass()) {
34+
$fromClasses = $this->options->targetClass();
35+
$toClasses = $this->options->targetClass();
36+
}
37+
3238
$this->maxDepth = $this->options->depth() - 1;
3339
$this->relationExpressions = $relation_expressions;
3440

test/RelationsFilterTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ public function testFiltersInboundRelations(): void
7575
$this->assertSame(" Relation ..> PackageRelations", $result[4]);
7676
}
7777

78+
public function testFiltersTargetRelations(): void
79+
{
80+
$relationsFilter = new RelationsFilter(new Options([
81+
'rel-target' => 'Entry'
82+
]));
83+
84+
$result = $relationsFilter->filterRelations($this->fixture);
85+
86+
$this->assertSame(" Entry \"1\" ..> \"*\" Arrow", $result[0]);
87+
$this->assertSame(" Entry ..> Division_DivisionColor", $result[1]);
88+
$this->assertSame(" Entry ..> ArrowDependency", $result[2]);
89+
$this->assertSame(" Entry ..> ArrowInheritance", $result[3]);
90+
$this->assertSame(" Package \"1\" ..> \"*\" Package", $result[4]);
91+
$this->assertSame(" Package \"1\" ..> \"*\" Entry", $result[5]);
92+
$this->assertSame(" Package ..> Entry", $result[6]);
93+
$this->assertSame(" Package ..> Package", $result[7]);
94+
$this->assertSame(" PackageRelations ..> Package", $result[8]);
95+
$this->assertSame(" Relation ..> Package", $result[9]);
96+
$this->assertSame(" Relation \"1\" ..> \"*\" Entry", $result[10]);
97+
$this->assertSame(" Relation ..> PackageRelations", $result[11]);
98+
}
99+
78100
public function testFiltersInboundRelationsWithDepth(): void
79101
{
80102
$relationsFilter = new RelationsFilter(new Options([

0 commit comments

Comments
 (0)