Skip to content

Commit

Permalink
minor #51146 More short closures (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 6.4 branch.

Discussion
----------

More short closures

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

cf173a3321 More short closures
  • Loading branch information
nicolas-grekas committed Jul 31, 2023
2 parents fc958b5 + d1017d7 commit 6ac5379
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions Builder/ConfigBuilderGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ private function buildToArray(ClassBuilder $class): void
if (null !== $p->getType()) {
if ($p->isArray()) {
$code = $p->areScalarsAllowed()
? 'array_map(function ($v) { return $v instanceof CLASS ? $v->toArray() : $v; }, $this->PROPERTY)'
: 'array_map(function ($v) { return $v->toArray(); }, $this->PROPERTY)'
? 'array_map(fn ($v) => $v instanceof CLASS ? $v->toArray() : $v, $this->PROPERTY)'
: 'array_map(fn ($v) => $v->toArray(), $this->PROPERTY)'
;
} else {
$code = $p->areScalarsAllowed()
Expand Down Expand Up @@ -514,8 +514,8 @@ private function buildConstructor(ClassBuilder $class): void
if (null !== $p->getType()) {
if ($p->isArray()) {
$code = $p->areScalarsAllowed()
? 'array_map(function ($v) { return \is_array($v) ? new '.$p->getType().'($v) : $v; }, $value[\'ORG_NAME\'])'
: 'array_map(function ($v) { return new '.$p->getType().'($v); }, $value[\'ORG_NAME\'])'
? 'array_map(fn ($v) => \is_array($v) ? new '.$p->getType().'($v) : $v, $value[\'ORG_NAME\'])'
: 'array_map(fn ($v) => new '.$p->getType().'($v), $value[\'ORG_NAME\'])'
;
} else {
$code = $p->areScalarsAllowed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public function __construct(array $value = [])
{
if (array_key_exists('routing', $value)) {
$this->_usedProperties['routing'] = true;
$this->routing = array_map(function ($v) { return new \Symfony\Config\AddToList\Messenger\RoutingConfig($v); }, $value['routing']);
$this->routing = array_map(fn ($v) => new \Symfony\Config\AddToList\Messenger\RoutingConfig($v), $value['routing']);
unset($value['routing']);
}

if (array_key_exists('receiving', $value)) {
$this->_usedProperties['receiving'] = true;
$this->receiving = array_map(function ($v) { return new \Symfony\Config\AddToList\Messenger\ReceivingConfig($v); }, $value['receiving']);
$this->receiving = array_map(fn ($v) => new \Symfony\Config\AddToList\Messenger\ReceivingConfig($v), $value['receiving']);
unset($value['receiving']);
}

Expand All @@ -58,10 +58,10 @@ public function toArray(): array
{
$output = [];
if (isset($this->_usedProperties['routing'])) {
$output['routing'] = array_map(function ($v) { return $v->toArray(); }, $this->routing);
$output['routing'] = array_map(fn ($v) => $v->toArray(), $this->routing);
}
if (isset($this->_usedProperties['receiving'])) {
$output['receiving'] = array_map(function ($v) { return $v->toArray(); }, $this->receiving);
$output['receiving'] = array_map(fn ($v) => $v->toArray(), $this->receiving);
}

return $output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(array $value = [])
{
if (array_key_exists('page', $value)) {
$this->_usedProperties['page'] = true;
$this->page = array_map(function ($v) { return new \Symfony\Config\AddToList\Translator\Books\PageConfig($v); }, $value['page']);
$this->page = array_map(fn ($v) => new \Symfony\Config\AddToList\Translator\Books\PageConfig($v), $value['page']);
unset($value['page']);
}

Expand All @@ -42,7 +42,7 @@ public function toArray(): array
{
$output = [];
if (isset($this->_usedProperties['page'])) {
$output['page'] = array_map(function ($v) { return $v->toArray(); }, $this->page);
$output['page'] = array_map(fn ($v) => $v->toArray(), $this->page);
}

return $output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(array $value = [])

if (array_key_exists('bar', $value)) {
$this->_usedProperties['bar'] = true;
$this->bar = array_map(function ($v) { return new \Symfony\Config\ArrayExtraKeys\BarConfig($v); }, $value['bar']);
$this->bar = array_map(fn ($v) => new \Symfony\Config\ArrayExtraKeys\BarConfig($v), $value['bar']);
unset($value['bar']);
}

Expand All @@ -86,7 +86,7 @@ public function toArray(): array
$output['foo'] = $this->foo->toArray();
}
if (isset($this->_usedProperties['bar'])) {
$output['bar'] = array_map(function ($v) { return $v->toArray(); }, $this->bar);
$output['bar'] = array_map(fn ($v) => $v->toArray(), $this->bar);
}
if (isset($this->_usedProperties['baz'])) {
$output['baz'] = $this->baz->toArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(array $value = [])
{
if (array_key_exists('transports', $value)) {
$this->_usedProperties['transports'] = true;
$this->transports = array_map(function ($v) { return new \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig($v); }, $value['transports']);
$this->transports = array_map(fn ($v) => new \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig($v), $value['transports']);
unset($value['transports']);
}

Expand All @@ -43,7 +43,7 @@ public function toArray(): array
{
$output = [];
if (isset($this->_usedProperties['transports'])) {
$output['transports'] = array_map(function ($v) { return $v->toArray(); }, $this->transports);
$output['transports'] = array_map(fn ($v) => $v->toArray(), $this->transports);
}

return $output;
Expand Down
18 changes: 9 additions & 9 deletions Tests/Builder/Fixtures/ScalarNormalizedTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode
->children()
->arrayNode('simple_array')
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
->beforeNormalization()->ifString()->then(fn ($v) => [$v])->end()
->prototype('scalar')->end()
->end()
->arrayNode('keyed_array')
->useAttributeAsKey('name')
->prototype('array')
->beforeNormalization()
->ifString()->then(function ($v) { return [$v]; })
->ifString()->then(fn ($v) => [$v])
->end()
->prototype('scalar')->end()
->end()
->end()
->arrayNode('object')
->addDefaultsIfNotSet()
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return ['enabled' => $v]; })
->ifTrue(fn ($v) => !\is_array($v))
->then(fn ($v) => ['enabled' => $v])
->end()
->children()
->booleanNode('enabled')->defaultNull()->end()
Expand Down Expand Up @@ -93,8 +93,8 @@ public function getConfigTreeBuilder(): TreeBuilder
->useAttributeAsKey('class')
->prototype('array')
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return ['enabled' => $v]; })
->ifTrue(fn ($v) => !\is_array($v))
->then(fn ($v) => ['enabled' => $v])
->end()
->children()
->booleanNode('enabled')->defaultTrue()->end()
Expand All @@ -109,16 +109,16 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayNode('nested_object')
->addDefaultsIfNotSet()
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return ['enabled' => $v]; })
->ifTrue(fn ($v) => !\is_array($v))
->then(fn ($v) => ['enabled' => $v])
->end()
->children()
->booleanNode('enabled')->defaultNull()->end()
->end()
->end()
->arrayNode('nested_list_object')
->beforeNormalization()
->ifTrue(function ($v) { return isset($v[0]) && \is_string($v[0]); })
->ifTrue(fn ($v) => isset($v[0]) && \is_string($v[0]))
->then(function ($values) {
return array_map(function (string $value) {
return ['name' => $value];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(array $value = [])

if (array_key_exists('nested_list_object', $value)) {
$this->_usedProperties['nestedListObject'] = true;
$this->nestedListObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig($v) : $v; }, $value['nested_list_object']);
$this->nestedListObject = array_map(fn ($v) => \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig($v) : $v, $value['nested_list_object']);
unset($value['nested_list_object']);
}

Expand All @@ -86,7 +86,7 @@ public function toArray(): array
$output['nested_object'] = $this->nestedObject instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig ? $this->nestedObject->toArray() : $this->nestedObject;
}
if (isset($this->_usedProperties['nestedListObject'])) {
$output['nested_list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig ? $v->toArray() : $v; }, $this->nestedListObject);
$output['nested_list_object'] = array_map(fn ($v) => $v instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig ? $v->toArray() : $v, $this->nestedListObject);
}

return $output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ public function __construct(array $value = [])

if (array_key_exists('list_object', $value)) {
$this->_usedProperties['listObject'] = true;
$this->listObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig($v) : $v; }, $value['list_object']);
$this->listObject = array_map(fn ($v) => \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig($v) : $v, $value['list_object']);
unset($value['list_object']);
}

if (array_key_exists('keyed_list_object', $value)) {
$this->_usedProperties['keyedListObject'] = true;
$this->keyedListObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig($v) : $v; }, $value['keyed_list_object']);
$this->keyedListObject = array_map(fn ($v) => \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig($v) : $v, $value['keyed_list_object']);
unset($value['keyed_list_object']);
}

Expand Down Expand Up @@ -189,10 +189,10 @@ public function toArray(): array
$output['object'] = $this->object instanceof \Symfony\Config\ScalarNormalizedTypes\ObjectConfig ? $this->object->toArray() : $this->object;
}
if (isset($this->_usedProperties['listObject'])) {
$output['list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig ? $v->toArray() : $v; }, $this->listObject);
$output['list_object'] = array_map(fn ($v) => $v instanceof \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig ? $v->toArray() : $v, $this->listObject);
}
if (isset($this->_usedProperties['keyedListObject'])) {
$output['keyed_list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig ? $v->toArray() : $v; }, $this->keyedListObject);
$output['keyed_list_object'] = array_map(fn ($v) => $v instanceof \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig ? $v->toArray() : $v, $this->keyedListObject);
}
if (isset($this->_usedProperties['nested'])) {
$output['nested'] = $this->nested->toArray();
Expand Down

0 comments on commit 6ac5379

Please sign in to comment.