|
5 | 5 |
|
6 | 6 | use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeContainer;
|
7 | 7 | use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem;
|
8 |
| -use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeSingle; |
9 | 8 | use GoetasWebservices\XML\XSDReader\Schema\Attribute\Group;
|
10 | 9 | use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
|
11 |
| -use Psl\Option\Option; |
12 | 10 | use Soap\Engine\Metadata\Collection\PropertyCollection;
|
13 | 11 | use Soap\Engine\Metadata\Model\Property;
|
14 | 12 | use Soap\Engine\Metadata\Model\TypeMeta;
|
15 | 13 | use Soap\Engine\Metadata\Model\XsdType as EngineType;
|
16 | 14 | use Soap\WsdlReader\Metadata\Converter\Types\Configurator;
|
17 |
| -use Soap\WsdlReader\Metadata\Converter\Types\Detector\AttributeDeclaringParentTypeDetector; |
| 15 | +use Soap\WsdlReader\Metadata\Converter\Types\Detector\AttributeTypeNameDetector; |
18 | 16 | use Soap\WsdlReader\Metadata\Converter\Types\TypesConverterContext;
|
19 | 17 | use function Psl\Fun\pipe;
|
20 |
| -use function Psl\Option\from_nullable; |
21 | 18 | use function Psl\Result\wrap;
|
22 | 19 | use function Psl\Type\instance_of;
|
23 | 20 | use function Psl\Vec\flat_map;
|
@@ -91,35 +88,15 @@ private function parseAttribute(AttributeItem $attribute, TypesConverterContext
|
91 | 88 | return $this->parseAttributes($attribute, $context);
|
92 | 89 | }
|
93 | 90 |
|
94 |
| - // Detecting the type-name for an attribute is complex. |
95 |
| - // We first try to use the type name, |
96 |
| - // Next up is the base type of the restriction if there aren't any restriction checks configured. |
97 |
| - // Finally there is a fallback to the attribute name |
98 |
| - $attributeType = $attribute instanceof AttributeSingle ? $attribute->getType() : null; |
99 |
| - $attributeRestriction = $attributeType?->getRestriction(); |
100 |
| - $attributeTypeName = $attributeType?->getName(); |
101 |
| - $attributeRestrictionName = ($attributeRestriction && !$attributeRestriction->getChecks()) ? $attributeRestriction->getBase()?->getName() : null; |
102 |
| - |
103 |
| - $typeName = $attributeTypeName ?: ($attributeRestrictionName ?: $attribute->getName()); |
104 |
| - $engineType = EngineType::guess($typeName); |
105 |
| - |
106 |
| - // If a name cannot be determined from the type, we fallback to the attribute name: |
107 |
| - // Prefix the attribute name with the parent element name resulting in a more unique type-name. |
108 |
| - if (!$attributeTypeName && !$attributeRestrictionName) { |
109 |
| - $engineType = AttributeDeclaringParentTypeDetector::detectWithParentContext($attribute, $context->parent()) |
110 |
| - ->andThen(static fn (Type $parent): Option => from_nullable($parent->getName())) |
111 |
| - ->map(static fn (string $parentName): EngineType => $engineType->copy($parentName . ucfirst($typeName))) |
112 |
| - ->unwrapOr($engineType); |
113 |
| - } |
114 |
| - |
| 91 | + $typeName = (new AttributeTypeNameDetector())($attribute, $context->parent()->unwrap()); |
115 | 92 | $configure = pipe(
|
116 | 93 | static fn (EngineType $engineType): EngineType => (new Configurator\AttributeConfigurator())($engineType, $attribute, $context),
|
117 | 94 | );
|
118 | 95 |
|
119 | 96 | return new PropertyCollection(
|
120 | 97 | new Property(
|
121 | 98 | $attribute->getName(),
|
122 |
| - $configure($engineType) |
| 99 | + $configure(EngineType::guess($typeName)) |
123 | 100 | )
|
124 | 101 | );
|
125 | 102 | }
|
|
0 commit comments