Skip to content

Commit 1dc80fb

Browse files
committed
feat: search dependency from method code.
Until now, dependency information was obtained from class fields and method signatures, but now the dependency information is also obtained from within the method code.
1 parent 22d5f93 commit 1dc80fb

20 files changed

+165
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Features
44

55
* added to run PHPStan in GitHub Action flow.
6+
* Until now, dependency information was obtained from class fields and method signatures, but now the dependency information is also obtained from within the method code.
67

78
## v1.1.1 (2023-07-30)
89

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"scripts": {
3333
"test": [
34-
"php vendor/phpunit/phpunit/phpunit test/"
34+
"php vendor/phpunit/phpunit/phpunit --colors test/"
3535
],
3636
"build": [
3737
"php -d phar.readonly=off ./vendor/bin/phar-composer build ./"

dogfood-model.png

12.2 KB
Loading

dogfood-package.png

-217 Bytes
Loading

dogfood.png

25 KB
Loading

src/DiagramElement/Entry.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,16 @@ public function getArrows(): array
166166

167167
return $arrows;
168168
}
169+
170+
/**
171+
* @return Arrow[] using arrows.
172+
*/
173+
public function getUsingArrows(): array
174+
{
175+
$arrows = [];
176+
foreach ($this->getClass()->getUsingTypes() as $t) {
177+
$arrows[] = new ArrowDependency($this->class, $t);
178+
}
179+
return $arrows;
180+
}
169181
}

src/DiagramElement/Package.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public function getArrows(): array
143143
foreach ($this->children as $n) {
144144
$arrows = array_merge($arrows, $n->getArrows());
145145
}
146+
foreach ($this->entries as $n) {
147+
$arrows = array_merge($arrows, $n->getUsingArrows());
148+
}
149+
146150
return $arrows;
147151
}
148152

src/DiagramElement/Relation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public function dump(): array
4949
*/
5050
public function getRelations(): array
5151
{
52-
$entities = $this->package->getEntries();
53-
$relation_expressions = array_map(function (Arrow $x) use ($entities) {
54-
foreach ($entities as $e) {
52+
$entries = $this->package->getEntries();
53+
$relation_expressions = array_map(function (Arrow $x) use ($entries) {
54+
foreach ($entries as $e) {
5555
if ($e->getClass()->getClassType()->equals($x->getTo())) {
5656
return $x->toString($e->getClass());
5757
}
@@ -60,7 +60,7 @@ public function getRelations(): array
6060
}, $this->package->getArrows());
6161
$relation_expressions = array_filter($relation_expressions);
6262
sort($relation_expressions);
63-
return array_unique($relation_expressions);
63+
return array_values(array_unique($relation_expressions));
6464
}
6565

6666
/**

src/Php/Doc/PhpDocComment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Smeghead\PhpClassDiagram\Php\Doc;
66

7-
use PhpParser\Node\Stmt;
7+
use PhpParser\Node;
88
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
99
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
1010
use PHPStan\PhpDocParser\Lexer\Lexer;
@@ -17,7 +17,7 @@ class PhpDocComment
1717
{
1818
private string $text = '';
1919

20-
public function __construct(Stmt $stmt)
20+
public function __construct(Node $stmt)
2121
{
2222
$doc = $stmt->getDocComment();
2323
if (!empty($doc)) {

src/Php/Finders/FindConstructerProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use PhpParser\Node\Stmt\ClassMethod;
1212
use PhpParser\NodeFinder;
1313

14-
class FindConstructerProperties
14+
final class FindConstructerProperties
1515
{
1616
/** @var \PhpParser\Node\Param[] */
1717
private array $properties = [];

0 commit comments

Comments
 (0)