Skip to content

Commit fc08e61

Browse files
committed
more types
1 parent da456a4 commit fc08e61

File tree

10 files changed

+60
-9
lines changed

10 files changed

+60
-9
lines changed

src/HttpCache/State/AddHeadersProcessor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@
1818
use ApiPlatform\State\ProcessorInterface;
1919
use Symfony\Component\HttpFoundation\Response;
2020

21+
/**
22+
* @template T1
23+
* @template T2
24+
*
25+
* @implements ProcessorInterface<T1, T2>
26+
*/
2127
final class AddHeadersProcessor implements ProcessorInterface
2228
{
2329
/**
24-
* @param ProcessorInterface<Response>|ProcessorInterface<mixed> $decorated
30+
* @param ProcessorInterface<T1, T2> $decorated
2531
*/
2632
public function __construct(private readonly ProcessorInterface $decorated, private readonly bool $etag = false, private readonly ?int $maxAge = null, private readonly ?int $sharedMaxAge = null, private readonly ?array $vary = null, private readonly ?bool $public = null, private readonly ?int $staleWhileRevalidate = null, private readonly ?int $staleIfError = null)
2733
{

src/Hydra/State/HydraLinkProcessor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@
2222
use Symfony\Component\WebLink\GenericLinkProvider;
2323
use Symfony\Component\WebLink\Link;
2424

25+
/**
26+
* @template T1
27+
* @template T2
28+
*
29+
* @implements ProcessorInterface<T1, T2>
30+
*/
2531
final class HydraLinkProcessor implements ProcessorInterface
2632
{
2733
use CorsTrait;
2834

2935
/**
30-
* @param ProcessorInterface<mixed> $decorated
36+
* @param ProcessorInterface<T1, T2> $decorated
3137
*/
3238
public function __construct(private readonly ProcessorInterface $decorated, private readonly UrlGeneratorInterface $urlGenerator)
3339
{

src/State/CallableProcessor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
use ApiPlatform\Metadata\Operation;
1818
use Psr\Container\ContainerInterface;
1919

20+
/**
21+
* @template T1
22+
* @template T2
23+
*
24+
* @implements ProcessorInterface<T1, T2>
25+
*/
2026
final class CallableProcessor implements ProcessorInterface
2127
{
2228
public function __construct(private readonly ?ContainerInterface $locator = null)
@@ -40,7 +46,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
4046
throw new RuntimeException(sprintf('Processor "%s" not found on operation "%s"', $processor, $operation->getName()));
4147
}
4248

43-
/** @var ProcessorInterface $processorInstance */
49+
/** @var ProcessorInterface<T1, T2> $processorInstance */
4450
$processorInstance = $this->locator->get($processor);
4551

4652
return $processorInstance->process($data, $operation, $uriVariables, $context);

src/State/Processor/AddLinkHeaderProcessor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@
1818
use Symfony\Component\HttpFoundation\Response;
1919
use Symfony\Component\WebLink\HttpHeaderSerializer;
2020

21+
/**
22+
* @template T1
23+
* @template T2
24+
*
25+
* @implements ProcessorInterface<T1, T2>
26+
*/
2127
final class AddLinkHeaderProcessor implements ProcessorInterface
2228
{
29+
/**
30+
* @param ProcessorInterface<T1, T2> $decorated
31+
*/
2332
public function __construct(private readonly ProcessorInterface $decorated, private readonly ?HttpHeaderSerializer $serializer = new HttpHeaderSerializer())
2433
{
2534
}

src/State/Processor/RespondProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use ApiPlatform\Metadata\Util\ClassInfoTrait;
2525
use ApiPlatform\Metadata\Util\CloneTrait;
2626
use ApiPlatform\State\ProcessorInterface;
27+
use DateTimeInterface;
2728
use Symfony\Component\HttpFoundation\Response;
2829
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface as SymfonyHttpExceptionInterface;
2930

@@ -74,7 +75,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
7475
$status = $operation->getStatus();
7576

7677
if ($sunset = $operation->getSunset()) {
77-
$headers['Sunset'] = (new \DateTimeImmutable($sunset))->format(\DateTime::RFC1123);
78+
$headers['Sunset'] = (new \DateTimeImmutable($sunset))->format(DateTimeInterface::RFC1123);
7879
}
7980

8081
if ($acceptPatch = $operation->getAcceptPatch()) {

src/State/Processor/SerializeProcessor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@
2626
/**
2727
* Serializes data.
2828
*
29+
* @template T1
30+
* @template T2
31+
*
32+
* @implements ProcessorInterface<T1, T2>
33+
*
2934
* @author Kévin Dunglas <[email protected]>
3035
*/
3136
final class SerializeProcessor implements ProcessorInterface
3237
{
38+
/**
39+
* @param ProcessorInterface<T1, T2> $processor
40+
*/
3341
public function __construct(private readonly ProcessorInterface $processor, private readonly SerializerInterface $serializer, private readonly SerializerContextBuilderInterface $serializerContextBuilder)
3442
{
3543
}

src/State/Processor/WriteProcessor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@
2121
/**
2222
* Bridges persistence and the API system.
2323
*
24+
* @template T1
25+
* @template T2
26+
*
27+
* @implements ProcessorInterface<T1, T2>
28+
*
2429
* @author Kévin Dunglas <[email protected]>
2530
* @author Baptiste Meyer <[email protected]>
2631
*/
2732
final class WriteProcessor implements ProcessorInterface
2833
{
2934
use ClassInfoTrait;
3035

36+
/**
37+
* @param ProcessorInterface<T1, T2> $processor
38+
* @param ProcessorInterface<T1, T2> $callableProcessor
39+
*/
3140
public function __construct(private readonly ProcessorInterface $processor, private readonly ProcessorInterface $callableProcessor)
3241
{
3342
}

src/State/ProcessorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
/**
2020
* Processes data: sends an email, persists to storage, adds to queue etc.
2121
*
22-
* @template T1 of object
23-
* @template T2 of object
22+
* @template T1
23+
* @template T2
2424
*
2525
* @author Antoine Bluchet <[email protected]>
2626
*/

src/Symfony/State/MercureLinkProcessor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717
use ApiPlatform\State\ProcessorInterface;
1818
use Symfony\Component\Mercure\Discovery;
1919

20+
/**
21+
* @template T1
22+
* @template T2
23+
*
24+
* @implements ProcessorInterface<T1, T2>
25+
*/
2026
final class MercureLinkProcessor implements ProcessorInterface
2127
{
2228
/**
23-
* @param ProcessorInterface<mixed> $decorated
29+
* @param ProcessorInterface<T1, T2> $decorated
2430
*/
2531
public function __construct(private readonly ProcessorInterface $decorated, private readonly Discovery $discovery)
2632
{

tests/State/RespondProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testRedirectToOperation(): void
7171
return ($args[2] ?? null)?->getUriTemplate() ?? '/default';
7272
});
7373

74-
/** @var ProcessorInterface<Response> $respondProcessor */
74+
/** @var ProcessorInterface<string, Response> $respondProcessor */
7575
$respondProcessor = new RespondProcessor($iriConverter->reveal(), $resourceClassResolver->reveal(), $operationMetadataFactory->reveal());
7676

7777
$response = $respondProcessor->process('content', $canonicalUriTemplateRedirectingOperation, context: [
@@ -103,7 +103,7 @@ public function testAddsExceptionHeaders(): void
103103
{
104104
$operation = new Get();
105105

106-
/** @var ProcessorInterface<Response> $respondProcessor */
106+
/** @var ProcessorInterface<string, Response> $respondProcessor */
107107
$respondProcessor = new RespondProcessor();
108108
$req = new Request();
109109
$req->attributes->set('exception', new TooManyRequestsHttpException(32));

0 commit comments

Comments
 (0)