Skip to content

Commit bd222cb

Browse files
authored
chore: better PHP types (#4886)
1 parent d06ecf0 commit bd222cb

6 files changed

+16
-25
lines changed

CallableProcessor.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,23 @@ public function __construct(private readonly ContainerInterface $locator)
2626
/**
2727
* {@inheritDoc}
2828
*/
29-
public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
29+
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
3030
{
3131
if (!($processor = $operation->getProcessor())) {
32-
return;
32+
return null;
3333
}
3434

3535
if (\is_callable($processor)) {
3636
return $processor($data, $operation, $uriVariables, $context);
3737
}
3838

39-
if (\is_string($processor)) {
40-
if (!$this->locator->has($processor)) {
41-
throw new RuntimeException(sprintf('Processor "%s" not found on operation "%s"', $processor, $operation->getName()));
42-
}
39+
if (!$this->locator->has($processor)) {
40+
throw new RuntimeException(sprintf('Processor "%s" not found on operation "%s"', $processor, $operation->getName()));
41+
}
4342

44-
/** @var ProcessorInterface */
45-
$processor = $this->locator->get($processor);
43+
/** @var ProcessorInterface $processorInstance */
44+
$processorInstance = $this->locator->get($processor);
4645

47-
return $processor->process($data, $operation, $uriVariables, $context);
48-
}
46+
return $processorInstance->process($data, $operation, $uriVariables, $context);
4947
}
5048
}

CallableProvider.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(private readonly ContainerInterface $locator)
2626
/**
2727
* {@inheritDoc}
2828
*/
29-
public function provide(Operation $operation, array $uriVariables = [], array $context = [])
29+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|iterable|null
3030
{
3131
if (\is_callable($provider = $operation->getProvider())) {
3232
return $provider($operation, $uriVariables, $context);
@@ -37,10 +37,10 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
3737
throw new RuntimeException(sprintf('Provider "%s" not found on operation "%s"', $provider, $operation->getName()));
3838
}
3939

40-
/** @var ProviderInterface */
41-
$provider = $this->locator->get($provider);
40+
/** @var ProviderInterface $providerInstance */
41+
$providerInstance = $this->locator->get($provider);
4242

43-
return $provider->provide($operation, $uriVariables, $context);
43+
return $providerInstance->provide($operation, $uriVariables, $context);
4444
}
4545

4646
throw new RuntimeException(sprintf('Provider not found on operation "%s"', $operation->getName()));

Pagination/Pagination.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,8 @@ private function getGraphQlEnabled(?Operation $operation): bool
221221

222222
/**
223223
* Gets the given pagination parameter name from the given context.
224-
*
225-
* @param mixed|null $default
226224
*/
227-
private function getParameterFromContext(array $context, string $parameterName, $default = null)
225+
private function getParameterFromContext(array $context, string $parameterName, mixed $default = null)
228226
{
229227
$filters = $context['filters'] ?? [];
230228

ProcessorInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ interface ProcessorInterface
2626
/**
2727
* Handle the state.
2828
*/
29-
public function process($data, Operation $operation, array $uriVariables = [], array $context = []);
29+
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []);
3030
}

ProviderInterface.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ interface ProviderInterface
2525
{
2626
/**
2727
* Provides data.
28-
*
29-
* @return object|array|null
3028
*/
31-
public function provide(Operation $operation, array $uriVariables = [], array $context = []);
29+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|iterable|null;
3230
}

SerializerAwareProviderTrait.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ trait SerializerAwareProviderTrait
2525
{
2626
/**
2727
* @internal
28-
*
29-
* @var ContainerInterface
3028
*/
31-
private $serializerLocator;
29+
private ContainerInterface $serializerLocator;
3230

3331
public function setSerializerLocator(ContainerInterface $serializerLocator): void
3432
{
@@ -37,7 +35,6 @@ public function setSerializerLocator(ContainerInterface $serializerLocator): voi
3735

3836
private function getSerializer(): SerializerInterface
3937
{
40-
/* @var SerializerInterface */
4138
return $this->serializerLocator->get('serializer');
4239
}
4340
}

0 commit comments

Comments
 (0)