Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
divya-intelli committed May 30, 2023
1 parent 83e7fe5 commit cdb9894
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"php-http/guzzle7-adapter": "^1.0",
"php-http/mock-client": "^1.1.0",
"phpmetrics/phpmetrics": "^2.7",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^9.6",
"sebastian/comparator": "^4.0.5",
"symfony/cache": "~3.4 || ~4.0",
"vimeo/psalm": "^3.18.2 || ^5.0"
Expand Down
7 changes: 1 addition & 6 deletions src/Api/ApigeeX/Normalizer/ApiProductNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory
*/
public function normalize($object, $format = null, array $context = [])
{
$normalized = (array) parent::normalize($object, $format, $context);

//convert to ArrayObject as symfony normalizer throws error for std object.
//set ARRAY_AS_PROPS flag as we need entries to be accessed as properties.
$array_as_props = \ArrayObject::ARRAY_AS_PROPS;
$normalized = new \ArrayObject($normalized, $array_as_props);
$normalized = parent::normalize($object, $format, $context);

return $normalized;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ public function normalize($object, $format = null, array $context = [])

//convert to ArrayObject as symfony normalizer throws error for std object.
//set ARRAY_AS_PROPS flag as we need entries to be accessed as properties.
$array_as_props = \ArrayObject::ARRAY_AS_PROPS;
$normalized = new \ArrayObject($normalized, $array_as_props);

return $normalized;
return new \ArrayObject($normalized, \ArrayObject::ARRAY_AS_PROPS);
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/Api/Monetization/Normalizer/ApiPackageNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ public function normalize($object, $format = null, array $context = [])
$normalized['product'][$id] = (object) ['id' => $data['id']];
}

//convert to ArrayObject as symfony normalizer throws error for std object.
//set ARRAY_AS_PROPS flag as we need entries to be accessed as properties.
$array_as_props = \ArrayObject::ARRAY_AS_PROPS;
$normalized = new \ArrayObject($normalized, $array_as_props);

return $normalized;
return $this->convertToArrayObject($normalized);
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/Api/Monetization/Normalizer/EntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ public function normalize($object, $format = null, array $context = [])
}
}

//convert to ArrayObject as symfony normalizer throws error for std object.
//set ARRAY_AS_PROPS flag as we need entries to be accessed as properties.
$array_as_props = \ArrayObject::ARRAY_AS_PROPS;
$normalized = new \ArrayObject($normalized, $array_as_props);

return $normalized;
return $this->convertToArrayObject($normalized);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Normalizer/CredentialProductNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public function normalize($object, $format = null, array $context = [])

//Need to convert to ArrayObject as symfony normalizer throws error for std object.
//Need to set ARRAY_AS_PROPS flag as we need Entries to be accessed as properties.
$array_as_props = \ArrayObject::ARRAY_AS_PROPS;
$asObject = new \ArrayObject($asObject, $array_as_props);

return $asObject;
return new \ArrayObject($asObject, \ArrayObject::ARRAY_AS_PROPS);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions src/Normalizer/ObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ public function normalize($object, $format = null, array $context = [])
return !is_null($value);
});
ksort($asArray);
//Need to convert to ArrayObject as symfony normalizer throws error for std object.
//Need to set ARRAY_AS_PROPS flag as we need Entries to be accessed as properties.
$array_as_props = \ArrayObject::ARRAY_AS_PROPS;
$asArray = new \ArrayObject($asArray, $array_as_props);

return $asArray;
return $this->convertToArrayObject($asArray);
}

/**
Expand All @@ -129,4 +125,13 @@ public function setSerializer(SerializerInterface $serializer): void
$this->serializer = $serializer;
$this->objectNormalizer->setSerializer($serializer);
}

/**
* {@inheritDoc}
*/
public function convertToArrayObject($normalized, $array_as_props = \ArrayObject::ARRAY_AS_PROPS)
{
//default set ARRAY_AS_PROPS flag as we need entries to be accessed as properties.
return new \ArrayObject($normalized, $array_as_props);
}
}
5 changes: 1 addition & 4 deletions src/Normalizer/PropertiesPropertyNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ public function normalize($object, $format = null, array $context = [])

//convert to ArrayObject as symfony normalizer throws error for std object.
//set ARRAY_AS_PROPS flag as we need entries to be accessed as properties.
$array_as_props = \ArrayObject::ARRAY_AS_PROPS;
$return = new \ArrayObject($return, $array_as_props);

return $return;
return new \ArrayObject($return, \ArrayObject::ARRAY_AS_PROPS);
}

/**
Expand Down

0 comments on commit cdb9894

Please sign in to comment.