Skip to content

Commit

Permalink
fix: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
fogrye committed Apr 8, 2024
1 parent 6646743 commit 2d5ce22
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
24 changes: 11 additions & 13 deletions src/AnnotationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class AnnotationReader
/** @var array<string, array<object>> */
private array $propertyAnnotationsCache = [];

public function __construct()
{
}

/**
* Returns a class annotation. Does not look in the parent class.
*
Expand All @@ -63,13 +59,12 @@ public function __construct()
private function getClassAnnotation(ReflectionClass $refClass, string $annotationClass): object|null
{
$attribute = $refClass->getAttributes($annotationClass)[0] ?? null;
if ($attribute) {
$instance = $attribute->newInstance();
assert($instance instanceof $annotationClass);
return $instance;
if (! $attribute) {
return null;
}

return null;
$instance = $attribute->newInstance();
assert($instance instanceof $annotationClass);
return $instance;
}

/**
Expand All @@ -85,11 +80,14 @@ private function getMethodAnnotation(ReflectionMethod $refMethod, string $annota
}

$attribute = $refMethod->getAttributes($annotationClass)[0] ?? null;
if ($attribute) {
return $this->methodAnnotationCache[$cacheKey] = $attribute->newInstance();
if (! $attribute) {
$this->methodAnnotationCache[$cacheKey] = null;

return null;
}
$this->methodAnnotationCache[$cacheKey] = $attribute->newInstance();

return $this->methodAnnotationCache[$cacheKey] = null;
return $this->methodAnnotationCache[$cacheKey];
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Annotations/InjectUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
#[Attribute(Attribute::TARGET_PARAMETER)]
class InjectUser implements ParameterAnnotationInterface
{
/** @var string */
private $for;
private string|null $for = null;

/** @param array<string, mixed> $values */
public function __construct(array|null $values = [])
public function __construct(array $values = [])
{
if (! isset($values['for'])) {
return;
Expand Down
8 changes: 4 additions & 4 deletions src/FieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1152,10 +1152,10 @@ private function getInputFieldsByPropertyAnnotations(
assert($type instanceof InputType);
$forConstructorHydration = in_array($name, $constructerParameters);
$resolver = $forConstructorHydration
? new SourceConstructorParameterResolver(
$refProperty->getDeclaringClass()->getName(),
$refProperty->getName(),
)
? new SourceConstructorParameterResolver(
$refProperty->getDeclaringClass()->getName(),
$refProperty->getName(),
)
: new SourceInputPropertyResolver($refProperty);

// setters and properties
Expand Down

0 comments on commit 2d5ce22

Please sign in to comment.