Skip to content

Commit 8f21e28

Browse files
loic425diimpp
andcommitted
Apply suggestions from code review
Co-authored-by: Dmitri Perunov <[email protected]>
1 parent 4e7bcd2 commit 8f21e28

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/Bundle/Context/Initiator/LegacyRequestContextInitiator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ public function __construct(
3030
private RequestContextInitiatorInterface $decorated,
3131
private ?VarsResolverInterface $varsResolver = null,
3232
) {
33+
if (null === $varsResolver) {
34+
trigger_deprecation(
35+
'sylius/resource-bundle',
36+
'1.14',
37+
'Not passing an instance of "%s" as the fourth constructor argument for "%s" is deprecated and will not be supported in 2.0.',
38+
VarsResolverInterface::class,
39+
self::class,
40+
);
41+
}
3342
}
3443

3544
public function initializeContext(Request $request): Context

src/Component/src/Metadata/Operation/HttpOperationInitiator.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public function __construct(
2626
private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
2727
private ?VarsResolverInterface $varsResolver = null,
2828
) {
29+
if (null === $varsResolver) {
30+
trigger_deprecation(
31+
'sylius/resource-bundle',
32+
'1.14',
33+
'Not passing an instance of "%s" as the third constructor argument for "%s" is deprecated and will not be supported in 2.0.',
34+
VarsResolverInterface::class,
35+
self::class,
36+
);
37+
}
2938
}
3039

3140
public function initializeOperation(Request $request): ?HttpOperation
@@ -61,20 +70,19 @@ public function initializeOperation(Request $request): ?HttpOperation
6170

6271
private function getOperationWithVars(HttpOperation $operation): HttpOperation
6372
{
64-
$operationVars = null !== $operation->getVars() ? $this->resolveVars($operation->getVars()) : null;
65-
66-
if (null !== $operationVars) {
67-
$operation = $operation->withVars($operationVars);
68-
}
73+
$operationVars = $operation->getVars();
74+
$resolvedOperationVars = $operationVars !== null ? $this->resolveVars($operationVars) : null;
6975

70-
$resource = $operation->getResource();
71-
$resourceVars = $resource?->getVars();
76+
$resourceVars = $operation->getResource()?->getVars();
77+
$resolvedResourceVars = $resourceVars !== null ? $this->resolveVars($resourceVars) : null;
7278

73-
if (null === $resourceVars) {
79+
if (null === $resolvedOperationVars && null === $resolvedResourceVars) {
7480
return $operation;
7581
}
7682

77-
return $operation->withVars(\array_merge($this->resolveVars($resourceVars), $operationVars ?? []));
83+
$mergedVars = array_merge($resolvedResourceVars ?? [], $resolvedOperationVars ?? []);
84+
85+
return $operation->withVars($mergedVars);
7886
}
7987

8088
private function resolveVars(array $vars): array

src/Component/tests/Metadata/Operation/HttpOperationInitiatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testItInitializesHttpOperationsFromRequest(): void
9797
$this->assertSame($operation->reveal(), $initiator->initializeOperation($request->reveal()));
9898
}
9999

100-
public function testResolvesOperationVars(): void
100+
public function testItResolvesOperationVars(): void
101101
{
102102
$request = $this->prophesize(Request::class);
103103
$attributes = $this->prophesize(ParameterBag::class);

0 commit comments

Comments
 (0)