Skip to content

Commit 63e255b

Browse files
authored
Merge pull request #313 from ahilles107/php_8_compat
PHP 8 compatibility
2 parents 588db94 + 34bcfb8 commit 63e255b

38 files changed

+113
-78
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ cache:
66
- $HOME/.composer/cache
77

88
php:
9-
- '7.2'
109
- '7.3'
11-
- '7.4snapshot'
10+
- '7.4'
11+
- '8.0'
1212

1313
env:
1414
- SYMFONY_VERSION=^3.4

composer.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
}
1818
],
1919
"require": {
20-
"php": "^7.2",
20+
"php": "^7.2 | ^8.0",
2121
"doctrine/annotations": "~1.0",
2222
"jms/serializer": "^3.2",
2323
"jms/metadata": "^2.0",
2424
"symfony/expression-language": "~3.0 || ~4.0 || ~5.0"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^7",
28-
"doctrine/coding-standard": "^5.0",
27+
"phpunit/phpunit": "^7 | ^9",
28+
"doctrine/coding-standard": "^5.0 | ^8.0",
2929
"doctrine/persistence": "^1.3.4",
3030
"symfony/yaml": "~3.0 || ~4.0 || ~5.0",
3131
"symfony/routing": "~3.0 || ~4.0 || ~5.0",
3232
"pagerfanta/pagerfanta": "~1.0",
33-
"twig/twig": "^1.34 || ^2.0 || ^3.0"
33+
"twig/twig": "^1.34 || ^2.0 || ^3.0",
34+
"phpspec/prophecy-phpunit": "^2.0"
3435
},
3536
"suggest": {
3637
"symfony/yaml": "To use yaml based configuration.",

phpcs.xml.dist

+28-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@
3333

3434
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/>
3535

36-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
37-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
38-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification"/>
36+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator.RequiredNullCoalesceEqualOperator"/>
37+
38+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix"/>
39+
40+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
41+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
42+
43+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
44+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
45+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
3946
</rule>
4047

4148
<rule ref="SlevomatCodingStandard.ControlStructures.RequireYodaComparison"/>
@@ -72,9 +79,26 @@
7279
<exclude-pattern>tests/*</exclude-pattern>
7380
</rule>
7481

75-
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
82+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
83+
<exclude-pattern>tests/*</exclude-pattern>
84+
</rule>
85+
86+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint">
87+
<exclude-pattern>tests/*</exclude-pattern>
88+
</rule>
89+
90+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint">
91+
<exclude-pattern>tests/*</exclude-pattern>
92+
</rule>
93+
94+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint">
7695
<exclude-pattern>tests/*</exclude-pattern>
7796
</rule>
97+
98+
<rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps">
99+
<exclude-pattern>tests/*</exclude-pattern>
100+
</rule>
101+
78102
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements">
79103
<exclude-pattern>tests/*</exclude-pattern>
80104
</rule>

src/Configuration/Metadata/ClassMetadata.php

-6
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,11 @@ public function getRelations(): array
2828
return $this->relations;
2929
}
3030

31-
/**
32-
* {@inheritDoc}
33-
*/
3431
public function addRelation(Relation $relation): void
3532
{
3633
$this->relations[] = $relation;
3734
}
3835

39-
/**
40-
* {@inheritDoc}
41-
*/
4236
public function merge(MergeableInterface $object): void
4337
{
4438
if (!$object instanceof self) {

src/Configuration/Metadata/Driver/AnnotationDriver.php

-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public function __construct(
5050
$this->typeParser = $typeParser;
5151
}
5252

53-
/**
54-
* {@inheritdoc}
55-
*/
5653
public function loadMetadataForClass(\ReflectionClass $class): ?JMSClassMetadata
5754
{
5855
$annotations = $this->reader->getClassAnnotations($class);

src/Configuration/Metadata/Driver/CheckExpressionTrait.php

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private function checkExpression($exp, array $names = [])
2424
{
2525
if (is_string($exp) && preg_match('/expr\((?P<expression>.+)\)/', $exp, $matches)) {
2626
$names = array_merge($names, ['object', 'context', 'metadata']);
27+
2728
return $this->expressionLanguage->parse($matches['expression'], $names);
2829
} else {
2930
return $exp;
@@ -36,6 +37,7 @@ private function checkExpressionArray(array $data): array
3637
foreach ($data as $key => $value) {
3738
$newArray[$key] = $this->checkExpression($value);
3839
}
40+
3941
return $newArray;
4042
}
4143
}

src/Configuration/Metadata/Driver/ExtensionDriver.php

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public function __construct(DriverInterface $delegate, array $extensions = [])
2727
$this->extensions = $extensions;
2828
}
2929

30-
/**
31-
* {@inheritdoc}
32-
*/
3330
public function loadMetadataForClass(\ReflectionClass $class): ?JMSClassMetadata
3431
{
3532
$metadata = $this->delegate->loadMetadataForClass($class);

src/Configuration/Metadata/Driver/XmlDriver.php

-6
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ public function __construct(
4646
$this->typeParser = $typeParser;
4747
}
4848

49-
/**
50-
* {@inheritdoc}
51-
*/
5249
protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?JMSClassMetadata
5350
{
5451
$previous = libxml_use_internal_errors(true);
@@ -115,9 +112,6 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file):
115112
return $classMetadata;
116113
}
117114

118-
/**
119-
* {@inheritdoc}
120-
*/
121115
protected function getExtension(): string
122116
{
123117
return 'xml';

src/Configuration/Metadata/Driver/YamlDriver.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public function __construct(
4545
$this->typeParser = $typeParser;
4646
}
4747

48-
/**
49-
* {@inheritdoc}
50-
*/
5148
protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?JMSClassMetadata
5249
{
5350
$config = Yaml::parse(file_get_contents($file));
@@ -67,7 +64,7 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file):
6764
$relation['rel'],
6865
$this->createHref($relation),
6966
$this->createEmbedded($relation),
70-
isset($relation['attributes']) ? $this->checkExpressionArray($relation['attributes']): [],
67+
isset($relation['attributes']) ? $this->checkExpressionArray($relation['attributes']) : [],
7168
$this->createExclusion($relation)
7269
));
7370
}
@@ -85,9 +82,6 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file):
8582
return $classMetadata;
8683
}
8784

88-
/**
89-
* {@inheritdoc}
90-
*/
9185
protected function getExtension(): string
9286
{
9387
return 'yml';
@@ -151,6 +145,7 @@ private function createEmbedded($relation)
151145
}
152146

153147
$xmlElementName = isset($embedded['xmlElementName']) ? $this->checkExpression((string) $embedded['xmlElementName']) : null;
148+
154149
return new Embedded(
155150
$this->checkExpression($embedded['content']),
156151
$xmlElementName,

src/Expression/LinkExpressionFunction.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ class LinkExpressionFunction implements ExpressionFunctionProviderInterface
1212
/**
1313
* @return ExpressionFunction[]
1414
*
15-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint
16-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation
15+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
1716
*/
1817
public function getFunctions()
1918
{
20-
return [new ExpressionFunction('link', static function ($object, $rel, $absolute = false) {
19+
return [
20+
new ExpressionFunction('link', static function ($object, $rel, $absolute = false) {
2121
return sprintf('$link_helper->getLinkHref(%s, %s, %s)', $object, $rel, $absolute);
22-
}, static function ($context, $object, $rel, $absolute = false) {
23-
return $context['link_helper']->getLinkHref($object, $rel, $absolute);
24-
}),
22+
}, static function ($context, $object, $rel, $absolute = false) {
23+
return $context['link_helper']->getLinkHref($object, $rel, $absolute);
24+
}),
2525
];
2626
}
2727
}

src/Factory/EmbeddedsFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Hateoas\Factory;
66

7-
use Hateoas\Configuration\Relation;
87
use Hateoas\Model\Embedded;
98
use Hateoas\Serializer\ExclusionManager;
109
use Hateoas\Serializer\Metadata\RelationPropertyMetadata;
@@ -66,6 +65,7 @@ public function create(object $object, SerializationContext $context): array
6665
$embeddeds[] = new Embedded($rel, $data, $propertyMetadata, $xmlElementName, $relation->getEmbedded()->getType());
6766
}
6867
}
68+
6969
return $embeddeds;
7070
}
7171

src/HateoasBuilder.php

-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ public function setExpressionLanguage(ExpressionLanguage $expressionLanguage): H
260260
return $this;
261261
}
262262

263-
264263
public function addConfigurationExtension(ConfigurationExtensionInterface $configurationExtension): HateoasBuilder
265264
{
266265
$this->configurationExtensions[] = $configurationExtension;

src/Representation/AbstractSegmentedRepresentation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class AbstractSegmentedRepresentation extends RouteAwareRepresentation
4040
public function __construct(
4141
$inline,
4242
string $route,
43-
array $parameters = [],
43+
array $parameters,
4444
int $limit,
4545
?int $total = null,
4646
?string $limitParameterName = null,

src/Representation/OffsetRepresentation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class OffsetRepresentation extends AbstractSegmentedRepresentation
7272
public function __construct(
7373
CollectionRepresentation $inline,
7474
string $route,
75-
array $parameters = [],
75+
array $parameters,
7676
?int $offset,
7777
?int $limit,
7878
?int $total = null,

src/Representation/PaginatedRepresentation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class PaginatedRepresentation extends AbstractSegmentedRepresentation
8585
public function __construct(
8686
$inline,
8787
string $route,
88-
array $parameters = [],
88+
array $parameters,
8989
?int $page,
9090
?int $limit,
9191
?int $pages,

src/Serializer/ExclusionManager.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ public function shouldSkipLink(object $object, Relation $relation, Serialization
2828
return true;
2929
}
3030

31-
if (null === $relation->getHref()) {
32-
return true;
33-
}
34-
35-
return false;
31+
return null === $relation->getHref();
3632
}
3733

3834
public function shouldSkipEmbedded(object $object, Relation $relation, SerializationContext $context): bool
@@ -62,13 +58,8 @@ private function shouldSkip(Relation $relation, ?Exclusion $exclusion = null, Se
6258
}
6359
}
6460

65-
if (null !== $exclusion
61+
return null !== $exclusion
6662
&& null !== $exclusion->getExcludeIf()
67-
&& $this->expressionExclusionStrategy->shouldSkipProperty($propertyMetadata, $context)
68-
) {
69-
return true;
70-
}
71-
72-
return false;
63+
&& $this->expressionExclusionStrategy->shouldSkipProperty($propertyMetadata, $context);
7364
}
7465
}

src/Serializer/Metadata/InlineDeferrer.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ private function getParentObjectInlining(object $object, SerializationContext $c
4949
if (count($visitingStack) > 0) {
5050
$parentObject = $visitingStack[0];
5151
}
52+
5253
if ($parentObject === $object && count($visitingStack) > 1) {
5354
$parentObject = $visitingStack[1]; // $object is inlined inside $parentObject
5455
}
5556

56-
if ($metadataStack->count() > 0 && isset($metadataStack[0]->inline) && $metadataStack[0]->inline
57+
if (
58+
$metadataStack->count() > 0 && isset($metadataStack[0]->inline) && $metadataStack[0]->inline
5759
&& $context->getMetadataFactory()->getMetadataForClass(get_class($parentObject)) === $metadataStack[1]
5860
) {
5961
return $parentObject;

src/Serializer/XmlHalSerializer.php

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use JMS\Serializer\SerializationContext;
1010
use JMS\Serializer\Visitor\SerializationVisitorInterface;
1111
use JMS\Serializer\XmlSerializationVisitor;
12+
1213
use function is_bool;
1314

1415
class XmlHalSerializer implements SerializerInterface
@@ -85,6 +86,7 @@ private function acceptDataAndAppend(Embedded $embedded, $data, XmlSerialization
8586
}
8687
} catch (NotAcceptableException $e) {
8788
}
89+
8890
$context->popPropertyMetadata();
8991
}
9092

@@ -96,6 +98,7 @@ private function formatValue($attributeValue): string
9698
if (is_bool($attributeValue)) {
9799
return $attributeValue ? 'true' : 'false';
98100
}
101+
99102
return (string) $attributeValue;
100103
}
101104
}

src/Serializer/XmlSerializer.php

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use JMS\Serializer\SerializationContext;
1212
use JMS\Serializer\Visitor\SerializationVisitorInterface;
1313
use JMS\Serializer\XmlSerializationVisitor;
14+
1415
use function is_bool;
1516

1617
class XmlSerializer implements SerializerInterface
@@ -96,6 +97,7 @@ private function acceptDataAndAppend(Embedded $embedded, $data, XmlSerialization
9697
}
9798
} catch (NotAcceptableException $e) {
9899
}
100+
99101
$context->popPropertyMetadata();
100102
}
101103

@@ -107,6 +109,7 @@ private function formatValue($attributeValue): string
107109
if (is_bool($attributeValue)) {
108110
return $attributeValue ? 'true' : 'false';
109111
}
112+
110113
return (string) $attributeValue;
111114
}
112115
}

src/UrlGenerator/CallableUrlGenerator.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct(callable $callable)
1515
{
1616
$this->callable = $callable;
1717
}
18+
1819
/**
1920
* @param bool|int $absolute
2021
*/

tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testUser()
5959
/** @var Relation[] $relations */
6060
$relations = $classMetadata->getRelations();
6161

62-
$this->assertInternalType('array', $relations);
62+
$this->assertIsArray($relations);
6363
foreach ($relations as $relation) {
6464
$this->assertInstanceOf('Hateoas\Configuration\Relation', $relation);
6565
}
@@ -140,7 +140,7 @@ public function testUser()
140140

141141
/** @var RelationProvider[] $relations */
142142
$relations = $classMetadata->getRelations();
143-
$this->assertInternalType('array', $relations);
143+
$this->assertIsArray($relations);
144144
$this->assertCount(8, $relations);
145145

146146
// $relation = current($relations);

0 commit comments

Comments
 (0)