Skip to content

Commit

Permalink
Use attributes everywhere instead of annotations (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil authored Dec 8, 2023
1 parent e18b0c0 commit f5b82c7
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 61 deletions.
12 changes: 5 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,23 @@
"php": "^8.2",
"doctrine/inflector": "^1.4 || ^2.0",
"nikic/php-parser": "^4.0",
"symfony/property-info": "^5.3 || ^6.0",
"symfony/serializer": "^5.1 || ^6.0"
"symfony/property-info": "^5.4 || ^6.0",
"symfony/serializer": "^5.4 || ^6.0"
},
"require-dev": {
"doctrine/annotations": "~1.0",
"moneyphp/money": "^3.0",
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0",
"phpunit/phpunit": "^8.0",
"symfony/filesystem": "^5.3 || ^6.0",
"symfony/http-kernel": "^5.3 || ^6.0",
"symfony/uid": "^5.2 || ^6.0"
"symfony/filesystem": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/uid": "^5.4 || ^6.0"
},
"suggest": {
"doctrine/annotations": "Docblock Annotations Parser",
"phpdocumentor/reflection-docblock": "Allow to extract informations from PHP Doc blocks"
},
"conflict": {
"symfony/serializer": "<4.2",
"symfony/property-info": "5.1.6 || 5.1.7",
"nikic/php-parser": "<4.0.4"
},
"autoload": {
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class Bar
{
/**
* @var int|null
*
* @Groups({"group2", "group3"})
*/
#[Groups(['group2', 'group3'])]
private $id;

public function getId(): ?int
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/Foo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class Foo
{
/**
* @var int
*
* @Groups({"group1", "group2", "group3"})
*/
#[Groups(['group1', 'group2', 'group3'])]
private $id = 0;

public function getId(): int
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/FooIgnore.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class FooIgnore
{
/**
* @var int
*
* @Ignore
*/
#[Ignore]
public $id;

public function getId(): int
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/FooMaxDepth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class FooMaxDepth

/**
* @var FooMaxDepth|null
*
* @MaxDepth(2)
*/
#[MaxDepth(2)]
private $child;

public function __construct(int $id, ?self $child = null)
Expand Down
12 changes: 5 additions & 7 deletions tests/Fixtures/Pet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

use Symfony\Component\Serializer\Annotation\DiscriminatorMap;

/**
* @DiscriminatorMap(typeProperty="type", mapping={
* "cat"="AutoMapper\Tests\Fixtures\Cat",
* "dog"="AutoMapper\Tests\Fixtures\Dog",
* "fish"="AutoMapper\Tests\Fixtures\Fish"
* })
*/
#[DiscriminatorMap(typeProperty: 'type', mapping: [
'cat' => Cat::class,
'dog' => Dog::class,
'fish' => Fish::class,
])]
abstract class Pet
{
/** @var string */
Expand Down
9 changes: 0 additions & 9 deletions tests/Fixtures/Transformer/ArrayToMoneyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
*/
final class ArrayToMoneyTransformer implements TransformerInterface
{
/**
* {@inheritdoc}
*/
public function transform(Expr $input, Expr $target, PropertyMapping $propertyMapping, UniqueVariableScope $uniqueVariableScope): array
{
return [new Expr\New_(new Name\FullyQualified(Money::class), [
Expand All @@ -34,17 +31,11 @@ public function transform(Expr $input, Expr $target, PropertyMapping $propertyMa
]), []];
}

/**
* {@inheritdoc}
*/
public function getDependencies(): array
{
return [];
}

/**
* {@inheritdoc}
*/
public function assignByRef(): bool
{
return false;
Expand Down
9 changes: 0 additions & 9 deletions tests/Fixtures/Transformer/MoneyToArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
final class MoneyToArrayTransformer implements TransformerInterface
{
/**
* {@inheritdoc}
*/
public function transform(Expr $input, Expr $target, PropertyMapping $propertyMapping, UniqueVariableScope $uniqueVariableScope): array
{
$moneyVar = new Expr\Variable($uniqueVariableScope->getUniqueName('money'));
Expand All @@ -31,17 +28,11 @@ public function transform(Expr $input, Expr $target, PropertyMapping $propertyMa
]];
}

/**
* {@inheritdoc}
*/
public function getDependencies(): array
{
return [];
}

/**
* {@inheritdoc}
*/
public function assignByRef(): bool
{
return false;
Expand Down
9 changes: 0 additions & 9 deletions tests/Fixtures/Transformer/MoneyToMoneyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
*/
final class MoneyToMoneyTransformer implements TransformerInterface
{
/**
* {@inheritdoc}
*/
public function transform(Expr $input, Expr $target, PropertyMapping $propertyMapping, UniqueVariableScope $uniqueVariableScope): array
{
return [
Expand All @@ -36,17 +33,11 @@ public function transform(Expr $input, Expr $target, PropertyMapping $propertyMa
];
}

/**
* {@inheritdoc}
*/
public function getDependencies(): array
{
return [];
}

/**
* {@inheritdoc}
*/
public function assignByRef(): bool
{
return false;
Expand Down
3 changes: 0 additions & 3 deletions tests/Fixtures/Transformer/MoneyTransformerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
final class MoneyTransformerFactory extends AbstractUniqueTypeTransformerFactory
{
/**
* {@inheritdoc}
*/
protected function createTransformer(Type $sourceType, Type $targetType, MapperMetadataInterface $mapperMetadata): ?TransformerInterface
{
$isSourceMoney = $this->isMoneyType($sourceType);
Expand Down
13 changes: 4 additions & 9 deletions tests/Fixtures/UserWithYearOfBirth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@
class UserWithYearOfBirth
{
/**
* @Groups({"read"})
*
* @var int
*/
#[Groups('read')]
private $id;

/**
* @Groups({"read"})
*
* @var string
*/
#[Groups('read')]
public $name;

/**
* @Groups({"read"})
*
* @var string|int
*/
#[Groups('read')]
public $age;

public function __construct($id, $name, $age)
Expand All @@ -36,9 +33,7 @@ public function __construct($id, $name, $age)
$this->age = $age;
}

/**
* @Groups({"read"})
*/
#[Groups('read')]
public function getYearOfBirth()
{
return ((int) date('Y')) - ((int) $this->age);
Expand Down

0 comments on commit f5b82c7

Please sign in to comment.