Skip to content

Commit 52bf4b6

Browse files
author
Bernhard Schmitt
committed
Remove provider generation and adjust test cases
1 parent f408e89 commit 52bf4b6

16 files changed

Lines changed: 36 additions & 435 deletions

Classes/Application/PseudoEnumProvider.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ final class PseudoEnumProvider extends AbstractDataSource implements ProtectedCo
2828
*/
2929
protected static $identifier = 'packagefactory-atomicfusion-presentationobjects-enumcases';
3030

31+
/**
32+
* @param NodeInterface|null $node
33+
* @param array<string|int,string> $arguments
34+
* @return array<string|int|float,array<string,string>>
35+
*/
3136
public function getData(NodeInterface $node = null, array $arguments = []): array
3237
{
3338
if (!isset($arguments['enumName'])) {
3439
throw new \InvalidArgumentException('Argument "enumName" must be provided.', 1625297174);
3540
}
36-
$values = $this->getValues($arguments['enumName']);
37-
$enumLabel = EnumLabel::fromEnumName($arguments['enumName']);
41+
/** @var class-string<mixed> $enumName */
42+
$enumName = $arguments['enumName'];
43+
$values = $this->getValues($enumName);
44+
$enumLabel = EnumLabel::fromEnumName($enumName);
3845
$options = [];
3946
foreach ($values as $value) {
4047
$options[$value]['label'] = $this->getLabel($enumLabel, (string)$value);
@@ -43,6 +50,11 @@ public function getData(NodeInterface $node = null, array $arguments = []): arra
4350
return $options;
4451
}
4552

53+
/**
54+
* @param NodeType $nodeType
55+
* @param array<mixed> $configuration
56+
* @param array<mixed> $options
57+
*/
4658
public function process(NodeType $nodeType, array &$configuration, array $options)
4759
{
4860
if (!isset($options['enumName'])) {
@@ -98,7 +110,7 @@ private function validateEnumName(string $enumName): void
98110
if (!class_exists($enumName)) {
99111
throw new \InvalidArgumentException('Given enum "' . $enumName . '" does not exist.', 1625297031);
100112
}
101-
if (!in_array(PseudoEnumInterface::class, class_implements($enumName))) {
113+
if (!in_array(PseudoEnumInterface::class, class_implements($enumName) ?: [])) {
102114
throw new \InvalidArgumentException('Given enum "' . $enumName . '" does not implement the required ' . PseudoEnumInterface::class, 1625297122);
103115
}
104116
}

Classes/Domain/Component/PropType/EnumPropType.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use Neos\Flow\Annotations as Flow;
9+
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Enum\PseudoEnumInterface;
910

1011
/**
1112
* @Flow\Proxy(false)
@@ -60,14 +61,15 @@ public function getStyleGuideValue(int $nestingLevel = 0): string
6061
return '= \'\'';
6162
}
6263

63-
$values = $this->className::getValues();
64+
$values = $this->className::cases();
65+
/** @var PseudoEnumInterface $value */
6466
$value = reset($values);
6567
switch ((string) $type) {
6668
case 'string':
67-
return '= \'' . $value . '\'';
69+
return '= \'' . $value->getValue() . '\'';
6870
case 'int':
6971
case 'float':
70-
return '= ' . $value;
72+
return '= ' . $value->getValue();
7173
default:
7274
}
7375

Classes/Domain/Enum/Enum.php

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
use Neos\Flow\Annotations as Flow;
9-
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\PluralName;
109

1110
/**
1211
* @Flow\Proxy(false)
@@ -134,72 +133,6 @@ public static function becauseItMustBeOneOfTheDefinedConstants(' . $this->type .
134133
';
135134
}
136135

137-
/**
138-
* @return string
139-
*/
140-
public function getProviderContent(): string
141-
{
142-
$arrayName = lcfirst(PluralName::forName($this->name->getName()));
143-
return '<?php declare(strict_types=1);
144-
namespace ' . $this->name->getProviderNamespace() . ';
145-
146-
/*
147-
* This file is part of the ' . $this->name->getPackageKey() . ' package.
148-
*/
149-
150-
use Neos\ContentRepository\Domain\Model\NodeInterface;
151-
use Neos\Flow\Annotations as Flow;
152-
use Neos\Flow\I18n\Translator;
153-
use Neos\Neos\Service\DataSource\AbstractDataSource;
154-
use Neos\Eel\ProtectedContextAwareInterface;
155-
use ' . $this->name->getFullyQualifiedName() . ';
156-
157-
class ' . $this->name->getProviderName() . ' extends AbstractDataSource implements ProtectedContextAwareInterface
158-
{
159-
/**
160-
* @Flow\Inject
161-
* @var Translator
162-
*/
163-
protected $translator;
164-
165-
/**
166-
* @var string
167-
*/
168-
protected static $identifier = \'' . $this->name->getDataSourceIdentifier() . '\';
169-
170-
public function getData(NodeInterface $node = null, array $arguments = []): array
171-
{
172-
$' . $arrayName . ' = [];
173-
foreach (' . $this->name->getName() . '::getValues() as $value) {
174-
$' . $arrayName . '[$value][\'label\'] = $this->translator->translateById(
175-
\'' . lcfirst($this->name->getName()) . '.\' . $value,
176-
[],
177-
null,
178-
null,
179-
\'' . $this->name->getComponentName()->getName() . '\',
180-
\'' . $this->name->getPackageKey() . '\'
181-
) ?: $value;
182-
}
183-
184-
return $' . $arrayName . ';
185-
}
186-
187-
/**
188-
* @return array|' . $this->type . '[]
189-
*/
190-
public function getValues(): array
191-
{
192-
return ' . $this->name->getName() . '::getValues();
193-
}
194-
195-
public function allowsCallOfMethod($methodName): bool
196-
{
197-
return true;
198-
}
199-
}
200-
';
201-
}
202-
203136
/**
204137
* @return string
205138
*/

Classes/Domain/Enum/EnumGenerator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,5 @@ public function generateEnum(
5252

5353
$this->fileWriter->writeFile($enumName->getClassPath($packagePath, $colocate), $enum->getClassContent());
5454
$this->fileWriter->writeFile($enumName->getExceptionPath($packagePath, $colocate), $enum->getExceptionContent($this->now));
55-
$this->fileWriter->writeFile($enumName->getProviderPath($packagePath), $enum->getProviderContent());
5655
}
5756
}

Classes/Domain/Enum/EnumLabel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ private function __construct(
3131
public static function fromEnumName(string $enumName): self
3232
{
3333
list($packageKey, $componentName) = explode('/Presentation/', $enumName);
34-
$pivot = \mb_strrpos($componentName, '/');
35-
$componentNamespace = \mb_substr($packageKey, 0 , $pivot);
34+
$pivot = \mb_strrpos($componentName, '/') ?: null;
35+
$componentNamespace = \mb_substr($packageKey, 0, $pivot);
3636
$enumShort = lcfirst(\mb_substr($packageKey, $pivot+1));
3737

3838
return new self(

Classes/Domain/Enum/EnumName.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Neos\Flow\Annotations as Flow;
99
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\ComponentName;
10-
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\PluralName;
1110
use PackageFactory\AtomicFusion\PresentationObjects\Domain\FusionNamespace;
1211
use PackageFactory\AtomicFusion\PresentationObjects\Domain\PackageKey;
1312

@@ -53,11 +52,6 @@ public function getPhpNamespace(): string
5352
return $this->componentName->getPhpNamespace();
5453
}
5554

56-
public function getFullyQualifiedName(): string
57-
{
58-
return $this->getPhpNamespace() . '\\' . $this->name;
59-
}
60-
6155
public function getExceptionName(): string
6256
{
6357
return $this->name . 'IsInvalid';
@@ -82,45 +76,4 @@ public function getExceptionPath(string $packagePath, bool $colocate): string
8276
{
8377
return $this->getPhpFilePath($packagePath, $colocate) . '/' . $this->getExceptionName() . '.php';
8478
}
85-
86-
public function getProviderBasePath(string $packagePath): string
87-
{
88-
return $packagePath . '/Classes/Application';
89-
}
90-
91-
public function getProviderPath(string $packagePath): string
92-
{
93-
return $this->getProviderBasePath($packagePath) . '/' . $this->name . 'Provider.php';
94-
}
95-
96-
public function getProviderNamespace(): string
97-
{
98-
return $this->getPackageKey()->toPhpNamespace() . '\\Application';
99-
}
100-
101-
public function getDataSourceIdentifier(): string
102-
{
103-
return strtolower(str_replace('.', '-', (string)$this->getPackageKey()) . '-' . implode('-', $this->splitName()));
104-
}
105-
106-
/**
107-
* @return string[]
108-
*/
109-
private function splitName(): array
110-
{
111-
$nameParts = [];
112-
$parts = preg_split("/([A-Z])/", PluralName::forName($this->name), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
113-
114-
if (is_array($parts)) {
115-
foreach ($parts as $i => $part) {
116-
if ($i % 2 === 0) {
117-
$nameParts[$i / 2] = $part;
118-
} else {
119-
$nameParts[($i - 1) / 2] .= $part;
120-
}
121-
}
122-
}
123-
124-
return $nameParts;
125-
}
12679
}

Tests/Unit/Domain/Component/ComponentNameTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package
66
*/
77

8-
use Neos\Eel\Package;
98
use Neos\Flow\Tests\UnitTestCase;
109
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\ComponentName;
1110
use PackageFactory\AtomicFusion\PresentationObjects\Domain\FusionNamespace;
@@ -91,7 +90,7 @@ public function classNameProvider(): array
9190
],
9291
[
9392
'Vendor\Site\Presentation\Component\MyNewComponent\MyStringPseudoEnum',
94-
new ComponentName($packageKey, FusionNamespace::fromString('Component'), 'MyStringEnum')
93+
new ComponentName($packageKey, FusionNamespace::fromString('Component'), 'MyStringPseudoEnum')
9594
],
9695
[
9796
'Vendor\Site\Presentation\Component\AnotherComponent\AnotherComponents',

Tests/Unit/Domain/Component/PropType/EnumPropTypeTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public function simpleNameProvider(): array
3434
return [
3535
[
3636
new EnumPropType(MyStringPseudoEnum::class, false),
37-
'MyStringEnum'
37+
'MyStringPseudoEnum'
3838
],
3939
[
4040
new EnumPropType(MyStringPseudoEnum::class, true),
41-
'MyStringEnum'
41+
'MyStringPseudoEnum'
4242
]
4343
];
4444
}
@@ -62,12 +62,12 @@ public function useStatementProvider(): array
6262
return [
6363
[
6464
new EnumPropType(MyStringPseudoEnum::class, false),
65-
'use Vendor\Site\Presentation\Component\MyNewComponent\MyStringEnum;
65+
'use Vendor\Site\Presentation\Component\MyNewComponent\MyStringPseudoEnum;
6666
'
6767
],
6868
[
6969
new EnumPropType(MyStringPseudoEnum::class, true),
70-
'use Vendor\Site\Presentation\Component\MyNewComponent\MyStringEnum;
70+
'use Vendor\Site\Presentation\Component\MyNewComponent\MyStringPseudoEnum;
7171
'
7272
]
7373
];
@@ -92,11 +92,11 @@ public function typeProvider(): array
9292
return [
9393
[
9494
new EnumPropType(MyStringPseudoEnum::class, false),
95-
'MyStringEnum'
95+
'MyStringPseudoEnum'
9696
],
9797
[
9898
new EnumPropType(MyStringPseudoEnum::class, true),
99-
'?MyStringEnum'
99+
'?MyStringPseudoEnum'
100100
]
101101
];
102102
}

Tests/Unit/Domain/Component/PropType/PropTypeFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ public function validInputStringProvider(): array
123123
],
124124
[
125125
$componentName,
126-
'MyStringEnum',
126+
'MyStringPseudoEnum',
127127
new EnumPropType('Vendor\\Site\\Presentation\\Component\\MyNewComponent\\MyStringPseudoEnum', false)
128128
],
129129
[
130130
$componentName,
131-
'?MyStringEnum',
131+
'?MyStringPseudoEnum',
132132
new EnumPropType('Vendor\\Site\\Presentation\\Component\\MyNewComponent\\MyStringPseudoEnum', true)
133133
],
134134
[

Tests/Unit/Domain/Enum/EnumGeneratorTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public function exampleProvider(): array
5757
'vfs://DistributionPackages/Vendor.Site/',
5858
[
5959
'vfs://DistributionPackages/Vendor.Site/Classes/Presentation/Component/Headline/HeadlineType.php',
60-
'vfs://DistributionPackages/Vendor.Site/Classes/Presentation/Component/Headline/HeadlineTypeIsInvalid.php',
61-
'vfs://DistributionPackages/Vendor.Site/Classes/Application/HeadlineTypeProvider.php',
60+
'vfs://DistributionPackages/Vendor.Site/Classes/Presentation/Component/Headline/HeadlineTypeIsInvalid.php'
6261
],
6362
false
6463
],
@@ -70,8 +69,7 @@ public function exampleProvider(): array
7069
'vfs://DistributionPackages/Vendor.Default/',
7170
[
7271
'vfs://DistributionPackages/Vendor.Default/Classes/Presentation/Component/Crossing/TrafficLight.php',
73-
'vfs://DistributionPackages/Vendor.Default/Classes/Presentation/Component/Crossing/TrafficLightIsInvalid.php',
74-
'vfs://DistributionPackages/Vendor.Default/Classes/Application/TrafficLightProvider.php',
72+
'vfs://DistributionPackages/Vendor.Default/Classes/Presentation/Component/Crossing/TrafficLightIsInvalid.php'
7573
],
7674
false
7775
],
@@ -83,8 +81,7 @@ public function exampleProvider(): array
8381
'vfs://DistributionPackages/Vendor.Default/',
8482
[
8583
'vfs://DistributionPackages/Vendor.Default/Classes/Presentation/Custom/Type/Crossing/Duration.php',
86-
'vfs://DistributionPackages/Vendor.Default/Classes/Presentation/Custom/Type/Crossing/DurationIsInvalid.php',
87-
'vfs://DistributionPackages/Vendor.Default/Classes/Application/DurationProvider.php',
84+
'vfs://DistributionPackages/Vendor.Default/Classes/Presentation/Custom/Type/Crossing/DurationIsInvalid.php'
8885
],
8986
false
9087
],
@@ -96,8 +93,7 @@ public function exampleProvider(): array
9693
'vfs://DistributionPackages/Vendor.Site/',
9794
[
9895
'vfs://DistributionPackages/Vendor.Site/Resources/Private/Fusion/Presentation/Component/Headline/HeadlineType.php',
99-
'vfs://DistributionPackages/Vendor.Site/Resources/Private/Fusion/Presentation/Component/Headline/HeadlineTypeIsInvalid.php',
100-
'vfs://DistributionPackages/Vendor.Site/Classes/Application/HeadlineTypeProvider.php',
96+
'vfs://DistributionPackages/Vendor.Site/Resources/Private/Fusion/Presentation/Component/Headline/HeadlineTypeIsInvalid.php'
10197
],
10298
true
10399
],

0 commit comments

Comments
 (0)