Skip to content

Commit 8433eb4

Browse files
committed
fix(deprec): fix php 8.5 deprecations
1 parent d10a34f commit 8433eb4

11 files changed

+28
-24
lines changed

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ parameters:
99
tmpDir: cache
1010

1111
ignoreErrors:
12-
- "#Instantiated class fromIteratorToArray not found#"
13-
- "#Instantiated class toArray not found#"
14-
1512
-
1613
message: "#^Method Symfony\\\\Component\\\\Serializer\\\\NameConverter\\\\NameConverterInterface\\:\\:normalize\\(\\) invoked with 2 parameters, 1 required\\.$#"
1714
count: 2

src/GeneratedMapper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function getTargetIdentifiers(mixed $value): mixed
4141
return null;
4242
}
4343

44-
public function getSourceHash(mixed $value): ?string
44+
public function getSourceHash(mixed $value): string
4545
{
46-
return null;
46+
return '';
4747
}
4848

49-
public function getTargetHash(mixed $value): ?string
49+
public function getTargetHash(mixed $value): string
5050
{
51-
return null;
51+
return '';
5252
}
5353

5454
/** @var array<string, MapperInterface<object, object>|MapperInterface<object, array<mixed>>|MapperInterface<array<mixed>, object>> */

src/Generator/IdentifierHashGenerator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private function getStatements(GeneratorMetadata $metadata, bool $fromSource): a
6565
if ($property->source->checkExists) {
6666
$statements[] = new Stmt\If_($property->source->accessor->getIsUndefinedExpression($valueVariable), [
6767
'stmts' => [
68-
new Stmt\Return_(new Expr\ConstFetch(new Name('null'))),
68+
new Stmt\Return_(new Expr\ConstFetch(new Name("''"))),
6969
],
7070
]);
7171
}
@@ -78,7 +78,7 @@ private function getStatements(GeneratorMetadata $metadata, bool $fromSource): a
7878
} else {
7979
$statements[] = new Stmt\If_($property->target->readAccessor->getIsUndefinedExpression($valueVariable, true), [
8080
'stmts' => [
81-
new Stmt\Return_(new Expr\ConstFetch(new Name('null'))),
81+
new Stmt\Return_(new Expr\ConstFetch(new Name("''"))),
8282
],
8383
]);
8484

@@ -121,7 +121,7 @@ public function getSourceHashMethod(GeneratorMetadata $metadata): ?Stmt\ClassMet
121121

122122
return (new Builder\Method('getSourceHash'))
123123
->makePublic()
124-
->setReturnType('?string')
124+
->setReturnType('string')
125125
->addParam(new Param(
126126
var: new Expr\Variable('value'),
127127
type: new Name('mixed'))
@@ -149,7 +149,7 @@ public function getTargetHashMethod(GeneratorMetadata $metadata): ?Stmt\ClassMet
149149

150150
return (new Builder\Method('getTargetHash'))
151151
->makePublic()
152-
->setReturnType('?string')
152+
->setReturnType('string')
153153
->addParam(new Param(
154154
var: new Expr\Variable('value'),
155155
type: new Name('mixed'))

src/Transformer/AbstractArrayTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM
7575
$loopExistingStatements[] = new Stmt\If_($isDeepPopulateExpr, [
7676
'stmts' => [
7777
new Stmt\Expression(new Expr\Assign($targetHashVar, $this->itemTransformer->getTargetHashExpression($loopRemoveValueVar))),
78-
new Stmt\If_(new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name('null')), $targetHashVar), [
78+
new Stmt\If_(new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name("''")), $targetHashVar), [
7979
'stmts' => [new Stmt\Expression(new Expr\Assign(new Expr\ArrayDimFetch($exisingValuesIndexed, $targetHashVar), $loopRemoveValueVar))],
8080
]),
8181
],
@@ -124,7 +124,7 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM
124124
new Stmt\Foreach_($propertyMapping->target->readAccessor->getExpression($target), $loopExistingValueVar, [
125125
'stmts' => [
126126
new Stmt\Expression(new Expr\Assign($hashValueVariable, $this->itemTransformer->getTargetHashExpression($loopExistingValueVar))),
127-
new Stmt\If_(new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name('null')), $hashValueVariable), [
127+
new Stmt\If_(new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name("''")), $hashValueVariable), [
128128
'stmts' => [
129129
new Stmt\Expression(new Expr\Assign(new Expr\ArrayDimFetch($exisingValuesIndexed, $hashValueVariable), $loopExistingValueVar)),
130130
],

src/Transformer/ArrayToDoctrineCollectionTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM
5656
new Stmt\Foreach_($propertyMapping->target->readAccessor->getExpression($target), $loopExistingValueVar, [
5757
'stmts' => [
5858
new Stmt\Expression(new Expr\Assign($hashValueVariable, $this->itemTransformer->getTargetHashExpression($loopExistingValueVar))),
59-
new Stmt\If_(new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name('null')), $hashValueVariable), [
59+
new Stmt\If_(new Expr\BinaryOp\NotIdentical(new Expr\ConstFetch(new Name("''")), $hashValueVariable), [
6060
'stmts' => [
6161
new Stmt\Expression(new Expr\Assign(new Expr\ArrayDimFetch($exisingValuesIndexed, $hashValueVariable), $loopExistingValueVar)),
6262
],

src/Transformer/BuiltinTransformer.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
TypeIdentifier::BOOL->value => [
2929
TypeIdentifier::INT->value => Cast\Int_::class,
3030
TypeIdentifier::STRING->value => Cast\String_::class,
31-
TypeIdentifier::FLOAT->value => Cast\Double::class,
31+
TypeIdentifier::FLOAT->value => 'toFloat',
3232
TypeIdentifier::ARRAY->value => 'toArray',
3333
TypeIdentifier::ITERABLE->value => 'toArray',
3434
],
3535
TypeIdentifier::MIXED->value => [
3636
TypeIdentifier::INT->value => Cast\Int_::class,
3737
TypeIdentifier::STRING->value => Cast\String_::class,
38-
TypeIdentifier::FLOAT->value => Cast\Double::class,
38+
TypeIdentifier::FLOAT->value => 'toFloat',
3939
TypeIdentifier::ARRAY->value => 'toArray',
4040
TypeIdentifier::ITERABLE->value => 'toArray',
4141
],
@@ -47,7 +47,7 @@
4747
TypeIdentifier::ITERABLE->value => 'toArray',
4848
],
4949
TypeIdentifier::INT->value => [
50-
TypeIdentifier::FLOAT->value => Cast\Double::class,
50+
TypeIdentifier::FLOAT->value => 'toFloat',
5151
TypeIdentifier::STRING->value => Cast\String_::class,
5252
TypeIdentifier::BOOL->value => Cast\Bool_::class,
5353
TypeIdentifier::ARRAY->value => 'toArray',
@@ -60,7 +60,7 @@
6060
TypeIdentifier::STRING->value => [
6161
TypeIdentifier::ARRAY->value => 'toArray',
6262
TypeIdentifier::ITERABLE->value => 'toArray',
63-
TypeIdentifier::FLOAT->value => Cast\Double::class,
63+
TypeIdentifier::FLOAT->value => 'toFloat',
6464
TypeIdentifier::INT->value => Cast\Int_::class,
6565
TypeIdentifier::BOOL->value => Cast\Bool_::class,
6666
],
@@ -120,6 +120,10 @@ public function transform(Expr $input, Expr $target, PropertyMetadata $propertyM
120120
return [$this->$castMethod($input), []];
121121
}
122122

123+
if (!class_exists($castMethod)) {
124+
continue;
125+
}
126+
123127
/*
124128
* Use the cast expression find in the cast matrix
125129
*
@@ -156,6 +160,11 @@ private function toArray(Expr $input): Expr
156160
return new Expr\Array_([create_expr_array_item($input)]);
157161
}
158162

163+
private function toFloat(Expr $input): Expr
164+
{
165+
return new Cast\Double($input, ['kind' => Cast\Double::KIND_FLOAT]);
166+
}
167+
159168
private function fromIteratorToArray(Expr $input): Expr
160169
{
161170
return new Expr\FuncCall(new Name('iterator_to_array'), [

tests/AutoMapperMapToTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function testDateTimeFormat(): void
149149
self::assertArrayHasKey('immutable', $result);
150150
self::assertSame($immutable->format(\DateTimeInterface::RFC822), $result['immutable']);
151151
self::assertArrayHasKey('interface', $result);
152-
self::assertSame($normal->format(\DateTimeInterface::RFC7231), $result['interface']);
152+
self::assertSame($normal->format(\DateTimeInterface::RFC3339_EXTENDED), $result['interface']);
153153

154154
$bar = new MapperDateTimeFormatMapTo($normal, $immutable, $normal);
155155
$result = $this->autoMapper->map($bar, 'array');
@@ -159,7 +159,7 @@ public function testDateTimeFormat(): void
159159
self::assertArrayHasKey('immutable', $result);
160160
self::assertSame($immutable->format(\DateTimeInterface::ATOM), $result['immutable']);
161161
self::assertArrayHasKey('interface', $result);
162-
self::assertSame($normal->format(\DateTimeInterface::RFC7231), $result['interface']);
162+
self::assertSame($normal->format(\DateTimeInterface::RFC3339_EXTENDED), $result['interface']);
163163

164164
$baz = new MapperDateTimeFormatMapTo($normal, $immutable, $normal);
165165
$result = $this->autoMapper->map($baz, 'array', [MapperContext::DATETIME_FORMAT => \DateTimeInterface::RFC822]);

tests/AutoMapperTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ public function testNotReadable(): void
216216
self::assertInstanceOf(Address::class, $addressMapped);
217217

218218
$property = (new \ReflectionClass($addressMapped))->getProperty('city');
219-
$property->setAccessible(true);
220219

221220
$city = $property->getValue($addressMapped);
222221

tests/Fixtures/MapTo/DateTimeFormatMapTo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function __construct(
1313
public \DateTime $normal,
1414
#[MapTo('array', dateTimeFormat: \DateTimeInterface::RFC822)]
1515
public \DateTimeImmutable $immutable,
16-
#[MapTo('array', dateTimeFormat: \DateTimeInterface::RFC7231)]
16+
#[MapTo('array', dateTimeFormat: \DateTimeInterface::RFC3339_EXTENDED)]
1717
public \DateTimeInterface $interface,
1818
) {
1919
}

tests/Fixtures/MapTo/MapperDateTimeFormatMapTo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MapperDateTimeFormatMapTo
1313
public function __construct(
1414
public \DateTime $normal,
1515
public \DateTimeImmutable $immutable,
16-
#[MapTo('array', dateTimeFormat: \DateTimeInterface::RFC7231)]
16+
#[MapTo('array', dateTimeFormat: \DateTimeInterface::RFC3339_EXTENDED)]
1717
public \DateTimeInterface $interface,
1818
) {
1919
}

0 commit comments

Comments
 (0)