Skip to content

Commit 5162d1f

Browse files
committed
TASK: Simplyfy InterfaceName and ObjectNameSpecification
1 parent 2f7555b commit 5162d1f

9 files changed

+20
-16
lines changed

Classes/Command/NodeObjectsCommandController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function buildCommand(string $packageKey, string $crId = 'default'): void
101101
$interfaceSpecification->interfaceFilename,
102102
$interfaceSpecification->toPhpString()
103103
);
104-
$this->outputLine(' - ' . $interfaceSpecification->interfaceName->nodeTypeName . ' -> <info>' . $interfaceSpecification->interfaceFilename . '</info>');
104+
$this->outputLine(' - ' . $interfaceSpecification->interfaceName->nodeTypeName . ' -> <info>' . $interfaceSpecification->interfaceName->getFullyQualifiedClassName() . '</info>');
105105
}
106106

107107
// loop 2 build objects for all non abstract nodetypes in package
@@ -121,7 +121,7 @@ public function buildCommand(string $packageKey, string $crId = 'default'): void
121121
$objectSpecification->classFilename,
122122
$objectSpecification->toPhpString()
123123
);
124-
$this->outputLine(' - ' . $objectSpecification->objectName->nodeTypeName . ' -> <info>' . $objectSpecification->objectName->fullyQualifiedClassName . '</info>');
124+
$this->outputLine(' - ' . $objectSpecification->objectName->nodeTypeName . ' -> <info>' . $objectSpecification->objectName->getFullyQualifiedClassName() . '</info>');
125125
}
126126
}
127127

Classes/Domain/NodeInterfaceNameSpecification.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
public function __construct(
1515
public string $nodeTypeName,
1616
public string $phpNamespace,
17-
public string $interfaceName,
18-
public string $fullyQualifiedInterfaceName,
17+
public string $interfaceName
1918
) {
2019
}
2120

21+
public function getFullyQualifiedClassName(): string
22+
{
23+
return $this->phpNamespace . '\\' . $this->interfaceName;
24+
}
25+
2226
public static function createFromNodeTypeName(
2327
NodeTypeName $nodeTypeName
2428
): self {
@@ -34,8 +38,7 @@ public static function createFromNodeTypeName(
3438
return new self(
3539
$nodeTypeName->value,
3640
$phpNamespace,
37-
$interfaceName,
38-
$phpNamespace . '\\' . $interfaceName
41+
$interfaceName
3942
);
4043
}
4144

Classes/Domain/NodeInterfaceNameSpecificationCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function createFromNodeType(NodeType $nodeType, bool $checkForExis
3737
];
3838
foreach ($nodeType->getDeclaredSuperTypes() as $superType) {
3939
$interface = NodeInterfaceNameSpecification::createFromNodeType($superType);
40-
if ($checkForExistence && interface_exists($interface->fullyQualifiedInterfaceName)) {
40+
if ($checkForExistence && interface_exists($interface->getFullyQualifiedClassName())) {
4141
$interfaces[] = $interface;
4242
} else {
4343
$interfaces[] = $interface;
@@ -51,7 +51,7 @@ public function asImplementsStatement(): string
5151
if (empty($this->items)) {
5252
return '';
5353
} else {
54-
return 'implements ' . implode(', ', array_map(fn(NodeInterfaceNameSpecification $item)=> $item->fullyQualifiedInterfaceName, $this->items));
54+
return 'implements ' . implode(', ', array_map(fn(NodeInterfaceNameSpecification $item)=> $item->getFullyQualifiedClassName(), $this->items));
5555
}
5656
}
5757
}

Classes/Domain/NodeObjectNameSpecification.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ public function __construct(
1515
public string $nodeTypeName,
1616
public string $phpNamespace,
1717
public string $className,
18-
public string $fullyQualifiedClassName,
1918
) {
2019
}
2120

21+
public function getFullyQualifiedClassName(): string
22+
{
23+
return $this->phpNamespace . '\\' . $this->className;
24+
}
25+
2226
public static function createFromNodeTypeName(
2327
NodeTypeName $nodeTypeName
2428
): self {
@@ -35,7 +39,6 @@ public static function createFromNodeTypeName(
3539
$nodeTypeName->value,
3640
$phpNamespace,
3741
$className,
38-
$phpNamespace . '\\' . $className
3942
);
4043
}
4144

Classes/Domain/NodeObjectSpecification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function toPhpString(): string
8080
/**
8181
* AUTOGENERATED CODE ... DO NOT MODIFY !!!
8282
*
83-
* run `./flow nodetypeobjects:build` to regenerate this
83+
* run `./flow nodeobjects:build` to regenerate this
8484
*/
8585
#[Flow\Proxy(false)]
8686
final readonly class {$this->objectName->className} {$interfaceDeclaration}

Classes/NodeObjectFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class NodeObjectFactory
1212
public static function forNode(Node $node): NodeObjectInterface
1313
{
1414
$nodeObjectName = NodeObjectNameSpecification::createFromNodeTypeName($node->nodeTypeName);
15-
$nodeObjectClass = $nodeObjectName->fullyQualifiedClassName;
15+
$nodeObjectClass = $nodeObjectName->getFullyQualifiedClassName();
1616
if (class_exists($nodeObjectClass) && is_a($nodeObjectClass, NodeObjectInterface::class, true)) {
1717
return $nodeObjectClass::fromNode($node);
1818
} else {
@@ -23,7 +23,7 @@ public static function forNode(Node $node): NodeObjectInterface
2323
public static function tryForNode(Node $node): ?NodeObjectInterface
2424
{
2525
$nodeObjectName = NodeObjectNameSpecification::createFromNodeTypeName($node->nodeTypeName);
26-
$nodeObjectClass = $nodeObjectName->fullyQualifiedClassName;
26+
$nodeObjectClass = $nodeObjectName->getFullyQualifiedClassName();
2727
if (class_exists($nodeObjectClass) && is_a($nodeObjectClass, NodeObjectInterface::class, true)) {
2828
return $nodeObjectClass::fromNode($node);
2929
} else {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Autogenerate php classes and interfaces for NodeTypes with type safe property ac
66

77
- NodeObjects are created for each non abstract NodeType in the namespace of the given package.
88
- NodeInterfaces are created for each NodeType in the namespace of the given package.
9-
- NodeObjects and NodeInterfaces are stored in the `NodeTypes` folder using all parts of the NodeTypeName as folders
9+
- NodeObjects and NodeInterfaces are stored in the `NodeTypes` folder using all parts of the NodeTypeName as folders
1010
- The namespace of each NodeTypeObject/NodeInterface is derived from the package-key with added ``NodeTypes`
1111
- The className of a NodeObject is defined by the last part of the NodeTypeName with postfix `NodeObject`
1212
- The interfaceName of a NodeInterface is defined by the last part of the NodeTypeName with postfix `NodeInterface`

Tests/Unit/NodeInterfaceNameSpecificationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function detectionOfNamesFromNodeType(): void
2929
'Vendor.Example:Foo.Bar',
3030
'Vendor\Example\NodeTypes\Foo\Bar',
3131
'BarNodeInterface',
32-
'Vendor\Example\NodeTypes\Foo\Bar\BarNodeInterface',
3332
),
3433
$specification
3534
);

Tests/Unit/NodeObjectNameSpecificationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public function detectionOfNamesFromNodeType(): void
2828
'Vendor.Example:Foo.Bar',
2929
'Vendor\Example\NodeTypes\Foo\Bar',
3030
'BarNodeObject',
31-
'Vendor\Example\NodeTypes\Foo\Bar\BarNodeObject',
3231
),
3332
$specification
3433
);

0 commit comments

Comments
 (0)