Skip to content

Commit df731b2

Browse files
authored
Merge pull request #150 from goetas-webservices/valid-types
Valid types
2 parents b76f9ae + 19637aa commit df731b2

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/DependencyInjection/Xsd2PhpExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected static function sanitizePhp($ns)
6464
return strtr($ns, '/', '\\');
6565
}
6666

67-
public function getAlias()
67+
public function getAlias(): string
6868
{
6969
return 'xsd2php';
7070
}

src/Jms/YamlConverter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ protected function getElementNamespace(Schema $schema, ElementItem $element)
480480
* @param Element $element
481481
* @param bool $arrayize
482482
*
483-
* @return \GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPProperty
483+
* @return array
484484
*/
485485
protected function &visitElement(&$class, Schema $schema, ElementItem $element, $arrayize = true)
486486
{

src/Jms/YamlValidatorConverter.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,19 @@ private function loadValidatorType(array &$property, Type $type, $arrayized = fa
7777
$rules = [];
7878

7979
if (($restrictions = $type->getRestriction()) && $checks = $restrictions->getChecks()) {
80+
$propertyType = isset($property['type']) ? $property['type'] : null;
8081
foreach ($checks as $key => $check) {
8182
switch ($key) {
8283
case 'enumeration':
8384
$rules[] = [
8485
'Choice' => [
85-
'choices' => array_map(function ($enum) {
86+
'choices' => array_map(function ($enum) use ($propertyType) {
87+
if ($propertyType === 'int') {
88+
return (int)$enum['value'];
89+
}
90+
if ($propertyType === 'float') {
91+
return (float)$enum['value'];
92+
}
8693
return $enum['value'];
8794
}, $check),
8895
],
@@ -250,7 +257,7 @@ private function loadValidatorElement(array &$property, ElementItem $element)
250257
* from a schema attribute including required rule.
251258
*
252259
* @param AttributeItem $element
253-
* @param bool $arrayize
260+
* @param bool $arrayize
254261
*/
255262
private function loadValidatorAttribute(array &$property, AttributeItem $attribute)
256263
{
@@ -273,8 +280,8 @@ private function loadValidatorAttribute(array &$property, AttributeItem $attribu
273280
* Override necessary to improve method to load validations from schema type.
274281
*
275282
* @param PHPClass $class
276-
* @param array $data
277-
* @param string $name
283+
* @param array $data
284+
* @param string $name
278285
*/
279286
protected function visitSimpleType(&$class, &$data, SimpleType $type, $name)
280287
{
@@ -295,7 +302,7 @@ protected function visitSimpleType(&$class, &$data, SimpleType $type, $name)
295302
* Override necessary to improve method to load validations from schema element.
296303
*
297304
* @param PHPClass $class
298-
* @param bool $arrayize
305+
* @param bool $arrayize
299306
*
300307
* @return PHPProperty
301308
*/
@@ -328,8 +335,8 @@ protected function &visitAttribute(&$class, Schema $schema, AttributeItem $attri
328335
* Responsible for handler all properties from extension types.
329336
*
330337
* @param PHPClass $class
331-
* @param array $data
332-
* @param string $parentName
338+
* @param array $data
339+
* @param string $parentName
333340
*/
334341
protected function &handleClassExtension(&$class, &$data, Type $type, $parentName)
335342
{

0 commit comments

Comments
 (0)