Skip to content

Commit e819d63

Browse files
committed
feat: add types to properties
1 parent 6d168dc commit e819d63

File tree

5 files changed

+19
-41
lines changed

5 files changed

+19
-41
lines changed

codemap.txt

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/CodemapGenerator.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,20 @@ public function enterNode(Node $node)
138138
? 'public'
139139
: ($node->isProtected() ? 'protected' : 'private');
140140

141+
$propertyType = $node->type;
142+
if ($propertyType instanceof Node\Identifier) {
143+
$propertyType = $propertyType->name;
144+
} elseif ($propertyType instanceof Node\Name) {
145+
$propertyType = $propertyType->toString();
146+
} else {
147+
$propertyType = 'mixed';
148+
}
149+
141150
foreach ($node->props as $prop) {
142151
$this->classes[$this->currentClassName]['properties'][] = [
143152
'visibility' => $visibility,
144153
'name' => $prop->name->toString(),
154+
'type' => $propertyType,
145155
];
146156
}
147157
}
@@ -171,7 +181,8 @@ public function enterNode(Node $node)
171181
foreach ($classData['properties'] as $propData) {
172182
$properties[] = new CodemapPropertyDto(
173183
$propData['visibility'],
174-
$propData['name']
184+
$propData['name'],
185+
$propData['type']
175186
);
176187
}
177188

src/Dto/CodemapPropertyDto.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ final class CodemapPropertyDto
88
{
99
public function __construct(
1010
public string $visibility,
11-
public string $name
11+
public string $name,
12+
public string $type
1213
) {}
1314
}

src/TextCodemapFormatter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ public function format(array $results): string
3939
foreach ($classDto->properties as $property) {
4040
if ($property->visibility === 'public') {
4141
$output .= sprintf(
42-
" %s property \$%s\n",
42+
" %s property %s \$%s\n",
4343
$property->visibility,
44+
$property->type,
4445
$property->name
4546
);
4647
}

tests/Unit/TextCodemapFormatterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
new Kauffinger\Codemap\Dto\CodemapMethodDto('protected', 'test', 'mixed'),
1616
],
1717
[
18-
new Kauffinger\Codemap\Dto\CodemapPropertyDto('public', 'foo'),
19-
new Kauffinger\Codemap\Dto\CodemapPropertyDto('private', 'bar'),
18+
new Kauffinger\Codemap\Dto\CodemapPropertyDto('public', 'foo', 'string'),
19+
new Kauffinger\Codemap\Dto\CodemapPropertyDto('private', 'bar', 'int'),
2020
]
2121
),
2222
]),
@@ -28,6 +28,6 @@
2828
->toContain('Class: Acme\\Example')
2929
->toContain('public function run(): void')
3030
->toContain('protected function test(): mixed')
31-
->toContain('public property $foo')
31+
->toContain('public property string $foo')
3232
->not->toContain('private property $bar'); // Should not list private props
3333
});

0 commit comments

Comments
 (0)