Skip to content

Commit

Permalink
Avoid parsing PHP 8 code under PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Mar 15, 2024
1 parent 57be670 commit 76d4c73
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 72 deletions.
9 changes: 7 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ parameters:

-
message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\SuppressDeprecationNormalizer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#"
count: 2
path: tests/End2End/App/SuppressDeprecationNormalizer.php
count: 1
path: tests/End2End/App/SuppressDeprecationNormalizer.php7.php

-
message: "#^Method Facile\\\\MongoDbMessenger\\\\Tests\\\\End2End\\\\App\\\\SuppressDeprecationNormalizer\\:\\:normalize\\(\\) return type with generic class ArrayObject does not specify its types\\: TKey, TValue$#"
count: 1
path: tests/End2End/App/SuppressDeprecationNormalizer.php8.php

-
message: "#^Parameter \\#1 \\$id of method Facile\\\\MongoDbMessenger\\\\Transport\\\\MongoDbUnresettableTransport\\:\\:find\\(\\) expects MongoDB\\\\BSON\\\\ObjectId\\|string, mixed given\\.$#"
Expand Down
72 changes: 2 additions & 70 deletions tests/End2End/App/SuppressDeprecationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,8 @@

namespace Facile\MongoDbMessenger\Tests\End2End\App;

use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\Messenger\Stamp\RedeliveryStamp;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;

if (\Symfony\Component\HttpKernel\Kernel::VERSION_ID >= 6_03_00) {
class SuppressDeprecationNormalizer extends ObjectNormalizerDecorator
{
/**
* @return array<string, bool>
*/
public function getSupportedTypes(?string $format): array
{
return [
FlattenException::class => true,
RedeliveryStamp::class => true,
];
}

/**
* @param mixed $data Data to restore
* @param string $type
* @param string|null $format
* @param array<string, mixed>&array{ignored_attributes?: string[]} $context
*/
public function denormalize($data, $type, $format = null, array $context = []): mixed
{
return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub
}

/**
* @param mixed $object
* @param string|null $format
* @param array<string, mixed>&array{ignored_attributes?: string[]} $context
*
* @return array<mixed>|string|int|float|bool|\ArrayObject|null
*/
public function normalize($object, $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
{
return $this->doNormalize($object, $format, $context);
}
}
require_once __DIR__ . '/SuppressDeprecationNormalizer.php8.php';
} else {
class SuppressDeprecationNormalizer extends ObjectNormalizerDecorator implements CacheableSupportsMethodInterface
{
public function hasCacheableSupportsMethod(): bool
{
return $this->objectNormalizer->hasCacheableSupportsMethod();
}

/**
* @param mixed $data Data to restore
* @param string $type
* @param string|null $format
* @param array<string, mixed>&array{ignored_attributes?: string[]} $context
*/
public function denormalize($data, $type, $format = null, array $context = [])
{
return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub
}

/**
* @param mixed $object
* @param string|null $format
* @param array<string, mixed>&array{ignored_attributes?: string[]} $context
*
* @return array<mixed>|string|int|float|bool|\ArrayObject|null
*/
public function normalize($object, $format = null, array $context = [])
{
return $this->doNormalize($object, $format, $context);
}
}
require_once __DIR__ . '/SuppressDeprecationNormalizer.php7.php';
}
38 changes: 38 additions & 0 deletions tests/End2End/App/SuppressDeprecationNormalizer.php7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Facile\MongoDbMessenger\Tests\End2End\App;

use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;

class SuppressDeprecationNormalizer extends ObjectNormalizerDecorator implements CacheableSupportsMethodInterface
{
public function hasCacheableSupportsMethod(): bool
{
return $this->objectNormalizer->hasCacheableSupportsMethod();
}

/**
* @param mixed $data Data to restore
* @param string $type
* @param string|null $format
* @param array<string, mixed>&array{ignored_attributes?: string[]} $context
*/
public function denormalize($data, $type, $format = null, array $context = [])
{
return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub
}

/**
* @param mixed $object
* @param string|null $format
* @param array<string, mixed>&array{ignored_attributes?: string[]} $context
*
* @return array<mixed>|string|int|float|bool|\ArrayObject|null
*/
public function normalize($object, $format = null, array $context = [])
{
return $this->doNormalize($object, $format, $context);
}
}
45 changes: 45 additions & 0 deletions tests/End2End/App/SuppressDeprecationNormalizer.php8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Facile\MongoDbMessenger\Tests\End2End\App;

use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\Messenger\Stamp\RedeliveryStamp;

class SuppressDeprecationNormalizer extends ObjectNormalizerDecorator
{
/**
* @return array<string, bool>
*/
public function getSupportedTypes(?string $format): array
{
return [
FlattenException::class => true,
RedeliveryStamp::class => true,
];
}

/**
* @param mixed $data Data to restore
* @param string $type
* @param string|null $format
* @param array<string, mixed>&array{ignored_attributes?: string[]} $context
*/
public function denormalize($data, $type, $format = null, array $context = []): mixed
{
return parent::doDenormalize($data, $type, $format, $context); // TODO: Change the autogenerated stub
}

/**
* @param mixed $object
* @param string|null $format
* @param array<string, mixed>&array{ignored_attributes?: string[]} $context
*
* @return array<mixed>|string|int|float|bool|\ArrayObject|null
*/
public function normalize($object, $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
{
return $this->doNormalize($object, $format, $context);
}
}

0 comments on commit 76d4c73

Please sign in to comment.