Skip to content

Commit 8dde776

Browse files
committed
format source files.
1 parent f7615ec commit 8dde776

20 files changed

+415
-224
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "smeghead/php-class-diagram",
33
"description": "A CLI tool that parses the PHP source directory and outputs PlantUML scripts.",
44
"type": "library",
5+
"keywords": [
6+
"classdiagram",
7+
"PlantUML"
8+
],
59
"require": {
610
"php" : ">=8.0",
711
"symfony/finder": "^5.3",

src/Config/Options.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Smeghead\PhpClassDiagram\Config;
36

4-
class Options {
7+
class Options
8+
{
59
private array $opt;
610

711
const PHP5 = 'php5';
@@ -12,11 +16,13 @@ class Options {
1216
const DIAGRAM_PACKAGE = 'package';
1317
const DIAGRAM_JIG = 'jig';
1418

15-
public function __construct(array $opt) {
19+
public function __construct(array $opt)
20+
{
1621
$this->opt = $opt;
1722
}
1823

19-
public function help(): bool {
24+
public function help(): bool
25+
{
2026
if (isset($this->opt['h'])) {
2127
return true;
2228
}
@@ -26,7 +32,8 @@ public function help(): bool {
2632
return false;
2733
}
2834

29-
public function diagram(): string {
35+
public function diagram(): string
36+
{
3037
if (isset($this->opt['class-diagram'])) {
3138
return self::DIAGRAM_CLASS;
3239
}
@@ -40,7 +47,8 @@ public function diagram(): string {
4047
return self::DIAGRAM_CLASS;
4148
}
4249

43-
public function classProperties(): bool {
50+
public function classProperties(): bool
51+
{
4452
if (isset($this->opt['enable-class-properties'])) {
4553
return true;
4654
}
@@ -51,7 +59,8 @@ public function classProperties(): bool {
5159
return true;
5260
}
5361

54-
public function classMethods(): bool {
62+
public function classMethods(): bool
63+
{
5564
if (isset($this->opt['enable-class-methods'])) {
5665
return true;
5766
}
@@ -62,7 +71,8 @@ public function classMethods(): bool {
6271
return true;
6372
}
6473

65-
public function phpVersion(): string {
74+
public function phpVersion(): string
75+
{
6676
if (isset($this->opt['php5'])) {
6777
return self::PHP5;
6878
}
@@ -79,11 +89,12 @@ public function phpVersion(): string {
7989
/**
8090
* @return string[] specified headers
8191
*/
82-
public function headers(): array {
92+
public function headers(): array
93+
{
8394
$headers = [];
8495
if (isset($this->opt['header'])) {
8596
$headers = $this->opt['header'];
86-
if ( ! is_array($headers)) {
97+
if (!is_array($headers)) {
8798
$headers = [$headers];
8899
}
89100
}
@@ -93,11 +104,12 @@ public function headers(): array {
93104
/**
94105
* @return string[] specified includes
95106
*/
96-
public function includes(): array {
107+
public function includes(): array
108+
{
97109
$includes = [];
98110
if (isset($this->opt['include'])) {
99111
$includes = $this->opt['include'];
100-
if ( ! is_array($includes)) {
112+
if (!is_array($includes)) {
101113
$includes = [$includes];
102114
}
103115
} else {
@@ -109,11 +121,12 @@ public function includes(): array {
109121
/**
110122
* @return string[] specified excludes
111123
*/
112-
public function excludes(): array {
124+
public function excludes(): array
125+
{
113126
$excludes = [];
114127
if (isset($this->opt['exclude'])) {
115128
$excludes = $this->opt['exclude'];
116-
if ( ! is_array($excludes)) {
129+
if (!is_array($excludes)) {
117130
$excludes = [$excludes];
118131
}
119132
}

src/DiagramElement/Arrow.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Smeghead\PhpClassDiagram\DiagramElement;
36

4-
use Smeghead\PhpClassDiagram\Php\ {
5-
PhpType,
6-
PhpClass,
7+
use Smeghead\PhpClassDiagram\Php\{
8+
PhpType,
9+
PhpClass,
710
};
811

9-
abstract class Arrow {
12+
abstract class Arrow
13+
{
1014
protected string $figure = '..>';
1115
private PhpClass $from;
1216
private PhpType $to;
1317

14-
public function __construct(PhpClass $from, PhpType $to) {
18+
public function __construct(PhpClass $from, PhpType $to)
19+
{
1520
$this->from = $from;
1621
$this->to = $to;
1722
}
1823

19-
public function getFrom(): PhpClass {
20-
return $this->from;
24+
public function getFrom(): PhpClass
25+
{
26+
return $this->from;
2127
}
2228

23-
public function getTo(): PhpType {
24-
return $this->to;
29+
public function getTo(): PhpType
30+
{
31+
return $this->to;
2532
}
2633

2734
abstract public function toString(PhpClass $toClass): string;

src/DiagramElement/ArrowDependency.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Smeghead\PhpClassDiagram\DiagramElement;
36

47
use Smeghead\PhpClassDiagram\Php\PhpClass;
58

6-
class ArrowDependency extends Arrow {
9+
class ArrowDependency extends Arrow
10+
{
711
protected string $figure = '..>';
812

9-
public function toString(PhpClass $toClass): string {
13+
public function toString(PhpClass $toClass): string
14+
{
1015
if (strpos($this->getTo()->getName(), '[]') === false) {
1116
return sprintf(' %s %s %s', $this->getFrom()->getClassNameAlias(), $this->figure, $toClass->getClassNameAlias());
1217
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Smeghead\PhpClassDiagram\DiagramElement;
36

47
use Smeghead\PhpClassDiagram\Php\PhpClass;
58

6-
class ArrowInheritance extends Arrow {
9+
class ArrowInheritance extends Arrow
10+
{
711
protected string $figure = '<|--';
812

9-
public function toString(PhpClass $toClass): string {
13+
public function toString(PhpClass $toClass): string
14+
{
1015
return sprintf(' %s %s %s', $toClass->getClassNameAlias(), $this->figure, $this->getFrom()->getClassNameAlias());
1116
}
1217
}

src/DiagramElement/Entry.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
1-
<?php declare(strict_types=1);
1+
<?php
2+
3+
declare(strict_types=1);
4+
25
namespace Smeghead\PhpClassDiagram\DiagramElement;
36

47
use Smeghead\PhpClassDiagram\Config\Options;
5-
use Smeghead\PhpClassDiagram\Php\ {
8+
use Smeghead\PhpClassDiagram\Php\{
69
PhpClass,
710
PhpAccessModifier,
811
PhpMethodParameter,
912
};
1013

11-
class Entry {
14+
class Entry
15+
{
1216
private Options $options;
1317
private string $directory;
1418
private PhpClass $class;
1519

16-
public function __construct(string $directory, PhpClass $class, Options $options) {
20+
public function __construct(string $directory, PhpClass $class, Options $options)
21+
{
1722
$this->directory = $directory;
1823
$this->class = $class;
1924
$this->options = $options;
2025
}
2126

22-
public function getOptions(): Options {
27+
public function getOptions(): Options
28+
{
2329
return $this->options;
2430
}
2531

26-
public function getDirectory(): string {
32+
public function getDirectory(): string
33+
{
2734
return $this->directory;
2835
}
2936

30-
public function getClass(): PhpClass {
37+
public function getClass(): PhpClass
38+
{
3139
return $this->class;
3240
}
3341

34-
public function dump($level = 0): array {
42+
public function dump($level = 0): array
43+
{
3544
$indent = str_repeat(' ', $level);
3645
$lines = [];
3746
// $meta = $this->class->getClassType()->getMeta() === 'Stmt_Interface' ? 'interface' : 'class';
@@ -45,7 +54,7 @@ public function dump($level = 0): array {
4554
}
4655
if ($this->options->classMethods()) {
4756
foreach ($this->class->getMethods() as $m) {
48-
$params = array_map(function(PhpMethodParameter $x){
57+
$params = array_map(function (PhpMethodParameter $x) {
4958
return $x->getName();
5059
}, $m->getParams());
5160
$lines[] = sprintf(' %s%s%s(%s)', $indent, $this->modifier($m->getAccessModifier()), $m->getName(), implode(', ', $params));
@@ -58,7 +67,8 @@ public function dump($level = 0): array {
5867
return $lines;
5968
}
6069

61-
private function modifier(PhpAccessModifier $modifier): string {
70+
private function modifier(PhpAccessModifier $modifier): string
71+
{
6272
$expressions = [];
6373
if ($modifier->isStatic()) {
6474
$expressions[] = '{static}';
@@ -75,10 +85,11 @@ private function modifier(PhpAccessModifier $modifier): string {
7585
if ($modifier->isPrivate()) {
7686
$expressions[] = '-';
7787
}
78-
return implode(' ' , $expressions);
88+
return implode(' ', $expressions);
7989
}
8090

81-
public function getArrows(): array {
91+
public function getArrows(): array
92+
{
8293
$arrows = [];
8394
//フィールド変数の型に対しての依存をArrowとして追加する。
8495
foreach ($this->class->getProperties() as $p) {
@@ -87,7 +98,7 @@ public function getArrows(): array {
8798
}
8899
}
89100
foreach ($this->class->getMethods() as $m) {
90-
if ( ! $m->getAccessModifier()->isPublic()) {
101+
if (!$m->getAccessModifier()->isPublic()) {
91102
continue;
92103
}
93104
foreach ($m->getParams() as $p) {
@@ -100,7 +111,7 @@ public function getArrows(): array {
100111
}
101112
}
102113
$extends = $this->class->getExtends();
103-
if ( ! empty($extends)) {
114+
if (!empty($extends)) {
104115
//継承先に対してArrowを追加する。
105116
foreach ($extends as $extend) {
106117
$arrows[] = new ArrowInheritance($this->class, $extend);

0 commit comments

Comments
 (0)