Skip to content

Commit 921d116

Browse files
committed
phpstan
1 parent 596747f commit 921d116

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

src/Hydra/State/JsonStreamerProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
use ApiPlatform\Hydra\PartialCollectionView;
2020
use ApiPlatform\Metadata\CollectionOperationInterface;
2121
use ApiPlatform\Metadata\Error;
22+
use ApiPlatform\Metadata\HttpOperation;
2223
use ApiPlatform\Metadata\IriConverterInterface;
2324
use ApiPlatform\Metadata\Operation;
2425
use ApiPlatform\Metadata\Operation\Factory\OperationMetadataFactoryInterface;
2526
use ApiPlatform\Metadata\QueryParameterInterface;
2627
use ApiPlatform\Metadata\ResourceClassResolverInterface;
2728
use ApiPlatform\Metadata\UrlGeneratorInterface;
2829
use ApiPlatform\Metadata\Util\IriHelper;
30+
use ApiPlatform\State\Pagination\PartialPaginatorInterface;
2931
use ApiPlatform\State\Util\HttpResponseStatusTrait;
3032
use ApiPlatform\State\Pagination\PaginatorInterface;
3133
use ApiPlatform\State\ProcessorInterface;
@@ -77,7 +79,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
7779
return $this->processor->process($data, $operation, $uriVariables, $context);
7880
}
7981

80-
if ($operation instanceof Error || $data instanceof Response) {
82+
if ($operation instanceof Error || $data instanceof Response || !$operation instanceof HttpOperation) {
8183
return $this->processor->process($data, $operation, $uriVariables, $context);
8284
}
8385

src/JsonLd/JsonStreamer/ValueTransformer/ContextValueTransformer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Metadata\UrlGeneratorInterface;
1717
use Symfony\Component\JsonStreamer\ValueTransformer\ValueTransformerInterface;
1818
use Symfony\Component\TypeInfo\Type;
19+
use ApiPlatform\Metadata\Exception\RuntimeException;
1920

2021
final class ContextValueTransformer implements ValueTransformerInterface
2122
{
@@ -26,6 +27,9 @@ public function __construct(
2627

2728
public function transform(mixed $value, array $options = []): mixed
2829
{
30+
if (!isset($options['operation'])) {
31+
throw new RuntimeException('Operation is not defined');
32+
}
2933
return $this->urlGenerator->generate('api_jsonld_context', ['shortName' => $options['operation']->getShortName()], $options['operation']->getUrlGenerationStrategy());
3034
}
3135

src/JsonLd/JsonStreamer/ValueTransformer/IriValueTransformer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Hydra\Collection;
1717
use ApiPlatform\Metadata\CollectionOperationInterface;
18+
use ApiPlatform\Metadata\Exception\RuntimeException;
1819
use ApiPlatform\Metadata\IriConverterInterface;
1920
use ApiPlatform\Metadata\UrlGeneratorInterface;
2021
use Symfony\Component\JsonStreamer\ValueTransformer\ValueTransformerInterface;
@@ -29,6 +30,10 @@ public function __construct(
2930

3031
public function transform(mixed $value, array $options = []): mixed
3132
{
33+
if (!isset($options['operation'])) {
34+
throw new RuntimeException('Operation is not defined');
35+
}
36+
3237
if ($options['_current_object'] instanceof Collection) {
3338
return $this->iriConverter->getIriFromResource($options['operation']->getClass(), UrlGeneratorInterface::ABS_PATH, $options['operation']);
3439
}

src/JsonLd/JsonStreamer/ValueTransformer/TypeValueTransformer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\JsonLd\JsonStreamer\ValueTransformer;
1515

1616
use ApiPlatform\Hydra\Collection;
17+
use ApiPlatform\Metadata\Exception\RuntimeException;
1718
use Symfony\Component\JsonStreamer\ValueTransformer\ValueTransformerInterface;
1819
use Symfony\Component\TypeInfo\Type;
1920

@@ -25,6 +26,10 @@ public function transform(mixed $value, array $options = []): mixed
2526
return 'Collection';
2627
}
2728

29+
if (!isset($options['operation'])) {
30+
throw new RuntimeException('Operation is not defined');
31+
}
32+
2833
return $options['operation']->getShortName();
2934
}
3035

0 commit comments

Comments
 (0)