Skip to content

Commit

Permalink
Merge pull request #150 from goetas-webservices/valid-types
Browse files Browse the repository at this point in the history
Valid types
  • Loading branch information
goetas authored Sep 14, 2022
2 parents b76f9ae + 19637aa commit df731b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/Xsd2PhpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected static function sanitizePhp($ns)
return strtr($ns, '/', '\\');
}

public function getAlias()
public function getAlias(): string
{
return 'xsd2php';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Jms/YamlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ protected function getElementNamespace(Schema $schema, ElementItem $element)
* @param Element $element
* @param bool $arrayize
*
* @return \GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPProperty
* @return array
*/
protected function &visitElement(&$class, Schema $schema, ElementItem $element, $arrayize = true)
{
Expand Down
21 changes: 14 additions & 7 deletions src/Jms/YamlValidatorConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ private function loadValidatorType(array &$property, Type $type, $arrayized = fa
$rules = [];

if (($restrictions = $type->getRestriction()) && $checks = $restrictions->getChecks()) {
$propertyType = isset($property['type']) ? $property['type'] : null;
foreach ($checks as $key => $check) {
switch ($key) {
case 'enumeration':
$rules[] = [
'Choice' => [
'choices' => array_map(function ($enum) {
'choices' => array_map(function ($enum) use ($propertyType) {
if ($propertyType === 'int') {
return (int)$enum['value'];
}
if ($propertyType === 'float') {
return (float)$enum['value'];
}
return $enum['value'];
}, $check),
],
Expand Down Expand Up @@ -250,7 +257,7 @@ private function loadValidatorElement(array &$property, ElementItem $element)
* from a schema attribute including required rule.
*
* @param AttributeItem $element
* @param bool $arrayize
* @param bool $arrayize
*/
private function loadValidatorAttribute(array &$property, AttributeItem $attribute)
{
Expand All @@ -273,8 +280,8 @@ private function loadValidatorAttribute(array &$property, AttributeItem $attribu
* Override necessary to improve method to load validations from schema type.
*
* @param PHPClass $class
* @param array $data
* @param string $name
* @param array $data
* @param string $name
*/
protected function visitSimpleType(&$class, &$data, SimpleType $type, $name)
{
Expand All @@ -295,7 +302,7 @@ protected function visitSimpleType(&$class, &$data, SimpleType $type, $name)
* Override necessary to improve method to load validations from schema element.
*
* @param PHPClass $class
* @param bool $arrayize
* @param bool $arrayize
*
* @return PHPProperty
*/
Expand Down Expand Up @@ -328,8 +335,8 @@ protected function &visitAttribute(&$class, Schema $schema, AttributeItem $attri
* Responsible for handler all properties from extension types.
*
* @param PHPClass $class
* @param array $data
* @param string $parentName
* @param array $data
* @param string $parentName
*/
protected function &handleClassExtension(&$class, &$data, Type $type, $parentName)
{
Expand Down

0 comments on commit df731b2

Please sign in to comment.