Skip to content

Commit e599583

Browse files
committed
Some adjustments to test
1 parent aa791f2 commit e599583

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

src/Frame.php

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ public function getRootNode(): self
3636
return $node;
3737
}
3838

39-
public function getName(): string
39+
public function getName(bool $emptyParent = false): string
4040
{
4141
if ($this->parent && str_contains($this->name, '$parent')) {
4242
$parent = $this;
4343
$parentName = '';
44-
while ($parent = $parent->getParent()) {
45-
$parentName = $parent->getName();
46-
if ($parentName) {
47-
break;
44+
if (!$emptyParent) {
45+
while ($parent = $parent->getParent()) {
46+
$parentName = $parent->getName();
47+
if ($parentName) {
48+
break;
49+
}
4850
}
4951
}
5052
return str_replace('$parent', $parentName, $this->name);
@@ -56,28 +58,15 @@ public function getName(): string
5658
public function getClassName(): ?string
5759
{
5860
$prefix = $this->parent?->getClassName() ?? '';
59-
$name = $this->getName() ?: $this->getParentKey();
60-
if (!$name) {
61+
$name = $this->getName(true) ?: $this->getParentKey();
62+
if (!$name || ($this->parent && !$prefix)) {
6163
return null;
6264
}
63-
64-
$segments = array_filter(explode('.', str_replace('_', '.', $prefix . '.' . $name)));
65-
66-
$deduped = [];
67-
foreach ($segments as $segment) {
68-
foreach ($deduped as $existing) {
69-
if (str_starts_with($segment, $existing)) {
70-
$segment = substr($segment, strlen($existing));
71-
$segment = ltrim($segment, '._');
72-
}
73-
}
74-
$deduped[] = $segment;
75-
}
76-
65+
7766
return str_replace(
7867
['$', ' ', '-', '.'],
7968
['', '_', '_', '_'],
80-
implode('.', array_filter($deduped))
69+
$prefix === '' ? $name : $prefix . '_' . $name,
8170
);
8271
}
8372

src/Registry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
class Registry
1212
{
1313
/**
14-
* @var T[]
14+
* @var array<string, (T&Frame)>
1515
*/
1616
private array $items = [];
1717

1818
/**
19-
* @param T $template
19+
* @param T&Frame $template
2020
*/
2121
public function register(?string $name, Frame $template): void
2222
{
@@ -27,15 +27,15 @@ public function register(?string $name, Frame $template): void
2727
}
2828

2929
/**
30-
* @return T|null
30+
* @return (T&Frame)|null
3131
*/
3232
public function get(string $name): ?Frame
3333
{
3434
return $this->items[$name] ?? null;
3535
}
3636

3737
/**
38-
* @return T[]
38+
* @return array<string, (T&Frame)>
3939
*/
4040
public function all(): array
4141
{

src/XmlFileParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function parseNode(SimpleXMLElement $node, Registry $fileRegistry, ?Fram
103103
$this->frameRegistry->register($frame->getClassName(), $frame);
104104
}
105105
if (!empty($name)) {
106-
$fileRegistry->register($name, $frame);
106+
$fileRegistry->register($frame->getClassName(), $frame);
107107
}
108108
$parent?->addChild($frame);
109109

0 commit comments

Comments
 (0)