Skip to content

Commit a618bfe

Browse files
authored
Merge pull request #47 from smeghead/phpstan
introduced PHPStan.
2 parents ec9d51e + 6d1bc41 commit a618bfe

File tree

18 files changed

+118
-41
lines changed

18 files changed

+118
-41
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
},
1414
"require-dev": {
1515
"phpunit/phpunit": "^9.5",
16-
"clue/phar-composer": "^1.2"
16+
"clue/phar-composer": "^1.2",
17+
"phpstan/phpstan": "^1.10"
1718
},
1819
"license": "Apache-2.0",
1920
"autoload": {

dogfood-model.png

2.72 KB
Loading

dogfood.png

6.39 KB
Loading

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src
5+
- tests

src/Config/Options.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66

77
class Options
88
{
9+
/** @var array<string, mixed> */
910
private array $opt;
1011

11-
const PHP5 = 'php5';
12-
const PHP7 = 'php7';
13-
const PHP8 = 'php8';
12+
public const PHP5 = 'php5';
13+
public const PHP7 = 'php7';
14+
public const PHP8 = 'php8';
1415

15-
const DIAGRAM_CLASS = 'class';
16-
const DIAGRAM_PACKAGE = 'package';
17-
const DIAGRAM_JIG = 'jig';
18-
const DIAGRAM_DIVSION = 'division';
16+
public const DIAGRAM_CLASS = 'class';
17+
public const DIAGRAM_PACKAGE = 'package';
18+
public const DIAGRAM_JIG = 'jig';
19+
public const DIAGRAM_DIVSION = 'division';
1920

21+
/**
22+
* @param array<string, mixed> $opt Option array
23+
*/
2024
public function __construct(array $opt)
2125
{
2226
$this->opt = $opt;

src/DiagramElement/Division/DivisionColor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class DivisionColor
88
{
9-
private static $gen;
9+
private static \Generator $gen;
1010
public static function nextColor(): string
1111
{
1212
if (empty(self::$gen)) {
@@ -27,6 +27,7 @@ function generateDivisionColorGenerator(): \Generator
2727
'#ccffff',
2828
'#ffccff',
2929
];
30+
// @phpstan-ignore-next-line
3031
while (true) {
3132
foreach ($COLORS as $c) {
3233
yield $c;

src/DiagramElement/Entry.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public function getClass(): PhpClass
4242
return $this->class;
4343
}
4444

45-
public function dump($level = 0): array
45+
/**
46+
* @return string[] diagram lines.
47+
*/
48+
public function dump(int $level = 0): array
4649
{
4750
$indent = str_repeat(' ', $level);
4851
$lines = [];
@@ -78,7 +81,10 @@ public function dump($level = 0): array
7881
return $lines;
7982
}
8083

81-
public function dumpDivisions($level = 0): array
84+
/**
85+
* @return string[] diagram lines.
86+
*/
87+
public function dumpDivisions(int $level = 0): array
8288
{
8389
$indent = str_repeat(' ', $level);
8490
$lines = [];
@@ -125,6 +131,9 @@ private function modifier(PhpAccessModifier $modifier): string
125131
return implode(' ', $expressions);
126132
}
127133

134+
/**
135+
* @return Arrow[] arrows
136+
*/
128137
public function getArrows(): array
129138
{
130139
$arrows = [];

src/DiagramElement/Package.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Package
2020
/** @var Entry[] entries */
2121
public array $entries = [];
2222

23+
/**
24+
* @param string[] $parents
25+
*/
2326
public function __construct(array $parents, string $name, Options $options)
2427
{
2528
$this->parents = $parents;
@@ -32,6 +35,9 @@ public function getLogicalName(): string
3235
return implode('.', array_merge(array_slice($this->parents, 1), [$this->name]));
3336
}
3437

38+
/**
39+
* @param string[] $paths Paths
40+
*/
3541
public function addEntry(array $paths, Entry $entry): string
3642
{
3743
if (count($paths) === 0) {
@@ -68,7 +74,10 @@ private function findChild(string $dir): Package
6874
return end($this->children);
6975
}
7076

71-
public function dump($level = 0): array
77+
/**
78+
* @return string[] diagram lines.
79+
*/
80+
public function dump(int $level = 0): array
7281
{
7382
$indent = str_repeat(' ', $level);
7483
$lines = [];
@@ -92,7 +101,10 @@ public function dump($level = 0): array
92101
return $lines;
93102
}
94103

95-
public function dumpPackages($level = 1): array
104+
/**
105+
* @return string[] diagram lines.
106+
*/
107+
public function dumpPackages(int $level = 1): array
96108
{
97109
$indent = str_repeat(' ', $level);
98110
$lines = [];
@@ -147,9 +159,10 @@ public function getEntries(): array
147159
}
148160

149161
/**
150-
* @return array useの一覧
162+
* @param array<string, \Smeghead\PhpClassDiagram\Php\PhpType[]> $acc list of uses.
163+
* @return array<string, \Smeghead\PhpClassDiagram\Php\PhpType[]> list of uses.
151164
*/
152-
public function getUses($acc): array
165+
public function getUses(array $acc): array
153166
{
154167
$uses = [];
155168
foreach ($this->entries as $e) {
@@ -165,8 +178,10 @@ public function getUses($acc): array
165178

166179
/**
167180
* 解析対象になっているpackage一覧を取得する。
181+
* @param array<string, string> $acc
182+
* @return array<string, string>
168183
*/
169-
public function getTargetPackages($acc = [])
184+
public function getTargetPackages(array $acc = []): array
170185
{
171186
$acc[$this->package] = $this->getLogicalName();
172187
foreach ($this->children as $n) {
@@ -205,7 +220,10 @@ private function recFindPackage(string $package): ?Package
205220
return null;
206221
}
207222

208-
public function dumpDivisions($level = 0): array
223+
/**
224+
* @return string[] diagram lines.
225+
*/
226+
public function dumpDivisions(int $level = 0): array
209227
{
210228
$indent = str_repeat(' ', $level);
211229
$lines = [];

src/DiagramElement/PackageArrow.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public function __construct(string $from, string $to)
1616
$this->to = $to;
1717
}
1818

19-
public function bothSideArrow()
19+
public function bothSideArrow(): void
2020
{
2121
$this->bothSideArrow = true;
2222
}
2323

24-
public function isOpposite(self $other)
24+
public function isOpposite(self $other): bool
2525
{
2626
if ($this->from !== $other->to) {
2727
return false;

src/DiagramElement/PackageRelations.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ private function displayPackage(string $package): string
3434
return $package; //外部のpackageはpackage表示
3535
}
3636

37+
/**
38+
* @return string[] arrows.
39+
*/
3740
public function getArrows(): array
3841
{
3942
$lines = [];
@@ -74,6 +77,10 @@ public function getArrows(): array
7477
return $lines;
7578
}
7679

80+
/**
81+
* @param PackageArrow[] $arrows arrows.
82+
* @return PackageArrow[] merged arrows.
83+
*/
7784
private function mergeBothSideArrow(array $arrows): array
7885
{
7986
$merged = [];
@@ -98,6 +105,9 @@ private function mergeBothSideArrow(array $arrows): array
98105
return $merged;
99106
}
100107

108+
/**
109+
* @param PackageArrow[] $arrows arrows
110+
*/
101111
private function existsUpsidedown(array $arrows, PackageArrow $arrow): bool
102112
{
103113
foreach ($arrows as $a) {

0 commit comments

Comments
 (0)