Skip to content

Commit 434b7ea

Browse files
authored
Houskeeping (#736)
* CS fixes * Resolved additional phpunit issues and deprecations * Allow PHPUnit 10.x * Restore deprecated ReflectionMethod construction for <PHP 8.3 support * CS fixes * Restore phpunit.xml.dist to Github compatible version
1 parent 37c06a9 commit 434b7ea

13 files changed

+142
-152
lines changed

phpunit.xml.dist

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
5+
bootstrap="tests/Bootstrap.php"
6+
7+
cacheDirectory=".phpunit.cache"
8+
cacheResult="true"
9+
10+
backupGlobals="false"
11+
colors="true"
12+
processIsolation="false"
13+
stopOnFailure="false"
14+
backupStaticProperties="false"
15+
>
316
<coverage>
417
<report>
518
<clover outputFile="build/logs/clover.xml"/>
619
<html outputDirectory="build/coverage"/>
720
</report>
821
</coverage>
22+
923
<testsuites>
1024
<testsuite name="GraphQLite Test Suite">
1125
<directory>./tests/</directory>
1226
<exclude>./tests/Bootstrap.php</exclude>
1327
</testsuite>
1428
</testsuites>
29+
1530
<logging/>
31+
1632
<source>
1733
<include>
1834
<directory suffix=".php">src/</directory>

src/Annotations/EnumType.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
#[Attribute(Attribute::TARGET_CLASS)]
2121
class EnumType
2222
{
23-
/** @var string|null */
24-
private $name;
25-
26-
/** @var bool */
27-
private $useValues;
23+
private string|null $name;
24+
private bool $useValues;
2825

2926
/** @param mixed[] $attributes */
3027
public function __construct(array $attributes = [], string|null $name = null, bool|null $useValues = null)

src/Annotations/ExtendType.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
class ExtendType
2020
{
2121
/** @var class-string<object>|null */
22-
private $class;
23-
/** @var string|null */
24-
private $name;
22+
private string|null $class;
23+
private string|null $name;
2524

2625
/** @param mixed[] $attributes */
27-
public function __construct(array $attributes = [], string|null $class = null, string|null $name = null)
28-
{
26+
public function __construct(
27+
array $attributes = [],
28+
string|null $class = null,
29+
string|null $name = null,
30+
) {
2931
$className = isset($attributes['class']) ? ltrim($attributes['class'], '\\') : null;
3032
$className = $className ?? $class;
3133
if ($className !== null && ! class_exists($className) && ! interface_exists($className)) {

src/Annotations/Factory.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
#[Attribute(Attribute::TARGET_METHOD)]
1414
class Factory
1515
{
16-
/** @var string|null */
17-
private $name;
18-
/** @var bool */
19-
private $default;
16+
private string|null $name;
17+
private bool $default;
2018

2119
/** @param mixed[] $attributes */
2220
public function __construct(array $attributes = [], string|null $name = null, bool|null $default = null)

src/Annotations/FailWith.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ class FailWith implements MiddlewareAnnotationInterface
1515
{
1616
/**
1717
* The default value to use if the right is not enforced.
18-
*
19-
* @var mixed
2018
*/
21-
private $value;
19+
private mixed $value;
2220

2321
/** @throws BadMethodCallException */
2422
public function __construct(mixed $values = [], mixed $value = '__fail__with__magic__key__')

src/Annotations/Field.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,31 @@
1313
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1414
class Field extends AbstractRequest
1515
{
16-
/** @var string|null */
17-
private $prefetchMethod;
16+
private string|null $prefetchMethod;
1817

1918
/**
2019
* Input/Output type names for which this fields should be applied to.
2120
*
2221
* @var string[]|null
2322
*/
24-
private $for = null;
23+
private array|null $for = null;
2524

26-
/** @var string|null */
27-
private $description;
28-
29-
/** @var string|null */
30-
private $inputType;
25+
private string|null $description;
26+
private string|null $inputType;
3127

3228
/**
3329
* @param mixed[] $attributes
3430
* @param string|string[] $for
3531
*/
36-
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)
37-
{
32+
public function __construct(
33+
array $attributes = [],
34+
string|null $name = null,
35+
string|null $outputType = null,
36+
string|null $prefetchMethod = null,
37+
string|array|null $for = null,
38+
string|null $description = null,
39+
string|null $inputType = null,
40+
) {
3841
parent::__construct($attributes, $name, $outputType);
3942

4043
$this->prefetchMethod = $prefetchMethod ?? $attributes['prefetchMethod'] ?? null;

src/Annotations/MagicField.php

+44-27
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,56 @@
1616
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
1717
class MagicField implements SourceFieldInterface
1818
{
19-
/** @var string */
20-
private $name;
19+
private string $name;
20+
private string|null $outputType;
21+
private string|null $phpType;
22+
private string|null $description;
23+
private string|null $sourceName;
2124

22-
/** @var string|null */
23-
private $outputType;
24-
25-
/** @var string|null */
26-
private $phpType;
27-
28-
/** @var string|null */
29-
private $description;
30-
31-
/** @var string|null */
32-
private $sourceName;
33-
34-
/** @var MiddlewareAnnotations */
35-
private $middlewareAnnotations;
25+
private MiddlewareAnnotations $middlewareAnnotations;
3626

3727
/** @var array<string, ParameterAnnotations> */
38-
private $parameterAnnotations;
28+
private array $parameterAnnotations;
3929

4030
/**
4131
* @param mixed[] $attributes
4232
* @param array<MiddlewareAnnotationInterface|ParameterAnnotationInterface> $annotations
4333
*/
44-
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 = [])
45-
{
46-
$this->name = $attributes['name'] ?? $name;
34+
public function __construct(
35+
array $attributes = [],
36+
string|null $name = null,
37+
string|null $outputType = null,
38+
string|null $phpType = null,
39+
string|null $description = null,
40+
string|null $sourceName = null,
41+
array $annotations = [],
42+
) {
43+
$name = $attributes['name'] ?? $name;
44+
if (! $name) {
45+
throw new BadMethodCallException(
46+
'The #[MagicField] attribute must be passed a name. For instance: #[MagicField(name: "phone")]',
47+
);
48+
}
49+
50+
$this->name = $name;
4751
$this->outputType = $attributes['outputType'] ?? $outputType ?? null;
4852
$this->phpType = $attributes['phpType'] ?? $phpType ?? null;
4953
$this->description = $attributes['description'] ?? $description ?? null;
5054
$this->sourceName = $attributes['sourceName'] ?? $sourceName ?? null;
5155

52-
if (! $this->name || (! $this->outputType && ! $this->phpType)) {
53-
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\')]"');
56+
if (! $this->outputType && ! $this->phpType) {
57+
throw new BadMethodCallException(
58+
"The #[MagicField] attribute must be passed an output type or a php type.
59+
For instance: #[MagicField(name: 'phone', outputType: 'String!')]
60+
or #[MagicField(name: 'phone', phpType: 'string')]",
61+
);
5462
}
5563
if (isset($this->outputType) && $this->phpType) {
56-
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\')]"');
64+
throw new BadMethodCallException(
65+
"In a #[MagicField] attribute, you cannot use the outputType and the phpType at the
66+
same time. For instance: #[MagicField(name: 'phone', outputType: 'String!')]
67+
or #[MagicField(name: 'phone', phpType: 'string')]",
68+
);
5769
}
5870
$middlewareAnnotations = [];
5971
$parameterAnnotations = [];
@@ -67,13 +79,18 @@ public function __construct(array $attributes = [], string|null $name = null, st
6779
} elseif ($annotation instanceof ParameterAnnotationInterface) {
6880
$parameterAnnotations[$annotation->getTarget()][] = $annotation;
6981
} else {
70-
throw new BadMethodCallException('The #[MagicField] attribute\'s "annotations" attribute must be passed an array of annotations implementing either MiddlewareAnnotationInterface or ParameterAnnotationInterface."');
82+
throw new BadMethodCallException(
83+
"The #[MagicField] attribute's 'annotation' attribute must be passed an array
84+
of annotations implementing either MiddlewareAnnotationInterface or
85+
ParameterAnnotationInterface.",
86+
);
7187
}
7288
}
7389
$this->middlewareAnnotations = new MiddlewareAnnotations($middlewareAnnotations);
74-
$this->parameterAnnotations = array_map(static function (array $parameterAnnotationsForAttribute): ParameterAnnotations {
75-
return new ParameterAnnotations($parameterAnnotationsForAttribute);
76-
}, $parameterAnnotations);
90+
$this->parameterAnnotations = array_map(
91+
static fn (array $parameterAnnotationsForAttribute): ParameterAnnotations => new ParameterAnnotations($parameterAnnotationsForAttribute),
92+
$parameterAnnotations,
93+
);
7794
}
7895

7996
/**

src/Annotations/Right.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1313
class Right implements MiddlewareAnnotationInterface
1414
{
15-
/** @var string */
16-
private $name;
15+
private string $name;
1716

1817
/**
1918
* @param array<string, mixed>|string $name

src/Annotations/Security.php

+16-14
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,35 @@
1313
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1414
class Security implements MiddlewareAnnotationInterface
1515
{
16-
/** @var string */
17-
private $expression;
18-
/** @var mixed */
19-
private $failWith;
20-
/** @var bool */
21-
private $failWithIsSet = false;
22-
/** @var int */
23-
private $statusCode;
24-
/** @var string */
25-
private $message;
16+
private string $expression;
17+
private mixed $failWith;
18+
private bool $failWithIsSet = false;
19+
private int $statusCode;
20+
private string $message;
2621

2722
/**
2823
* @param array<string, mixed>|string $data data array managed by the Doctrine Annotations library or the expression
2924
*
3025
* @throws BadMethodCallException
3126
*/
32-
public function __construct(array|string $data = [], string|null $expression = null, mixed $failWith = '__fail__with__magic__key__', string|null $message = null, int|null $statusCode = null)
33-
{
27+
public function __construct(
28+
array|string $data = [],
29+
string|null $expression = null,
30+
mixed $failWith = '__fail__with__magic__key__',
31+
string|null $message = null,
32+
int|null $statusCode = null,
33+
) {
3434
if (is_string($data)) {
3535
$data = ['expression' => $data];
3636
}
3737

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

43+
$this->expression = $expression;
44+
4345
if (array_key_exists('failWith', $data)) {
4446
$this->failWith = $data['failWith'];
4547
$this->failWithIsSet = true;

0 commit comments

Comments
 (0)