Skip to content

Commit

Permalink
fix coding standards issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ixarlie committed Jan 31, 2023
1 parent e13be25 commit ac5771e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 40 deletions.
6 changes: 5 additions & 1 deletion src/Configuration/Annotation/Embedded.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class Embedded
*/
public $exclusion = null;

public function __construct($values = [], $content = null, ?string $type = null, $xmlElementName = null, $exclusion = null)
/**
* @param string|array $content
* @param Exclusion|null $exclusion
*/
public function __construct(array $values = [], $content = null, ?string $type = null, ?string $xmlElementName = null, $exclusion = null)
{
$this->loadAnnotationParameters(get_defined_vars());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Annotation/Exclusion.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class Exclusion
*/
public $excludeIf = null;

public function __construct($values = [], ?array $groups = null, ?string $sinceVersion = null, ?string $untilVersion = null, ?int $maxDepth = null, ?string $excludeIf = null)
public function __construct(array $values = [], ?array $groups = null, ?string $sinceVersion = null, ?string $untilVersion = null, ?int $maxDepth = null, ?string $excludeIf = null)
{
$this->loadAnnotationParameters(get_defined_vars());
}
Expand Down
6 changes: 5 additions & 1 deletion src/Configuration/Annotation/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ final class Relation
*/
public $exclusion = null;

public function __construct($values = [], ?string $name = null, $href = null, $embedded = null, array $attributes = [], ?Exclusion $exclusion = null)
/**
* @param string|Route $href
* @param string|Embedded $embedded
*/
public function __construct(array $values = [], ?string $name = null, $href = null, $embedded = null, array $attributes = [], ?Exclusion $exclusion = null)
{
$this->loadAnnotationParameters(get_defined_vars());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Annotation/RelationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RelationProvider
*/
public $name;

public function __construct($values = [], ?string $name = null)
public function __construct(array $values = [], ?string $name = null)
{
$this->loadAnnotationParameters(get_defined_vars());
}
Expand Down
6 changes: 5 additions & 1 deletion src/Configuration/Annotation/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class Route
*/
public $generator = null;

public function __construct($values = [], ?string $name = null, $parameters = null, $absolute = false, ?string $generator = null)
/**
* @param array|string $parameters
* @param bool|string $absolute
*/
public function __construct(array $values = [], ?string $name = null, $parameters = null, $absolute = false, ?string $generator = null)
{
$this->loadAnnotationParameters(get_defined_vars());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,59 @@ public function __construct(Reader $reader)
$this->reader = $reader;
}

/**
* {@inheritDoc}
*/
public function getClassAnnotations(ReflectionClass $class): array
{
$attributes = $class->getAttributes();

return array_merge($this->reader->getClassAnnotations($class), $this->buildAnnotations($attributes));
}

/**
* {@inheritDoc}
*/
public function getClassAnnotation(ReflectionClass $class, $annotationName): ?object
{
$attributes = $class->getAttributes($annotationName);

return $this->reader->getClassAnnotation($class, $annotationName) ?? $this->buildAnnotation($attributes);
}

/**
* {@inheritDoc}
*/
public function getMethodAnnotations(ReflectionMethod $method): array
{
$attributes = $method->getAttributes();

return array_merge($this->reader->getMethodAnnotations($method), $this->buildAnnotations($attributes));
}

/**
* {@inheritDoc}
*/
public function getMethodAnnotation(ReflectionMethod $method, $annotationName): ?object
{
$attributes = $method->getAttributes($annotationName);

return $this->reader->getMethodAnnotation($method, $annotationName) ?? $this->buildAnnotation($attributes);
}

/**
* {@inheritDoc}
*/
public function getPropertyAnnotations(ReflectionProperty $property): array
{
$attributes = $property->getAttributes();

return array_merge($this->reader->getPropertyAnnotations($property), $this->buildAnnotations($attributes));
}

/**
* {@inheritDoc}
*/
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName): ?object
{
$attributes = $property->getAttributes($annotationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function testGetClassAnnotations()
->expects($this->once())
->method('getClassAnnotations')
->with($refl)
->willReturn([])
;
->willReturn([]);

$result = $reader->getClassAnnotations($refl);

Expand All @@ -50,8 +49,7 @@ public function testGetClassAnnotationsDelegated()
->expects($this->once())
->method('getClassAnnotations')
->with($refl)
->willReturn([$annotation])
;
->willReturn([$annotation]);

$result = $reader->getClassAnnotations($refl);

Expand All @@ -68,8 +66,7 @@ public function testGetClassAnnotation()
->expects($this->once())
->method('getClassAnnotation')
->with($refl, Annotation\RelationProvider::class)
->willReturn(null)
;
->willReturn(null);

$result = $reader->getClassAnnotation($refl, Annotation\RelationProvider::class);

Expand All @@ -87,8 +84,7 @@ public function testGetClassAnnotationDelegated()
->expects($this->once())
->method('getClassAnnotation')
->with($refl, Annotation\RelationProvider::class)
->willReturn($annotation)
;
->willReturn($annotation);

$result = $reader->getClassAnnotation($refl, Annotation\RelationProvider::class);

Expand All @@ -105,8 +101,7 @@ public function testGetMethodAnnotations()
->expects($this->once())
->method('getMethodAnnotations')
->with($refl)
->willReturn([])
;
->willReturn([]);

$result = $reader->getMethodAnnotations($refl);

Expand All @@ -124,8 +119,7 @@ public function testGetMethodAnnotationsDelegated()
->expects($this->once())
->method('getMethodAnnotations')
->with($refl)
->willReturn([$annotation])
;
->willReturn([$annotation]);

$result = $reader->getMethodAnnotations($refl);

Expand All @@ -142,8 +136,7 @@ public function testGetMethodAnnotation()
->expects($this->once())
->method('getMethodAnnotation')
->with($refl, Annotation\RelationProvider::class)
->willReturn(null)
;
->willReturn(null);

$result = $reader->getMethodAnnotation($refl, Annotation\RelationProvider::class);

Expand All @@ -161,8 +154,7 @@ public function testGetMethodAnnotationDelegated()
->expects($this->once())
->method('getMethodAnnotation')
->with($refl, Annotation\RelationProvider::class)
->willReturn($annotation)
;
->willReturn($annotation);

$result = $reader->getMethodAnnotation($refl, Annotation\RelationProvider::class);

Expand All @@ -179,8 +171,7 @@ public function testGetPropertyAnnotations()
->expects($this->once())
->method('getPropertyAnnotations')
->with($refl)
->willReturn([])
;
->willReturn([]);

$result = $reader->getPropertyAnnotations($refl);

Expand All @@ -198,8 +189,7 @@ public function testGetPropertyAnnotationsDelegated()
->expects($this->once())
->method('getPropertyAnnotations')
->with($refl)
->willReturn([$annotation])
;
->willReturn([$annotation]);

$result = $reader->getPropertyAnnotations($refl);

Expand All @@ -216,8 +206,7 @@ public function testGetPropertyAnnotation()
->expects($this->once())
->method('getPropertyAnnotation')
->with($refl, Annotation\RelationProvider::class)
->willReturn(null)
;
->willReturn(null);

$result = $reader->getPropertyAnnotation($refl, Annotation\RelationProvider::class);

Expand All @@ -235,8 +224,7 @@ public function testGetPropertyAnnotationDelegated()
->expects($this->once())
->method('getPropertyAnnotation')
->with($refl, Annotation\RelationProvider::class)
->willReturn($annotation)
;
->willReturn($annotation);

$result = $reader->getPropertyAnnotation($refl, Annotation\RelationProvider::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function createDriver()
$driver
->expects($this->once())
->method('getClassAnnotations')
->willReturn([])
;
->willReturn([]);

return new AnnotationDriver(
new AttributeReader($driver),
Expand Down
18 changes: 9 additions & 9 deletions tests/Hateoas/Tests/Fixtures/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
* @Hateoas\Relation("attribute_with_expression", href = "baz", attributes = {"baz" = "expr(object.getId())"})
* @Hateoas\RelationProvider("Hateoas\Tests\Fixtures\User::getRelations")
*/
#[Hateoas\Relation(name: "self", href: "http://hateoas.web/user/42", attributes: ["type" => "application/json"])]
#[Hateoas\Relation(name: "foo", href: new Hateoas\Route(name: "user_get", parameters: ["id" => "expr(object.getId())"]), embedded: "expr(object.getFoo())")]
#[Hateoas\Relation(name: "bar", href: "foo", embedded: new Hateoas\Embedded(content: "data", xmlElementName: "barTag"))]
#[Hateoas\Relation(name: "baz", href: new Hateoas\Route(name: "user_get", parameters: ["id" => "expr(object.getId())"], absolute: true), embedded: "expr(object.getFoo())")]
#[Hateoas\Relation(name: "boom", href: new Hateoas\Route(name: "user_get", parameters: ["id" => "expr(object.getId())"], absolute: false), embedded: "expr(object.getFoo())")]
#[Hateoas\Relation(name: "badaboom", embedded: "expr(object.getFoo())")]
#[Hateoas\Relation(name: "hello", href: "/hello", embedded: new Hateoas\Embedded(content: "hello", type: "string", xmlElementName: "barTag", exclusion: new Hateoas\Exclusion(groups: ["group3", "group4"], sinceVersion: "1.1", untilVersion: "2.3", maxDepth: 43, excludeIf: "bar")), exclusion: new Hateoas\Exclusion(groups: ["group1", "group2"], sinceVersion: "1", untilVersion: "2.2", maxDepth: 42, excludeIf: "foo"))]
#[Hateoas\Relation(name: "attribute_with_expression", href: "baz", attributes: ["baz" => "expr(object.getId())"])]
#[Hateoas\RelationProvider(name: "Hateoas\Tests\Fixtures\User::getRelations")]
#[Hateoas\Relation(name: 'self', href: 'http://hateoas.web/user/42', attributes: ['type' => 'application/json'])]
#[Hateoas\Relation(name: 'foo', href: new Hateoas\Route(name: 'user_get', parameters: ['id' => 'expr(object.getId())']), embedded: 'expr(object.getFoo())')]
#[Hateoas\Relation(name: 'bar', href: 'foo', embedded: new Hateoas\Embedded(content: 'data', xmlElementName: 'barTag'))]
#[Hateoas\Relation(name: 'baz', href: new Hateoas\Route(name: 'user_get', parameters: ['id' => 'expr(object.getId())'], absolute: true), embedded: 'expr(object.getFoo())')]
#[Hateoas\Relation(name: 'boom', href: new Hateoas\Route(name: 'user_get', parameters: ['id' => 'expr(object.getId())'], absolute: false), embedded: 'expr(object.getFoo())')]
#[Hateoas\Relation(name: 'badaboom', embedded: 'expr(object.getFoo())')]
#[Hateoas\Relation(name: 'hello', href: '/hello', embedded: new Hateoas\Embedded(content: 'hello', type: 'string', xmlElementName: 'barTag', exclusion: new Hateoas\Exclusion(groups: ['group3', 'group4'], sinceVersion: '1.1', untilVersion: '2.3', maxDepth: 43, excludeIf: 'bar')), exclusion: new Hateoas\Exclusion(groups: ['group1', 'group2'], sinceVersion: '1', untilVersion: '2.2', maxDepth: 42, excludeIf: 'foo'))]
#[Hateoas\Relation(name: 'attribute_with_expression', href: 'baz', attributes: ['baz' => 'expr(object.getId())'])]
#[Hateoas\RelationProvider(name: 'Hateoas\Tests\Fixtures\User::getRelations')]
class User
{
/**
Expand Down

0 comments on commit ac5771e

Please sign in to comment.