DX: apply rector rules up to php8.0

This commit is contained in:
2023-04-15 01:05:37 +02:00
parent d8870e906f
commit dde3002100
714 changed files with 2348 additions and 9263 deletions

View File

@@ -19,17 +19,8 @@ use function is_array;
class NormalizeNullValueHelper
{
private ?string $discriminatorType = null;
private ?string $discriminatorValue = null;
private NormalizerInterface $normalizer;
public function __construct(NormalizerInterface $normalizer, $discriminatorType = null, $discriminatorValue = null)
public function __construct(private NormalizerInterface $normalizer, private ?string $discriminatorType = null, private ?string $discriminatorValue = null)
{
$this->normalizer = $normalizer;
$this->discriminatorType = $discriminatorType;
$this->discriminatorValue = $discriminatorValue;
}
public function normalize(array $attributes, string $format = 'docgen', ?array $context = [], ?ClassMetadata $classMetadata = null)
@@ -45,27 +36,13 @@ class NormalizeNullValueHelper
if (is_numeric($key)) {
$data[$class] = '';
} else {
switch ($class) {
case 'array':
case 'bool':
case 'double':
case 'float':
case 'int':
case 'resource':
case 'string':
case 'null':
$data[$key] = '';
break;
default:
$data[$key] = $this->normalizer->normalize(null, $format, array_merge(
$this->getContextForAttribute($key, $context, $classMetadata),
['docgen:expects' => $class]
));
break;
}
$data[$key] = match ($class) {
'array', 'bool', 'double', 'float', 'int', 'resource', 'string', 'null' => '',
default => $this->normalizer->normalize(null, $format, array_merge(
$this->getContextForAttribute($key, $context, $classMetadata),
['docgen:expects' => $class]
)),
};
}
}

View File

@@ -40,19 +40,13 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
{
use NormalizerAwareTrait;
private ClassMetadataFactoryInterface $classMetadataFactory;
private PropertyAccessor $propertyAccess;
private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct(
ClassMetadataFactoryInterface $classMetadataFactory,
TranslatableStringHelperInterface $translatableStringHelper
private ClassMetadataFactoryInterface $classMetadataFactory,
private TranslatableStringHelperInterface $translatableStringHelper
) {
$this->classMetadataFactory = $classMetadataFactory;
$this->propertyAccess = PropertyAccess::createPropertyAccessor();
$this->translatableStringHelper = $translatableStringHelper;
}
public function normalize($object, $format = null, array $context = [])
@@ -66,7 +60,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
if (!$this->classMetadataFactory->hasMetadataFor($classMetadataKey)) {
throw new LogicException(sprintf(
'This object does not have metadata: %s. Add groups on this entity to allow to serialize with the format %s and groups %s',
is_object($object) ? get_class($object) : '(todo' /*$context['docgen:expects'],*/ ,
is_object($object) ? $object::class : '(todo' /*$context['docgen:expects'],*/ ,
$format,
implode(', ', ($context['groups'] ?? []))
));
@@ -199,10 +193,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
return $normalizer->normalize($keys, $format, $context, $metadata);
}
/**
* @param mixed $format
*/
private function normalizeNullOutputValue($format, array $context, AttributeMetadata $attribute, ReflectionClass $reflection)
private function normalizeNullOutputValue(mixed $format, array $context, AttributeMetadata $attribute, ReflectionClass $reflection)
{
$type = $this->getExpectedType($attribute, $reflection);