Skip to content

Commit

Permalink
symfony#39102: fix code style suggestions and suggested changes, first.
Browse files Browse the repository at this point in the history
  • Loading branch information
Basster committed Dec 21, 2020
1 parent 21c4d46 commit cba66e8
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 94 deletions.
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use ReflectionException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand All @@ -25,9 +24,6 @@

class SerializerDebugPass implements CompilerPassInterface
{
/**
* @throws ReflectionException
*/
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('serializer')) {
Expand All @@ -39,9 +35,6 @@ public function process(ContainerBuilder $container): void
}
}

/**
* @throws ReflectionException
*/
private function decorateNormalizer(string $id, ContainerBuilder $container): void
{
$aliasName = 'debug.'.$id;
Expand Down Expand Up @@ -74,9 +67,7 @@ private function decorateNormalizer(string $id, ContainerBuilder $container): vo
$decoratorDef = (new Definition($decoratorClass))
->setArguments([$normalizerDef])
->addTag('debug.normalizer')
->setDecoratedService($id)
->setAutowired(true)
->setAutoconfigured(true);
->setDecoratedService($id);

$container->setDefinition($aliasName, $decoratorDef);
}
Expand Down
Expand Up @@ -17,22 +17,12 @@
return static function (ContainerConfigurator $container) {
$container->services()
->set('debug.serializer', TraceableSerializer::class)
->decorate('serializer', null, 255)
->args([
service('debug.serializer.inner'),
])
->tag('kernel.reset', [
'method' => 'reset',
])
->decorate('serializer', null, 255)
->args([service('debug.serializer.inner')])
->tag('kernel.reset', ['method' => 'reset'])

->set('data_collector.serializer', SerializerDataCollector::class)
->args([
service('debug.serializer'),
tagged_iterator('debug.normalizer'),
])
->tag('data_collector', [
'template' => '@WebProfiler/Collector/serializer.html.twig',
'id' => 'serializer',
])
->args([service('debug.serializer'),tagged_iterator('debug.normalizer')])
->tag('data_collector', ['template' => '@WebProfiler/Collector/serializer.html.twig','id' => 'serializer'])
;
};
Expand Up @@ -19,17 +19,10 @@
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Contracts\Service\ResetInterface;
use Throwable;

class SerializerDataCollector extends DataCollector
{
/**
* @var SerializerInterface|null
*/
private $serializer;
/**
* @var array|iterable
*/
private $normalizers;

public function __construct(SerializerInterface $serializer = null, iterable $normalizers = [])
Expand All @@ -38,7 +31,7 @@ public function __construct(SerializerInterface $serializer = null, iterable $no
$this->normalizers = $normalizers;
}

public function collect(Request $request, Response $response, Throwable $exception = null): void
public function collect(Request $request, Response $response, \Throwable $exception = null): void
{
$this->initData();

Expand Down
7 changes: 2 additions & 5 deletions src/Symfony/Component/Serializer/Debug/Deserialization.php
Expand Up @@ -13,14 +13,11 @@

class Deserialization extends SerializerAction
{
/**
* @var string
*/
public $type;

public function __construct($data, string $type, string $format, array $context = [])
public function __construct($data, $result, string $type, string $format, array $context = [])
{
parent::__construct($data, $format, $context);
parent::__construct($data, $result, $format, $context);
$this->type = $type;
}
}
Expand Up @@ -29,22 +29,19 @@ abstract class AbstractTraceableNormalizer implements SerializerAwareInterface,
private $denormalizations = [];

/**
* AbstractTraceableNormalizer constructor.
*
* @param DenormalizerInterface|NormalizerInterface $delegate
*/
public function __construct($delegate)
public function __construct(object $delegate)
{
$this->delegate = $delegate;
}

public function denormalize($data, string $type, string $format = null, array $context = [])
{
$denormalization = new Denormalization($this->delegate, $data, $type, $format, $context);
$denormalization->result = $this->delegate->denormalize($data, $type, $format, $context);
$this->denormalizations[] = $denormalization;
$result = $this->delegate->denormalize($data, $type, $format, $context);
$this->denormalizations[] = new Denormalization($this->delegate, $result, $data, $type, $format, $context);

return $denormalization->result;
return $result;
}

public function supportsDenormalization($data, string $type, string $format = null): bool
Expand All @@ -54,11 +51,10 @@ public function supportsDenormalization($data, string $type, string $format = nu

public function normalize($object, string $format = null, array $context = [])
{
$normalization = new Normalization($this->delegate, $object, $format, $context);
$normalization->result = $this->delegate->normalize($object, $format, $context);
$this->normalizations[] = $normalization;
$result = $this->delegate->normalize($object, $format, $context);
$this->normalizations[] = new Normalization($this->delegate, $object, $result, $format, $context);

return $normalization->result;
return $result;
}

public function supportsNormalization($data, string $format = null): bool
Expand All @@ -72,7 +68,7 @@ public function supportsNormalization($data, string $format = null): bool
* and pass them to the delegate.
*
* Unfortunately this is heavily bound to the Serializer implementation. :(
* @see \Symfony\Component\Serializer\Serializer:77
* @see \Symfony\Component\Serializer\Serializer:__construct()
*/

public function setSerializer(SerializerInterface $serializer): void
Expand All @@ -98,11 +94,7 @@ public function setNormalizer(NormalizerInterface $normalizer): void

public function hasCacheableSupportsMethod(): bool
{
if ($this->delegate instanceof CacheableSupportsMethodInterface) {
return $this->delegate->hasCacheableSupportsMethod();
}

return false;
return $this->delegate instanceof CacheableSupportsMethodInterface && $this->delegate->hasCacheableSupportsMethod();
}

public function getNormalizations(): array
Expand Down
Expand Up @@ -16,19 +16,11 @@

final class Denormalization extends Deserialization
{
/**
* @var DenormalizerInterface
*/
public $denormalizer;

public function __construct(
DenormalizerInterface $denormalizer,
$data,
string $type,
string $format,
array $context = []
) {
parent::__construct($data, $type, $format, $context);
public function __construct(DenormalizerInterface $denormalizer, $data, $result, string $type, string $format, array $context = [])
{
parent::__construct($data, $result, $type, $format, $context);
$this->denormalizer = $denormalizer;
}
}
Expand Up @@ -16,14 +16,11 @@

final class Normalization extends Serialization
{
/**
* @var NormalizerInterface
*/
public $normalizer;

public function __construct(NormalizerInterface $normalizer, $data, string $format, array $context = [])
public function __construct(NormalizerInterface $normalizer, $data, $result, string $format, array $context = [])
{
parent::__construct($data, $format, $context);
parent::__construct($data, $result, $format, $context);
$this->normalizer = $normalizer;
}
}
13 changes: 4 additions & 9 deletions src/Symfony/Component/Serializer/Debug/SerializerAction.php
Expand Up @@ -14,25 +14,20 @@
abstract class SerializerAction
{
/**
* @var mixed
* @var object|string
*/
public $data;
/**
* @var string
*/
public $format;
/**
* @var array
*/
public $context;
/**
* @var mixed
* @var object|string
*/
public $result;

public function __construct($data, string $format, array $context = [])
public function __construct($data, $result, string $format, array $context = [])
{
$this->data = $data;
$this->result = $result;
$this->format = $format;
$this->context = $context;
}
Expand Down
14 changes: 6 additions & 8 deletions src/Symfony/Component/Serializer/Debug/TraceableSerializer.php
Expand Up @@ -37,20 +37,18 @@ public function __construct(SerializerInterface $delegate)

public function serialize($data, string $format, array $context = []): string
{
$serialization = new Serialization($data, $format, $context);
$serialization->result = $this->delegate->serialize($data, $format, $context);
$this->serializations[] = $serialization;
$result = $this->delegate->serialize($data, $format, $context);
$this->serializations[] = new Serialization($data, $result, $format, $context);

return $serialization->result;
return $result;
}

public function deserialize($data, string $type, string $format, array $context = [])
{
$deserialization = new Deserialization($data, $type, $format, $context);
$deserialization->result = $this->delegate->deserialize($data, $type, $format, $context);
$this->deserializations[] = $deserialization;
$result = $this->delegate->deserialize($data, $type, $format, $context);
$this->deserializations[] = new Deserialization($data, $result, $type, $format, $context);

return $deserialization->result;
return $result;
}

/**
Expand Down
Expand Up @@ -16,9 +16,6 @@

final class TestCacheableNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
{
/**
* @var bool
*/
private $cacheable;

public function __construct(bool $cacheable)
Expand Down
Expand Up @@ -15,9 +15,6 @@
use Symfony\Component\Serializer\Debug\TraceableSerializer;
use Symfony\Component\Serializer\SerializerInterface;

/**
* Class TraceableSerializerTest.
*/
final class TraceableSerializerTest extends TestCase
{
private const JSON = 'json';
Expand Down

0 comments on commit cba66e8

Please sign in to comment.