Skip to content

Commit 8877270

Browse files
authored
Performance improvements (#12)
Don't use call_user_func_array. Instead call functions directly
1 parent ba1dda7 commit 8877270

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
],
1313
"require": {
1414
"symplify/easy-coding-standard": "^7.2.3",
15-
"wol-soft/php-json-schema-model-generator-production": "^0.12.0",
16-
"wol-soft/php-micro-template": "^1.3.1",
15+
"wol-soft/php-json-schema-model-generator-production": "^0.12.1",
16+
"wol-soft/php-micro-template": "^1.3.2",
1717

1818
"php": ">=7.2",
1919
"ext-json": "*",

docs/source/gettingStarted.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Installation
66

77
The recommended way to install php-json-model-generator is through `Composer <http://getcomposer.org>`_:
88

9-
.. code-block:: rconsole
9+
.. code-block:: console
1010
1111
composer require --dev wol-soft/php-json-schema-model-generator
1212
composer require wol-soft/php-json-schema-model-generator-production

src/PropertyProcessor/ComposedValue/AbstractComposedValueProcessor.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ protected function generateValidators(PropertyInterface $property, array $proper
4343
// @codeCoverageIgnoreEnd
4444
}
4545

46-
$properties = $this->getCompositionProperties($property, $propertyData);
47-
$availableAmount = count($properties);
46+
$compositionProperties = $this->getCompositionProperties($property, $propertyData);
47+
$availableAmount = count($compositionProperties);
4848

4949
$property->addValidator(
5050
new ComposedPropertyValidator(
5151
$property,
52-
$properties,
52+
$compositionProperties,
5353
static::class,
5454
[
55-
'properties' => $properties,
55+
'properties' => $compositionProperties,
5656
'generatorConfiguration' => $this->schemaProcessor->getGeneratorConfiguration(),
5757
'viewHelper' => new RenderHelper($this->schemaProcessor->getGeneratorConfiguration()),
5858
'availableAmount' => $availableAmount,
@@ -63,7 +63,7 @@ protected function generateValidators(PropertyInterface $property, array $proper
6363
'postPropose' => $this instanceof ComposedPropertiesInterface,
6464
'mergedProperty' =>
6565
$this instanceof MergedComposedPropertiesInterface
66-
? $this->createMergedProperty($property, $properties, $propertyData)
66+
? $this->createMergedProperty($property, $compositionProperties, $propertyData)
6767
: null,
6868
'onlyForDefinedValues' =>
6969
$propertyData['onlyForDefinedValues'] && $this instanceof ComposedPropertiesInterface,
@@ -86,7 +86,7 @@ protected function generateValidators(PropertyInterface $property, array $proper
8686
protected function getCompositionProperties(PropertyInterface $property, array $propertyData): array
8787
{
8888
$propertyFactory = new PropertyFactory(new PropertyProcessorFactory());
89-
$properties = [];
89+
$compositionProperties = [];
9090

9191
foreach ($propertyData['propertyData'][$propertyData['type']] as $compositionElement) {
9292
$compositionProperty = new CompositionPropertyDecorator(
@@ -113,36 +113,39 @@ protected function getCompositionProperties(PropertyInterface $property, array $
113113
$property->addTypeHintDecorator(new CompositionTypeHintDecorator($compositionProperty));
114114
}
115115

116-
$properties[] = $compositionProperty;
116+
$compositionProperties[] = $compositionProperty;
117117
}
118118

119-
return $properties;
119+
return $compositionProperties;
120120
}
121121

122122
/**
123123
* TODO: no nested properties --> cancel, only one --> use original model
124124
*
125125
* Gather all nested object properties and merge them together into a single merged property
126126
*
127-
* @param PropertyInterface $compositionProperty
127+
* @param PropertyInterface $property
128128
* @param CompositionPropertyDecorator[] $properties
129129
* @param array $propertyData
130130
*
131-
* @return PropertyInterface
131+
* @return PropertyInterface|null
132132
*
133133
* @throws SchemaException
134134
*/
135135
private function createMergedProperty(
136-
PropertyInterface $compositionProperty,
136+
PropertyInterface $property,
137137
array $properties,
138138
array $propertyData
139-
): PropertyInterface {
140-
$mergedClassName = $this->schemaProcessor->getGeneratorConfiguration()->getClassNameGenerator()->getClassName(
141-
$compositionProperty->getName(),
142-
$propertyData['propertyData'],
143-
true,
144-
$this->schemaProcessor->getCurrentClassName()
145-
);
139+
): ?PropertyInterface {
140+
$mergedClassName = $this->schemaProcessor
141+
->getGeneratorConfiguration()
142+
->getClassNameGenerator()
143+
->getClassName(
144+
$property->getName(),
145+
$propertyData['propertyData'],
146+
true,
147+
$this->schemaProcessor->getCurrentClassName()
148+
);
146149

147150
// check if the merged property already has been generated
148151
if (isset(self::$generatedMergedProperties[$mergedClassName])) {
@@ -161,7 +164,7 @@ private function createMergedProperty(
161164
$mergedPropertySchema
162165
);
163166

164-
$compositionProperty->addTypeHintDecorator(new CompositionTypeHintDecorator($mergedProperty));
167+
$property->addTypeHintDecorator(new CompositionTypeHintDecorator($mergedProperty));
165168

166169
return $mergedProperty
167170
->addDecorator(

src/Templates/Serializer/TransformingFilterSerializer.phptpl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
*/
44
protected function serialize{{ viewHelper.ucfirst(property) }}()
55
{
6-
return call_user_func_array(
7-
[\{{ serializerClass }}::class, "{{ serializerMethod }}"],
8-
[$this->{{ property }}, {{ serializerOptions }}]
9-
);
6+
return \{{ serializerClass }}::{{ serializerMethod }}($this->{{ property }}, {{ serializerOptions }});
107
}

src/Templates/Validator/Filter.phptpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(function (&$value) use (&$transformationFailed): bool {
55
// make sure exceptions from the filter are caught and added to the error handling
66
try {
7-
$value = call_user_func_array([\{{ filterClass }}::class, "{{ filterMethod }}"], [$value, {{ filterOptions }}]);
7+
$value = \{{ filterClass }}::{{ filterMethod }}($value, {{ filterOptions }});
88
} catch (\Exception $filterException) {
99
{% if isTransformingFilter %}
1010
$transformationFailed = true;

0 commit comments

Comments
 (0)