Skip to content

Commit c984b61

Browse files
committed
The background color of the division map is changed for each division and displayed.
1 parent 249c1a7 commit c984b61

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Smeghead\PhpClassDiagram\DiagramElement\Division;
6+
7+
class DivisionColor {
8+
private static $gen;
9+
public static function nextColor(): string {
10+
if (empty(self::$gen)) {
11+
self::$gen = generateDivisionColorGenerator();
12+
}
13+
self::$gen->next();
14+
return self::$gen->current();
15+
}
16+
}
17+
18+
function generateDivisionColorGenerator(): \Generator
19+
{
20+
$COLORS = [
21+
'#ffffcc',
22+
'#ccffcc',
23+
'#ffcccc',
24+
'#ccccff',
25+
'#ccffff',
26+
'#ffccff',
27+
];
28+
while (true) {
29+
foreach ($COLORS as $c) {
30+
yield $c;
31+
}
32+
}
33+
}

src/DiagramElement/Entry.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Smeghead\PhpClassDiagram\DiagramElement;
66

7+
use Generator;
78
use Smeghead\PhpClassDiagram\Config\Options;
9+
use Smeghead\PhpClassDiagram\DiagramElement\Division\DivisionColor;
810
use Smeghead\PhpClassDiagram\Php\{
911
PhpClass,
1012
PhpAccessModifier,
@@ -74,7 +76,7 @@ public function dumpDivisions($level = 0): array
7476
$lines = [];
7577
$meta = $this->class->getClassType()->getMetaName();
7678
if ($meta === 'enum') {
77-
$lines[] = sprintf('%scard %s #ccffcc [', $indent, $this->class->getClassType()->getName());
79+
$lines[] = sprintf('%scard %s %s [', $indent, $this->class->getClassType()->getName(), DivisionColor::nextColor());
7880
$lines[] = sprintf('%s %s', $indent, $this->class->getClassType()->getName());
7981
$lines[] = sprintf('%s ====', $indent);
8082
$cases = $this->class->getEnumCases();

test/fixtures/enum/Sub/Status.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace Hoge\TestEnum\Sub;
3+
4+
enum Status {
5+
/** プレイヤーのターン */
6+
case Player;
7+
/** コンピュータのターン */
8+
case Computer;
9+
/** ゲーム終了 */
10+
case GameSet;
11+
}
12+
13+
enum MyExceptionCase {
14+
case InvalidMethod;
15+
case InvalidProperty;
16+
case Timeout;
17+
}
18+
19+
enum Size
20+
{
21+
case Small;
22+
case Medium;
23+
case Large;
24+
}

0 commit comments

Comments
 (0)