Skip to content

Commit e3b7b7a

Browse files
authored
Merge pull request #49 from smeghead/add-relations-from-method-code
feat: search dependency from method code.
2 parents 22d5f93 + 295d3c6 commit e3b7b7a

21 files changed

+166
-22
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
php-versions: ['8.0', '8.1', '8.2']
1616
name: PHP ${{ matrix.php-versions }} Test
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919

2020
- name: Install PHP
2121
uses: shivammathur/setup-php@v2

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)) {

0 commit comments

Comments
 (0)