8000 chore: refacto (#13) · mtarld/symfony@e50356f · GitHub
[go: up one dir, main page]

Skip to content

Commit e50356f

Browse files
authored
chore: refacto (symfony#13)
1 parent cd58d55 commit e50356f

23 files changed

+184
-116
lines changed

Attribute/Warmable.php renamed to Attribute/Marshallable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
1414
*/
1515
#[\Attribute(\Attribute::TARGET_CLASS)]
16-
final class Warmable
16+
final class Marshallable
1717
{
1818
public function __construct(
1919
public readonly ?bool $nullable = null,

Cache/WarmableResolver.php renamed to Cache/MarshallableResolver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
namespace Symfony\Component\Marshaller\Cache;
1111

12-
use Symfony\Component\Marshaller\Attribute\Warmable;
12+
use Symfony\Component\Marshaller\Attribute\Marshallable;
1313

1414
/**
1515
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
1616
*/
17-
final class WarmableResolver
17+
final class MarshallableResolver
1818
{
1919
/**
2020
* @param list<string> $paths
@@ -25,20 +25,20 @@ public function __construct(
2525
}
2626

2727
/**
28-
* @return \Generator<class-string, Warmable>
28+
* @return \Generator<class-string, Marshallable>
2929
*/
3030
public function resolve(): \Generator
3131
{
3232
foreach ($this->fromPaths($this->paths) as $class) {
3333
$attributeInstance = null;
3434

3535
foreach ($class->getAttributes() as $attribute) {
36-
if (Warmable::class === $attribute->getName()) {
36+
if (Marshallable::class === $attribute->getName()) {
3737
$attributeInstance = $attribute->newInstance();
3838
}
3939
}
4040

41-
/** @var Warmable|null $attributeInstance */
41+
/** @var Marshallable|null $attributeInstance */
4242
if (null === $attributeInstance) {
4343
continue;
4444
}

Cache/TemplateCacheWarmer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Symfony\Component\Marshaller\Cache;
1111

1212
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
13-
use Symfony\Component\Marshaller\Attribute\Warmable;
13+
use Symfony\Component\Marshaller\Attribute\Marshallable;
1414
use Symfony\Component\Marshaller\MarshallerInterface;
1515

1616
/**
@@ -22,7 +22,7 @@ final class TemplateCacheWarmer implements CacheWarmerInterface
2222
* @param list<string> $formats
2323
*/
2424
public function __construct(
25-
private readonly WarmableResolver $warmableResolver,
25+
private readonly MarshallableResolver $marshallableResolver,
2626
private readonly MarshallerInterface $marshaller,
2727
private readonly string $cacheDir,
2828
private readonly array $formats,
@@ -32,7 +32,7 @@ public function __construct(
3232

3333
public function warmUp(string $cacheDir): array
3434
{
35-
foreach ($this->warmableResolver->resolve() as $class => $attribute) {
35+
foreach ($this->marshallableResolver->resolve() as $class => $attribute) {
3636
foreach ($this->formats as $format) {
3737
$this->warmClass($class, $attribute, $format);
3838
}
@@ -49,7 +49,7 @@ public function isOptional(): bool
4949
/**
5050
* @param class-string $class
5151
*/
52-
private function warmClass(string $class, Warmable $attribute, string $format): void
52+
private function warmClass(string $class, Marshallable $attribute, string $format): void
5353
{
5454
$path = sprintf('%s/%s.%s.php', $this->cacheDir, md5($class), $format);
5555
if (file_exists($path)) {

DependencyInjection/MarshallerExtension.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Symfony\Component\DependencyInjection\Parameter;
1515
use Symfony\Component\DependencyInjection\Reference;
1616
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
17+
use Symfony\Component\Marshaller\Cache\MarshallableResolver;
1718
use Symfony\Component\Marshaller\Cache\TemplateCacheWarmer;
18-
use Symfony\Component\Marshaller\Cache\WarmableResolver;
1919
use Symfony\Component\Marshaller\Context\ContextBuilder\Generation as GenerationContextBuilder;
2020
use Symfony\Component\Marshaller\Context\ContextBuilder\Marshal as MarshalContextBuilder;
2121
use Symfony\Component\Marshaller\Context\ContextBuilder\Unmarshal as UnmarshalContextBuilder;
@@ -107,18 +107,18 @@ public function load(array $configs, ContainerBuilder $container): void
107107
//
108108
// Cache
109109
//
110-
$container->register('.marshaller.cache.warmable_resolver', WarmableResolver::class)
110+
$container->register('.marshaller.cache.marshallable_resolver', MarshallableResolver::class)
111111
->setArguments([
112-
new Parameter('marshaller.warmable_paths'),
112+
new Parameter('marshaller.marshallable_paths'),
113113
]);
114114

115115
$container->register('.marshaller.cache.template_warmer', TemplateCacheWarmer::class)
116116
->setArguments([
117-
new Reference('.marshaller.cache.warmable_resolver'),
117+
new Reference('.marshaller.cache.marshallable_resolver'),
118118
new Reference('marshaller'),
119119
new Parameter('marshaller.cache_dir'),
120-
new Parameter('marshaller.warmable_formats'),
121-
new Parameter('marshaller.warmable_nullable_data'),
120+
new Parameter('marshaller.marshallable_formats'),
121+
new Parameter('marshaller.marshallable_nullable_data'),
122122
])
123123
->addTag('kernel.cache_warmer');
124124
}

Exception/InvalidConstructorArgumentException.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,4 @@ public function __construct(string $parameter, string $className)
1818
{
1919
parent::__construct(sprintf('Parameter "%s" of "%s" constructor must either have a default value or be nullable.', $parameter, $className));
2020
}
21-
22-
/**
23-
* @param \ReflectionClass<object> $class
24-
*/
25-
public static function createForReflectors(\ReflectionParameter $parameter, \ReflectionClass $class): self
26-
{
27-
return new self($parameter->getName(), $class->getName());
28-
}
2921
}

Exception/InvalidTypeException.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@
1414
*/
1515
final class InvalidTypeException extends InvalidArgumentException
1616
{
17-
public function __construct(string $type, string $cause = null)
17+
public function __construct(string $type)
1818
{
19-
$message = sprintf('Invalid "%s" type', $type);
20-
21-
if (null !== $cause) {
22-
$message .= ': '.$cause;
23-
}
24-
25-
parent::__construct($message.'.');
19+
parent::__construct(sprintf('Invalid "%s" type.', $type));
2620
}
2721
}

Internal/Parser/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private function instantiateObject(\ReflectionClass $class, array $context): obj
197197
continue;
198198
}
199199

200-
$exception = InvalidConstructorArgumentException::createForReflectors($parameter, $class);
200+
$exception = new InvalidConstructorArgumentException($parameter->getName(), $class->getName());
201201
if (!($context['collect_errors'] ?? false)) {
202202
throw $exception;
203203
}

Marshaller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function marshal(mixed $data, string $format, StreamInterface $output, Co
4949
$rawContext = $this->buildGenerationContext($type, $context, $rawContext);
5050
}
5151

52-
marshal($data, $output->stream(), $format, $rawContext);
52+
marshal($data, $output->resource(), $format, $rawContext);
5353
}
5454

5555
public function generate(string $type, string $format, Context $context = null): string
@@ -59,7 +59,7 @@ public function generate(string $type, string $format, Context $context = null):
5959

6060
public function unmarshal(StreamInterface $input, string $type, string $format, Context $context = null): mixed
6161
{
62-
return unmarshal($input->stream(), $type, $format, $this->buildUnmarshalContext($type, $context));
62+
return unmarshal($input->resource(), $type, $format, $this->buildUnmarshalContext($type, $context));
6363
}
6464

6565
/**

MarshallerInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Symfony\Component\Marshaller;
1111

1212
use Symfony\Component\Marshaller\Context\Context;
13+
use Symfony\Component\Marshaller\Exception\PartialUnmarshalException;
1314
use Symfony\Component\Marshaller\Stream\StreamInterface;
1415

1516
/**
@@ -21,5 +22,8 @@ public function marshal(mixed $data, string $format, StreamInterface $output, Co
2122

2223
public function generate(string $type, string $format, Context $context = null): string;
2324

25+
/**
26+
* @throws PartialUnmarshalException
27+
*/
2428
public function unmarshal(StreamInterface $input, string $type, string $format, Context $context = null): mixed;
2529
}

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# TODO
22

3-
## Marshal
4-
- Better name for warmable
5-
63
## Unmarshal
74
- bench in CI
85

96
## Common
10-
- test exception messages
117
- determine which services are internal
128
- determine which classes are internal
139

0 commit comments

Comments
 (0)
0