Skip to content

Commit 27046ff

Browse files
author
Bernhard Schmitt
committed
Use component variant traits in kickstarter
1 parent 51e22de commit 27046ff

10 files changed

Lines changed: 55 additions & 54 deletions

Classes/Domain/Enum/Enum.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,13 @@ public function getClassContent(): string
3737
namespace ' . $this->name->getPhpNamespace() . ';
3838
3939
use Neos\Eel\ProtectedContextAwareInterface;
40+
use ' . $this->type->getFullyQualifiedVariantName() . ';
4041
4142
enum ' . $this->name->name . ': ' . $this->type->value . ' implements ProtectedContextAwareInterface
4243
{
43-
' . $this->renderCases() . '
44-
45-
public function equals(' . $this->type->value . ' $other): bool
46-
{
47-
return $this === self::from($other);
48-
}
44+
use ' . $this->type->getVariantName() . ';
4945
50-
public function allowsCallOfMethod($methodName): bool
51-
{
52-
return true;
53-
}
46+
' . $this->renderCases() . '
5447
}
5548
';
5649
}

Classes/Domain/Enum/EnumType.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,20 @@ public function processValueArray(array $valueArray): array
4545

4646
return $processedValueArray;
4747
}
48+
49+
public function getFullyQualifiedVariantName(): string
50+
{
51+
return match ($this) {
52+
self::TYPE_STRING => 'PackageFactory\AtomicFusion\PresentationObjects\Fusion\StringComponentVariant',
53+
self::TYPE_INT => 'PackageFactory\AtomicFusion\PresentationObjects\Fusion\IntComponentVariant'
54+
};
55+
}
56+
57+
public function getVariantName(): string
58+
{
59+
return match ($this) {
60+
self::TYPE_STRING => 'StringComponentVariant',
61+
self::TYPE_INT => 'IntComponentVariant'
62+
};
63+
}
4864
}

Tests/Unit/Domain/Enum/EnumTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,15 @@ public function testGetClassContent(): void
5959
namespace Vendor\Site\Presentation\Component\MyComponent;
6060
6161
use Neos\Eel\ProtectedContextAwareInterface;
62+
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\StringComponentVariant;
6263
6364
enum MyComponentType: string implements ProtectedContextAwareInterface
6465
{
66+
use StringComponentVariant;
67+
6568
case TYPE_PRIMARY = \'primary\';
6669
case TYPE_SECONDARY = \'secondary\';
6770
case TYPE_YET_ANOTHER = \'yetAnother\';
68-
69-
public function equals(string $other): bool
70-
{
71-
return $this === self::from($other);
72-
}
73-
74-
public function allowsCallOfMethod($methodName): bool
75-
{
76-
return true;
77-
}
7871
}
7972
',
8073
$this->subject->getClassContent()

Tests/Unit/Domain/Enum/__snapshots__/EnumGeneratorTest__generatesEnums with data set coLocatedHeadlineType__1.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,13 @@ declare(strict_types=1);
99
namespace Vendor\Site\Presentation\Component\Headline;
1010

1111
use Neos\Eel\ProtectedContextAwareInterface;
12+
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\StringComponentVariant;
1213

1314
enum HeadlineType: string implements ProtectedContextAwareInterface
1415
{
16+
use StringComponentVariant;
17+
1518
case TYPE_H1 = 'h1';
1619
case TYPE_H2 = 'h2';
1720
case TYPE_DIV = 'div';
18-
19-
public function equals(string $other): bool
20-
{
21-
return $this === self::from($other);
22-
}
23-
24-
public function allowsCallOfMethod($methodName): bool
25-
{
26-
return true;
27-
}
2821
}

Tests/Unit/Domain/Enum/__snapshots__/EnumGeneratorTest__generatesEnums with data set headlinetype__1.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,13 @@ declare(strict_types=1);
99
namespace Vendor\Site\Presentation\Component\Headline;
1010

1111
use Neos\Eel\ProtectedContextAwareInterface;
12+
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\StringComponentVariant;
1213

1314
enum HeadlineType: string implements ProtectedContextAwareInterface
1415
{
16+
use StringComponentVariant;
17+
1518
case TYPE_H1 = 'h1';
1619
case TYPE_H2 = 'h2';
1720
case TYPE_DIV = 'div';
18-
19-
public function equals(string $other): bool
20-
{
21-
return $this === self::from($other);
22-
}
23-
24-
public function allowsCallOfMethod($methodName): bool
25-
{
26-
return true;
27-
}
2821
}

Tests/Unit/Domain/Enum/__snapshots__/EnumGeneratorTest__generatesEnums with data set trafficlight__1.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,13 @@ declare(strict_types=1);
99
namespace Vendor\Default\Presentation\Component\Crossing;
1010

1111
use Neos\Eel\ProtectedContextAwareInterface;
12+
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\IntComponentVariant;
1213

1314
enum TrafficLight: int implements ProtectedContextAwareInterface
1415
{
16+
use IntComponentVariant;
17+
1518
case LIGHT_RED = 1;
1619
case LIGHT_YELLOW = 2;
1720
case LIGHT_GREEN = 3;
18-
19-
public function equals(int $other): bool
20-
{
21-
return $this === self::from($other);
22-
}
23-
24-
public function allowsCallOfMethod($methodName): bool
25-
{
26-
return true;
27-
}
2821
}

Tests/Unit/Fixtures/Site/Presentation/Component/Headline/HeadlineLook.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88

99
namespace Vendor\Site\Presentation\Component\Headline;
1010

11+
use Neos\Eel\ProtectedContextAwareInterface;
12+
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\StringComponentVariant;
13+
1114
/**
1215
* HeadlineLook enum for test purposes
1316
*/
14-
enum HeadlineLook: string
17+
enum HeadlineLook: string implements ProtectedContextAwareInterface
1518
{
19+
use StringComponentVariant;
20+
1621
case LOOK_LARGE = 'large';
1722
}

Tests/Unit/Fixtures/Site/Presentation/Component/Headline/HeadlineType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88

99
namespace Vendor\Site\Presentation\Component\Headline;
1010

11+
use Neos\Eel\ProtectedContextAwareInterface;
12+
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\StringComponentVariant;
13+
1114
/**
1215
* HeadlineType enum for test purposes
1316
*/
14-
enum HeadlineType: string
17+
enum HeadlineType: string implements ProtectedContextAwareInterface
1518
{
19+
use StringComponentVariant;
20+
1621
case TYPE_H1 = 'h1';
1722
}

Tests/Unit/Fixtures/Site/Presentation/Component/MyNewComponent/MyIntEnum.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
namespace Vendor\Site\Presentation\Component\MyNewComponent;
1010

11+
use Neos\Eel\ProtectedContextAwareInterface;
12+
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\IntComponentVariant;
13+
1114
/**
1215
* Dummy int enum for test purposes
1316
*/
14-
enum MyIntEnum: int
17+
enum MyIntEnum: int implements ProtectedContextAwareInterface
1518
{
19+
use IntComponentVariant;
20+
1621
case VALUE_ANSWER = 42;
1722
case VALUE_OTHER = 8472;
1823
}

Tests/Unit/Fixtures/Site/Presentation/Component/MyNewComponent/MyStringEnum.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
namespace Vendor\Site\Presentation\Component\MyNewComponent;
1010

11+
use Neos\Eel\ProtectedContextAwareInterface;
12+
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\StringComponentVariant;
13+
1114
/**
1215
* Dummy string enum for test purposes
1316
*/
14-
enum MyStringEnum: string
17+
enum MyStringEnum: string implements ProtectedContextAwareInterface
1518
{
19+
use StringComponentVariant;
20+
1621
case VALUE_MY_VALUE = 'myValue';
1722
case VALUE_MY_OTHER_VALUE = 'myOtherValue';
1823
}

0 commit comments

Comments
 (0)