Skip to content

Commit cc42333

Browse files
vincentchalamonalanpoulain
authored andcommitted
chore: remove PHP specific code based on PHP_VERSION_ID
1 parent 53ec00d commit cc42333

19 files changed

+57
-257
lines changed

src/GraphQl/Type/Definition/IterableType.php

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,20 @@
1818
use GraphQL\Language\AST\FloatValueNode;
1919
use GraphQL\Language\AST\IntValueNode;
2020
use GraphQL\Language\AST\ListValueNode;
21-
use GraphQL\Language\AST\Node;
2221
use GraphQL\Language\AST\NullValueNode;
2322
use GraphQL\Language\AST\ObjectValueNode;
2423
use GraphQL\Language\AST\StringValueNode;
2524
use GraphQL\Language\AST\ValueNode;
2625
use GraphQL\Type\Definition\ScalarType;
2726
use GraphQL\Utils\Utils;
2827

29-
if (\PHP_VERSION_ID >= 70200) {
30-
trait IterableTypeParseLiteralTrait
31-
{
32-
/**
33-
* {@inheritdoc}
34-
*
35-
* @param ObjectValueNode|ListValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|NullValueNode $valueNode
36-
*
37-
* @return mixed
38-
*/
39-
public function parseLiteral(/* Node */ $valueNode, ?array $variables = null)
40-
{
41-
if ($valueNode instanceof ObjectValueNode || $valueNode instanceof ListValueNode) {
42-
return $this->parseIterableLiteral($valueNode);
43-
}
44-
45-
// Intentionally without message, as all information already in wrapped Exception
46-
throw new \Exception();
47-
}
48-
}
49-
} else {
50-
trait IterableTypeParseLiteralTrait
51-
{
52-
/**
53-
* {@inheritdoc}
54-
*
55-
* @param ObjectValueNode|ListValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|NullValueNode $valueNode
56-
*/
57-
public function parseLiteral(Node $valueNode, ?array $variables = null)
58-
{
59-
if ($valueNode instanceof ObjectValueNode || $valueNode instanceof ListValueNode) {
60-
return $this->parseIterableLiteral($valueNode);
61-
}
62-
63-
// Intentionally without message, as all information already in wrapped Exception
64-
throw new \Exception();
65-
}
66-
}
67-
}
68-
6928
/**
7029
* Represents an iterable type.
7130
*
7231
* @author Alan Poulain <[email protected]>
7332
*/
7433
final class IterableType extends ScalarType implements TypeInterface
7534
{
76-
use IterableTypeParseLiteralTrait;
77-
7835
public function __construct()
7936
{
8037
$this->name = 'Iterable';
@@ -116,6 +73,23 @@ public function parseValue($value)
11673
return $value;
11774
}
11875

76+
/**
77+
* {@inheritdoc}
78+
*
79+
* @param ObjectValueNode|ListValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|NullValueNode $valueNode
80+
*
81+
* @return mixed
82+
*/
83+
public function parseLiteral($valueNode, ?array $variables = null)
84+
{
85+
if ($valueNode instanceof ObjectValueNode || $valueNode instanceof ListValueNode) {
86+
return $this->parseIterableLiteral($valueNode);
87+
}
88+
89+
// Intentionally without message, as all information already in wrapped Exception
90+
throw new \Exception();
91+
}
92+
11993
/**
12094
* @param StringValueNode|BooleanValueNode|IntValueNode|FloatValueNode|ObjectValueNode|ListValueNode|ValueNode $valueNode
12195
*/

src/GraphQl/Type/Definition/UploadType.php

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,13 @@
1919
use GraphQL\Utils\Utils;
2020
use Symfony\Component\HttpFoundation\File\UploadedFile;
2121

22-
if (\PHP_VERSION_ID >= 70200) {
23-
trait UploadTypeParseLiteralTrait
24-
{
25-
/**
26-
* {@inheritdoc}
27-
*
28-
* @return mixed
29-
*/
30-
public function parseLiteral(/* Node */ $valueNode, array $variables = null)
31-
{
32-
throw new Error('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification.', $valueNode);
33-
}
34-
}
35-
} else {
36-
trait UploadTypeParseLiteralTrait
37-
{
38-
/**
39-
* {@inheritdoc}
40-
*/
41-
public function parseLiteral(Node $valueNode, array $variables = null)
42-
{
43-
throw new Error('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification.', $valueNode);
44-
}
45-
}
46-
}
47-
4822
/**
4923
* Represents an upload type.
5024
*
5125
* @author Mahmood Bazdar <[email protected]>
5226
*/
5327
final class UploadType extends ScalarType implements TypeInterface
5428
{
55-
use UploadTypeParseLiteralTrait;
56-
5729
public function __construct()
5830
{
5931
$this->name = 'Upload';
@@ -88,4 +60,16 @@ public function parseValue($value): UploadedFile
8860

8961
return $value;
9062
}
63+
64+
/**
65+
* {@inheritdoc}
66+
*
67+
* @param Node $valueNode
68+
*
69+
* @return mixed
70+
*/
71+
public function parseLiteral($valueNode, array $variables = null)
72+
{
73+
throw new Error('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification.', $valueNode);
74+
}
9175
}

src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function create(string $resourceClass, string $property, array $options =
5353

5454
if ($reflectionClass->hasProperty($property)) {
5555
$reflectionProperty = $reflectionClass->getProperty($property);
56-
if (\PHP_VERSION_ID >= 80000 && $attributes = $reflectionProperty->getAttributes(ApiProperty::class)) {
56+
if ($attributes = $reflectionProperty->getAttributes(ApiProperty::class)) {
5757
return $this->createMetadata($attributes[0]->newInstance(), $parentPropertyMetadata);
5858
}
5959
}
@@ -69,7 +69,7 @@ public function create(string $resourceClass, string $property, array $options =
6969
continue;
7070
}
7171

72-
if (\PHP_VERSION_ID >= 80000 && $attributes = $reflectionMethod->getAttributes(ApiProperty::class)) {
72+
if ($attributes = $reflectionMethod->getAttributes(ApiProperty::class)) {
7373
return $this->createMetadata($attributes[0]->newInstance(), $parentPropertyMetadata);
7474
}
7575
}

src/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
7676
throw new ResourceClassNotFoundException(sprintf('Resource "%s" not found.', $resourceClass));
7777
}
7878

79-
if (\PHP_VERSION_ID >= 80000 && $this->hasResourceAttributes($reflectionClass)) {
79+
if ($this->hasResourceAttributes($reflectionClass)) {
8080
foreach ($this->buildResourceOperations($reflectionClass->getAttributes(), $resourceClass) as $i => $resource) {
8181
$resourceMetadataCollection[] = $resource;
8282
}

src/Metadata/Resource/Factory/AttributesResourceNameCollectionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function create(): ResourceNameCollection
5252
}
5353

5454
foreach (ReflectionClassRecursiveIterator::getReflectionClassesFromDirectories($this->paths) as $className => $reflectionClass) {
55-
if (\PHP_VERSION_ID >= 80000 && $this->isResource($reflectionClass)) {
55+
if ($this->isResource($reflectionClass)) {
5656
$classes[$className] = true;
5757
}
5858
}

src/Metadata/Resource/Factory/LinkFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ public function createLinksFromRelations($operation): array
8383
*/
8484
public function createLinksFromAttributes($operation): array
8585
{
86-
if (\PHP_VERSION_ID < 80000) {
87-
return [];
88-
}
89-
9086
$links = [];
9187
try {
9288
$reflectionClass = new \ReflectionClass($resourceClass = $operation->getClass());

src/Serializer/JsonEncoder.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\Serializer\Encoder\JsonDecode;
1919
use Symfony\Component\Serializer\Encoder\JsonEncode;
2020
use Symfony\Component\Serializer\Encoder\JsonEncoder as BaseJsonEncoder;
21-
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
2221

2322
/**
2423
* A JSON encoder with appropriate default options to embed the generated document into HTML.
@@ -39,17 +38,11 @@ public function __construct(string $format, BaseJsonEncoder $jsonEncoder = null)
3938
return;
4039
}
4140

42-
// Encode <, >, ', &, and " characters in the JSON, making it also safe to be embedded into HTML.
43-
$jsonEncodeOptions = \JSON_HEX_TAG | \JSON_HEX_APOS | \JSON_HEX_AMP | \JSON_HEX_QUOT | \JSON_UNESCAPED_UNICODE;
44-
if (interface_exists(AdvancedNameConverterInterface::class)) {
45-
$jsonEncode = new JsonEncode(['json_encode_options' => $jsonEncodeOptions]);
46-
$jsonDecode = new JsonDecode(['json_decode_associative' => true]);
47-
} else {
48-
$jsonEncode = new JsonEncode($jsonEncodeOptions);
49-
$jsonDecode = new JsonDecode(true);
50-
}
51-
52-
$this->jsonEncoder = new BaseJsonEncoder($jsonEncode, $jsonDecode);
41+
$this->jsonEncoder = new BaseJsonEncoder(
42+
// Encode <, >, ', &, and " characters in the JSON, making it also safe to be embedded into HTML.
43+
new JsonEncode(['json_encode_options' => \JSON_HEX_TAG | \JSON_HEX_APOS | \JSON_HEX_AMP | \JSON_HEX_QUOT | \JSON_UNESCAPED_UNICODE]),
44+
new JsonDecode(['json_decode_associative' => true])
45+
);
5346
}
5447

5548
/**

src/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ private function addOpenApiSection(ArrayNodeDefinition $rootNode): void
437437
->scalarNode('email')->defaultNull()->info('The email address of the contact person/organization. MUST be in the format of an email address.')->end()
438438
->end()
439439
->end()
440-
->booleanNode('backward_compatibility_layer')->defaultTrue()->info('Enable this to decorate the "api_platform.swagger.normalizer.documentation" instead of decorating the OpenAPI factory.')->end()
441440
->scalarNode('termsOfService')->defaultNull()->info('A URL to the Terms of Service for the API. MUST be in the format of a URL.')->end()
442441
->arrayNode('license')
443442
->addDefaultsIfNotSet()

src/Symfony/Bundle/Test/Response.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\Symfony\Bundle\Test;
1515

16-
use ApiPlatform\Util\ResponseTrait;
1716
use Symfony\Component\BrowserKit\Response as BrowserKitResponse;
1817
use Symfony\Component\HttpClient\Exception\ClientException;
1918
use Symfony\Component\HttpClient\Exception\JsonException;
@@ -34,8 +33,6 @@
3433
*/
3534
final class Response implements ResponseInterface
3635
{
37-
use ResponseTrait;
38-
3936
private $httpFoundationResponse;
4037
private $browserKitResponse;
4138
private $headers;
@@ -70,6 +67,15 @@ public function __construct(HttpFoundationResponse $httpFoundationResponse, Brow
7067
] + $info;
7168
}
7269

70+
public function getInfo(?string $type = null): mixed
71+
{
72+
if ($type) {
73+
return $this->info[$type] ?? null;
74+
}
75+
76+
return $this->info;
77+
}
78+
7379
/**
7480
* Checks the status, and try to extract message if appropriate.
7581
*/
@@ -140,15 +146,11 @@ public function toArray(bool $throw = true): array
140146
}
141147

142148
try {
143-
$content = json_decode($content, true, 512, \JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? \JSON_THROW_ON_ERROR : 0));
149+
$content = json_decode($content, true, 512, \JSON_BIGINT_AS_STRING | \JSON_THROW_ON_ERROR);
144150
} catch (\JsonException $e) {
145151
throw new JsonException($e->getMessage(), $e->getCode());
146152
}
147153

148-
if (\PHP_VERSION_ID < 70300 && \JSON_ERROR_NONE !== json_last_error()) {
149-
throw new JsonException(json_last_error_msg(), json_last_error());
150-
}
151-
152154
if (!\is_array($content)) {
153155
throw new JsonException(sprintf('JSON content was expected to decode to an array, %s returned.', \gettype($content)));
154156
}

src/Symfony/Maker/Resources/skeleton/StateProvider.tpl.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
class <?php echo $class_name; ?> implements ProviderInterface
1010
{
11-
public function provide(Operation $operation, array $uriVariables = [], array $context = [])<?php if (\PHP_VERSION_ID >= 80000) { ?>: object|array|null<?php } ?>
12-
11+
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
1312
{
1413
// Retrieve the state from somewhere
1514
}

0 commit comments

Comments
 (0)