Skip to content

Commit

Permalink
minor #52159 [Serializer] Replace "annotation" wording by "attribute"…
Browse files Browse the repository at this point in the history
… (nicolas-grekas)

This PR was merged into the 6.4 branch.

Discussion
----------

[Serializer] Replace "annotation" wording by "attribute"

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT

Commits
-------

8cdac69 [Serializer] Replace "annotation" wording by "attribute"
  • Loading branch information
nicolas-grekas committed Oct 19, 2023
2 parents 7402279 + 8cdac69 commit 2f247cf
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ public function setRouteAnnotationClass(string $class)
}

/**
* Loads from annotations from a class.
*
* @throws \InvalidArgumentException When route can't be parsed
*/
public function load(mixed $class, string $type = null): RouteCollection
Expand All @@ -121,7 +119,7 @@ public function load(mixed $class, string $type = null): RouteCollection

$class = new \ReflectionClass($class);
if ($class->isAbstract()) {
throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class->getName()));
throw new \InvalidArgumentException(sprintf('Attributes from class "%s" cannot be read as it is abstract.', $class->getName()));
}

$this->hasDeprecatedAnnotations = false;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Routing/Loader/AttributeFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AttributeFileLoader extends FileLoader
public function __construct(FileLocatorInterface $locator, AttributeClassLoader $loader)
{
if (!\function_exists('token_get_all')) {
throw new \LogicException('The Tokenizer extension is required for the routing annotation loaders.');
throw new \LogicException('The Tokenizer extension is required for the routing attribute loader.');
}

parent::__construct($locator);
Expand All @@ -39,7 +39,7 @@ public function __construct(FileLocatorInterface $locator, AttributeClassLoader
}

/**
* Loads from annotations from a file.
* Loads from attributes from a file.
*
* @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Serializer/Annotation/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public function __construct(
string|array $groups = [],
) {
if (!$context && !$normalizationContext && !$denormalizationContext) {
throw new InvalidArgumentException(sprintf('At least one of the "context", "normalizationContext", or "denormalizationContext" options of annotation "%s" must be provided as a non-empty array.', static::class));
throw new InvalidArgumentException(sprintf('At least one of the "context", "normalizationContext", or "denormalizationContext" options must be provided as a non-empty array to "%s".', static::class));
}

$this->groups = (array) $groups;

foreach ($this->groups as $group) {
if (!\is_string($group)) {
throw new InvalidArgumentException(sprintf('Parameter "groups" of annotation "%s" must be a string or an array of strings. Got "%s".', static::class, get_debug_type($group)));
throw new InvalidArgumentException(sprintf('Parameter "groups" given to "%s" must be a string or an array of strings, "%s" given.', static::class, get_debug_type($group)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function __construct(
private readonly array $mapping,
) {
if (empty($typeProperty)) {
throw new InvalidArgumentException(sprintf('Parameter "typeProperty" of annotation "%s" cannot be empty.', static::class));
throw new InvalidArgumentException(sprintf('Parameter "typeProperty" given to "%s" cannot be empty.', static::class));
}

if (empty($mapping)) {
throw new InvalidArgumentException(sprintf('Parameter "mapping" of annotation "%s" cannot be empty.', static::class));
throw new InvalidArgumentException(sprintf('Parameter "mapping" given to "%s" cannot be empty.', static::class));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Serializer/Annotation/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public function __construct(string|array $groups)
$this->groups = (array) $groups;

if (!$this->groups) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', static::class));
throw new InvalidArgumentException(sprintf('Parameter given to "%s" cannot be empty.', static::class));
}

foreach ($this->groups as $group) {
if (!\is_string($group) || '' === $group) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of non-empty strings.', static::class));
throw new InvalidArgumentException(sprintf('Parameter given to "%s" must be a string or an array of non-empty strings.', static::class));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/Annotation/MaxDepth.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MaxDepth
public function __construct(private readonly int $maxDepth)
{
if ($maxDepth <= 0) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a positive integer.', static::class));
throw new InvalidArgumentException(sprintf('Parameter given to "%s" must be a positive integer.', static::class));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class SerializedName
public function __construct(private readonly string $serializedName)
{
if ('' === $serializedName) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a non-empty string.', self::class));
throw new InvalidArgumentException(sprintf('Parameter given to "%s" must be a non-empty string.', self::class));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(string $serializedPath)
try {
$this->serializedPath = new PropertyPath($serializedPath);
} catch (InvalidPropertyPathException $pathException) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a valid property path.', self::class));
throw new InvalidArgumentException(sprintf('Parameter given to "%s" must be a valid property path.', self::class));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private function getCacheValueForNormalization(string $propertyName, string $cla
}

if (null !== $attributesMetadata[$propertyName]->getSerializedName() && null !== $attributesMetadata[$propertyName]->getSerializedPath()) {
throw new LogicException(sprintf('Found SerializedName and SerializedPath annotations on property "%s" of class "%s".', $propertyName, $class));
throw new LogicException(sprintf('Found SerializedName and SerializedPath attributes on property "%s" of class "%s".', $propertyName, $class));
}

return $attributesMetadata[$propertyName]->getSerializedName() ?? null;
Expand Down Expand Up @@ -124,7 +124,7 @@ private function getCacheValueForAttributesMetadata(string $class, array $contex
}

if (null !== $metadata->getSerializedName() && null !== $metadata->getSerializedPath()) {
throw new LogicException(sprintf('Found SerializedName and SerializedPath annotations on property "%s" of class "%s".', $name, $class));
throw new LogicException(sprintf('Found SerializedName and SerializedPath attributes on property "%s" of class "%s".', $name, $class));
}

$metadataGroups = $metadata->getGroups();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
$notConverted = $attribute;
$attribute = $this->nameConverter->denormalize($attribute, $resolvedClass, $format, $context);
if (isset($nestedData[$notConverted]) && !isset($originalNestedData[$attribute])) {
throw new LogicException(sprintf('Duplicate values for key "%s" found. One value is set via the SerializedPath annotation: "%s", the other one is set via the SerializedName annotation: "%s".', $notConverted, implode('->', $nestedAttributes[$notConverted]->getElements()), $attribute));
throw new LogicException(sprintf('Duplicate values for key "%s" found. One value is set via the SerializedPath attribute: "%s", the other one is set via the SerializedName attribute: "%s".', $notConverted, implode('->', $nestedAttributes[$notConverted]->getElements()), $attribute));
}
}

Expand Down Expand Up @@ -756,7 +756,7 @@ private function isUninitializedValueError(\Error $e): bool
}

/**
* Returns all attributes with a SerializedPath annotation and the respective path.
* Returns all attributes with a SerializedPath attribute and the respective path.
*/
private function getNestedAttributes(string $class): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ protected function setUp(): void
public function testThrowsOnEmptyContext()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('At least one of the "context", "normalizationContext", or "denormalizationContext" options of annotation "Symfony\Component\Serializer\Annotation\Context" must be provided as a non-empty array.');
$this->expectExceptionMessage('At least one of the "context", "normalizationContext", or "denormalizationContext" options must be provided as a non-empty array to "Symfony\Component\Serializer\Annotation\Context".');

new Context();
}

public function testInvalidGroupOption()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf('Parameter "groups" of annotation "%s" must be a string or an array of strings. Got "stdClass"', Context::class));
$this->expectExceptionMessage(sprintf('Parameter "groups" given to "%s" must be a string or an array of strings, "stdClass" given', Context::class));

new Context(context: ['foo' => 'bar'], groups: ['fine', new \stdClass()]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MaxDepthTest extends TestCase
public function testNotAnIntMaxDepthParameter(int $value)
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\MaxDepth" must be a positive integer.');
$this->expectExceptionMessage('Parameter given to "Symfony\Component\Serializer\Annotation\MaxDepth" must be a positive integer.');
new MaxDepth($value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SerializedNameTest extends TestCase
public function testNotAStringSerializedNameParameter()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\SerializedName" must be a non-empty string.');
$this->expectExceptionMessage('Parameter given to "Symfony\Component\Serializer\Annotation\SerializedName" must be a non-empty string.');

new SerializedName('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SerializedPathTest extends TestCase
public function testEmptyStringSerializedPathParameter()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Parameter of annotation "Symfony\Component\Serializer\Annotation\SerializedPath" must be a valid property path.');
$this->expectExceptionMessage('Parameter given to "Symfony\Component\Serializer\Annotation\SerializedPath" must be a valid property path.');

new SerializedPath('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function testDenormalizeWithNestedPathAndName()
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$nameConverter = new MetadataAwareNameConverter($classMetadataFactory);
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Found SerializedName and SerializedPath annotations on property "foo" of class "Symfony\Component\Serializer\Tests\NameConverter\NestedPathAndName".');
$this->expectExceptionMessage('Found SerializedName and SerializedPath attributes on property "foo" of class "Symfony\Component\Serializer\Tests\NameConverter\NestedPathAndName".');
$nameConverter->denormalize('foo', NestedPathAndName::class);
}

Expand All @@ -177,7 +177,7 @@ public function testNormalizeWithNestedPathAndName()
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$nameConverter = new MetadataAwareNameConverter($classMetadataFactory);
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Found SerializedName and SerializedPath annotations on property "foo" of class "Symfony\Component\Serializer\Tests\NameConverter\NestedPathAndName".');
$this->expectExceptionMessage('Found SerializedName and SerializedPath attributes on property "foo" of class "Symfony\Component\Serializer\Tests\NameConverter\NestedPathAndName".');
$nameConverter->normalize('foo', NestedPathAndName::class);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function testDenormalizeWithNestedAttributes()
public function testDenormalizeWithNestedAttributesDuplicateKeys()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Duplicate values for key "quux" found. One value is set via the SerializedPath annotation: "one->four", the other one is set via the SerializedName annotation: "notquux".');
$this->expectExceptionMessage('Duplicate values for key "quux" found. One value is set via the SerializedPath attribute: "one->four", the other one is set via the SerializedName attribute: "notquux".');
$normalizer = new AbstractObjectNormalizerWithMetadata();
$data = [
'one' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class GroupSequence
*/
public function __construct(array $groups)
{
// Support for Doctrine annotations
$this->groups = $groups['value'] ?? $groups;
}
}

0 comments on commit 2f247cf

Please sign in to comment.