Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/Bootstrap.php" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
bootstrap="tests/Bootstrap.php"

cacheDirectory=".phpunit.cache"
cacheResult="true"

backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
backupStaticProperties="false"
>
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
</report>
</coverage>

<testsuites>
<testsuite name="GraphQLite Test Suite">
<directory>./tests/</directory>
<exclude>./tests/Bootstrap.php</exclude>
</testsuite>
</testsuites>

<logging/>

<source>
<include>
<directory suffix=".php">src/</directory>
Expand Down
7 changes: 2 additions & 5 deletions src/Annotations/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
#[Attribute(Attribute::TARGET_CLASS)]
class EnumType
{
/** @var string|null */
private $name;

/** @var bool */
private $useValues;
private string|null $name;
private bool $useValues;

/** @param mixed[] $attributes */
public function __construct(array $attributes = [], string|null $name = null, bool|null $useValues = null)
Expand Down
12 changes: 7 additions & 5 deletions src/Annotations/ExtendType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
class ExtendType
{
/** @var class-string<object>|null */
private $class;
/** @var string|null */
private $name;
private string|null $class;
private string|null $name;

/** @param mixed[] $attributes */
public function __construct(array $attributes = [], string|null $class = null, string|null $name = null)
{
public function __construct(
array $attributes = [],
string|null $class = null,
string|null $name = null,
) {
$className = isset($attributes['class']) ? ltrim($attributes['class'], '\\') : null;
$className = $className ?? $class;
if ($className !== null && ! class_exists($className) && ! interface_exists($className)) {
Expand Down
6 changes: 2 additions & 4 deletions src/Annotations/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
#[Attribute(Attribute::TARGET_METHOD)]
class Factory
{
/** @var string|null */
private $name;
/** @var bool */
private $default;
private string|null $name;
private bool $default;

/** @param mixed[] $attributes */
public function __construct(array $attributes = [], string|null $name = null, bool|null $default = null)
Expand Down
4 changes: 1 addition & 3 deletions src/Annotations/FailWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ class FailWith implements MiddlewareAnnotationInterface
{
/**
* The default value to use if the right is not enforced.
*
* @var mixed
*/
private $value;
private mixed $value;

/** @throws BadMethodCallException */
public function __construct(mixed $values = [], mixed $value = '__fail__with__magic__key__')
Expand Down
23 changes: 13 additions & 10 deletions src/Annotations/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,31 @@
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Field extends AbstractRequest
{
/** @var string|null */
private $prefetchMethod;
private string|null $prefetchMethod;

/**
* Input/Output type names for which this fields should be applied to.
*
* @var string[]|null
*/
private $for = null;
private array|null $for = null;

/** @var string|null */
private $description;

/** @var string|null */
private $inputType;
private string|null $description;
private string|null $inputType;

/**
* @param mixed[] $attributes
* @param string|string[] $for
*/
public function __construct(array $attributes = [], string|null $name = null, string|null $outputType = null, string|null $prefetchMethod = null, string|array|null $for = null, string|null $description = null, string|null $inputType = null)
{
public function __construct(
array $attributes = [],
string|null $name = null,
string|null $outputType = null,
string|null $prefetchMethod = null,
string|array|null $for = null,
string|null $description = null,
string|null $inputType = null,
) {
parent::__construct($attributes, $name, $outputType);

$this->prefetchMethod = $prefetchMethod ?? $attributes['prefetchMethod'] ?? null;
Expand Down
71 changes: 44 additions & 27 deletions src/Annotations/MagicField.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,56 @@
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class MagicField implements SourceFieldInterface
{
/** @var string */
private $name;
private string $name;
private string|null $outputType;
private string|null $phpType;
private string|null $description;
private string|null $sourceName;

/** @var string|null */
private $outputType;

/** @var string|null */
private $phpType;

/** @var string|null */
private $description;

/** @var string|null */
private $sourceName;

/** @var MiddlewareAnnotations */
private $middlewareAnnotations;
private MiddlewareAnnotations $middlewareAnnotations;

/** @var array<string, ParameterAnnotations> */
private $parameterAnnotations;
private array $parameterAnnotations;

/**
* @param mixed[] $attributes
* @param array<MiddlewareAnnotationInterface|ParameterAnnotationInterface> $annotations
*/
public function __construct(array $attributes = [], string|null $name = null, string|null $outputType = null, string|null $phpType = null, string|null $description = null, string|null $sourceName = null, array $annotations = [])
{
$this->name = $attributes['name'] ?? $name;
public function __construct(
array $attributes = [],
string|null $name = null,
string|null $outputType = null,
string|null $phpType = null,
string|null $description = null,
string|null $sourceName = null,
array $annotations = [],
) {
$name = $attributes['name'] ?? $name;
if (! $name) {
throw new BadMethodCallException(
'The #[MagicField] attribute must be passed a name. For instance: #[MagicField(name: "phone")]',
);
}

$this->name = $name;
$this->outputType = $attributes['outputType'] ?? $outputType ?? null;
$this->phpType = $attributes['phpType'] ?? $phpType ?? null;
$this->description = $attributes['description'] ?? $description ?? null;
$this->sourceName = $attributes['sourceName'] ?? $sourceName ?? null;

if (! $this->name || (! $this->outputType && ! $this->phpType)) {
throw new BadMethodCallException('The #[MagicField] attribute must be passed a name and an output type or a php type. For instance: "#[MagicField(name: \'phone\', outputType: \'String!\')]" or "#[MagicField(name: \'phone\', phpType: \'string\')]"');
if (! $this->outputType && ! $this->phpType) {
throw new BadMethodCallException(
"The #[MagicField] attribute must be passed an output type or a php type.
For instance: #[MagicField(name: 'phone', outputType: 'String!')]
or #[MagicField(name: 'phone', phpType: 'string')]",
);
}
if (isset($this->outputType) && $this->phpType) {
throw new BadMethodCallException('In a #[MagicField] attribute, you cannot use the outputType and the phpType at the same time. For instance: "#[MagicField(name: \'phone\', outputType: \'String!\')]" or "#[MagicField(name: \'phone\', phpType: \'string\')]"');
throw new BadMethodCallException(
"In a #[MagicField] attribute, you cannot use the outputType and the phpType at the
same time. For instance: #[MagicField(name: 'phone', outputType: 'String!')]
or #[MagicField(name: 'phone', phpType: 'string')]",
);
}
$middlewareAnnotations = [];
$parameterAnnotations = [];
Expand All @@ -67,13 +79,18 @@ public function __construct(array $attributes = [], string|null $name = null, st
} elseif ($annotation instanceof ParameterAnnotationInterface) {
$parameterAnnotations[$annotation->getTarget()][] = $annotation;
} else {
throw new BadMethodCallException('The #[MagicField] attribute\'s "annotations" attribute must be passed an array of annotations implementing either MiddlewareAnnotationInterface or ParameterAnnotationInterface."');
throw new BadMethodCallException(
"The #[MagicField] attribute's 'annotation' attribute must be passed an array
of annotations implementing either MiddlewareAnnotationInterface or
ParameterAnnotationInterface.",
);
}
}
$this->middlewareAnnotations = new MiddlewareAnnotations($middlewareAnnotations);
$this->parameterAnnotations = array_map(static function (array $parameterAnnotationsForAttribute): ParameterAnnotations {
return new ParameterAnnotations($parameterAnnotationsForAttribute);
}, $parameterAnnotations);
$this->parameterAnnotations = array_map(
static fn (array $parameterAnnotationsForAttribute): ParameterAnnotations => new ParameterAnnotations($parameterAnnotationsForAttribute),
$parameterAnnotations,
);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Annotations/Right.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Right implements MiddlewareAnnotationInterface
{
/** @var string */
private $name;
private string $name;

/**
* @param array<string, mixed>|string $name
Expand Down
30 changes: 16 additions & 14 deletions src/Annotations/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,35 @@
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Security implements MiddlewareAnnotationInterface
{
/** @var string */
private $expression;
/** @var mixed */
private $failWith;
/** @var bool */
private $failWithIsSet = false;
/** @var int */
private $statusCode;
/** @var string */
private $message;
private string $expression;
private mixed $failWith;
private bool $failWithIsSet = false;
private int $statusCode;
private string $message;

/**
* @param array<string, mixed>|string $data data array managed by the Doctrine Annotations library or the expression
*
* @throws BadMethodCallException
*/
public function __construct(array|string $data = [], string|null $expression = null, mixed $failWith = '__fail__with__magic__key__', string|null $message = null, int|null $statusCode = null)
{
public function __construct(
array|string $data = [],
string|null $expression = null,
mixed $failWith = '__fail__with__magic__key__',
string|null $message = null,
int|null $statusCode = null,
) {
if (is_string($data)) {
$data = ['expression' => $data];
}

$this->expression = $data['value'] ?? $data['expression'] ?? $expression;
if (! $this->expression) {
$expression = $data['value'] ?? $data['expression'] ?? $expression;
if (! $expression) {
throw new BadMethodCallException('The #[Security] attribute must be passed an expression. For instance: "#[Security("is_granted(\'CAN_EDIT_STUFF\')")]"');
}

$this->expression = $expression;

if (array_key_exists('failWith', $data)) {
$this->failWith = $data['failWith'];
$this->failWithIsSet = true;
Expand Down
Loading
Loading