Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/JsonMapper/Converter/CamelCasePropertyNameConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@
{
private Inflector $inflector;

/**
* Creates the converter with the Doctrine inflector responsible for camel case transformations.
*
* The inflector dependency is initialised here so it can be reused for every conversion.
*/
public function __construct()
{
$this->inflector = InflectorFactory::create()->build();
}

/**
* Converts a raw JSON property name to the camelCase variant expected by PHP properties.
*
* @param string $name Raw property name as provided by the JSON payload.
*
* @return string Normalised camelCase property name that matches PHP naming conventions.
*/
public function convert(string $name): string
{
return $this->inflector->camelize($name);
Expand Down
4 changes: 2 additions & 2 deletions src/JsonMapper/Converter/PropertyNameConverterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ interface PropertyNameConverterInterface
/**
* Convert the specified JSON property name to its PHP property name.
*
* @param string $name
* @param string $name Raw property name exactly as it appears in the JSON structure.
*
* @return string
* @return string Normalised PHP property name that matches the target object's naming scheme.
*/
public function convert(string $name): string;
}
Loading