Skip to content

Commit 8ab5cf3

Browse files
committed
Code style fixes
1 parent 627516a commit 8ab5cf3

File tree

11 files changed

+41
-27
lines changed

11 files changed

+41
-27
lines changed

src/AnnotationReader.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ private function isErrorImportant(string $annotationClass, string $docComment, s
398398
*
399399
* @param ReflectionClass<T> $refClass
400400
* @param class-string<A> $annotationClass
401-
* @param bool $inherited
402401
*
403402
* @return A[]
404403
*
@@ -530,12 +529,12 @@ public function getPropertyAnnotations(ReflectionProperty $refProperty, string $
530529
if (PHP_MAJOR_VERSION >= 8) {
531530
$attributes = $refProperty->getAttributes();
532531
$toAddAnnotations = array_merge($toAddAnnotations, array_map(
533-
static function ($attribute) {
534-
return $attribute->newInstance();
535-
},
536-
array_filter($attributes, static function ($annotation) use ($annotationClass): bool {
537-
return is_a($annotation->getName(), $annotationClass, true);
538-
})
532+
static function ($attribute) {
533+
return $attribute->newInstance();
534+
},
535+
array_filter($attributes, static function ($annotation) use ($annotationClass): bool {
536+
return is_a($annotation->getName(), $annotationClass, true);
537+
})
539538
));
540539
}
541540
} catch (AnnotationException $e) {

src/Annotations/Field.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ public function __construct(array $attributes = [], ?string $name = null, ?strin
4949
$this->inputType = $inputType ?? $attributes['inputType'] ?? null;
5050

5151
$forValue = $for ?? $attributes['for'] ?? null;
52-
if ($forValue) {
53-
$this->for = (array) $forValue;
52+
if (! $forValue) {
53+
return;
5454
}
55+
56+
$this->for = (array) $forValue;
5557
}
5658

5759
/**

src/FailedResolvingInputType.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace TheCodingMachine\GraphQLite;
66

77
use RuntimeException;
8+
89
use function sprintf;
910

1011
class FailedResolvingInputType extends RuntimeException
@@ -16,11 +17,11 @@ public static function createForMissingConstructorParameter(string $class, strin
1617

1718
public static function createForDecorator(string $class): self
1819
{
19-
return new self("Input type '$class' cannot be a decorator.");
20+
return new self(sprintf("Input type '%s' cannot be a decorator.", $class));
2021
}
2122

2223
public static function createForNotInstantiableClass(string $class): self
2324
{
24-
return new self("Class '$class' annotated with @Input must be instantiable.");
25+
return new self(sprintf("Class '%s' annotated with @Input must be instantiable.", $class));
2526
}
2627
}

src/FieldsBuilder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use TheCodingMachine\GraphQLite\Utils\PropertyAccessor;
4242
use Webmozart\Assert\Assert;
4343

44+
use function array_diff_key;
4445
use function array_fill_keys;
4546
use function array_intersect_key;
4647
use function array_keys;
@@ -56,6 +57,7 @@
5657
use function reset;
5758
use function rtrim;
5859
use function trim;
60+
5961
use const PHP_EOL;
6062

6163
/**
@@ -187,7 +189,8 @@ public function getInputFields(string $className, string $inputName, bool $isUpd
187189
}
188190

189191
// Make sure @Field annotations applied to parent's private properties are taken into account as well.
190-
if ($parent = $refClass->getParentClass()) {
192+
$parent = $refClass->getParentClass();
193+
if ($parent) {
191194
$parentFields = $this->getInputFields($parent->getName(), $inputName, $isUpdate);
192195
$fields = array_merge($fields, array_diff_key($parentFields, $fields));
193196
}

src/Mappers/AbstractTypeMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public function mapClassToInputType(string $className): ResolvableMutableInputIn
325325

326326
$input = $this->getMaps()->getInputByObjectClass($className);
327327
if ($input !== null) {
328-
[ $typeName, $description, $isUpdate ] = $input;
328+
[$typeName, $description, $isUpdate] = $input;
329329
return $this->inputTypeGenerator->mapInput($className, $typeName, $description, $isUpdate);
330330
}
331331

@@ -357,7 +357,7 @@ public function mapNameToType(string $typeName): Type
357357

358358
$input = $this->getMaps()->getInputByGraphQLInputTypeName($typeName);
359359
if ($input !== null) {
360-
[ $className, $description, $isUpdate ] = $input;
360+
[$className, $description, $isUpdate] = $input;
361361
return $this->inputTypeGenerator->mapInput($className, $typeName, $description, $isUpdate);
362362
}
363363

src/Middlewares/SourcePropertyResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use TheCodingMachine\GraphQLite\GraphQLRuntimeException;
88
use TheCodingMachine\GraphQLite\Utils\PropertyAccessor;
99
use Webmozart\Assert\Assert;
10+
1011
use function get_class;
1112
use function is_object;
1213

src/QueryFieldDescriptor.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use TheCodingMachine\GraphQLite\Middlewares\SourceResolver;
1717
use TheCodingMachine\GraphQLite\Parameters\ParameterInterface;
1818

19+
use function is_array;
20+
1921
/**
2022
* A class that describes a field to be created.
2123
* To contains getters and setters to alter the field behaviour.
@@ -134,8 +136,6 @@ public function setPrefetchMethodName(?string $prefetchMethodName): void
134136
* Sets the callable targeting the resolver function if the resolver function is part of a service.
135137
* This should not be used in the context of a field middleware.
136138
* Use getResolver/setResolver if you want to wrap the resolver in another method.
137-
*
138-
* @param callable $callable
139139
*/
140140
public function setCallable(callable $callable): void
141141
{
@@ -159,9 +159,6 @@ public function setTargetMethodOnSource(string $targetMethodOnSource): void
159159
$this->magicProperty = null;
160160
}
161161

162-
/**
163-
* @param string|null $targetPropertyOnSource
164-
*/
165162
public function setTargetPropertyOnSource(?string $targetPropertyOnSource): void
166163
{
167164
if ($this->originalResolver !== null) {

src/SchemaFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use TheCodingMachine\GraphQLite\Utils\NamespacedCache;
5353
use TheCodingMachine\GraphQLite\Utils\Namespaces\NamespaceFactory;
5454

55+
use function apcu_enabled;
5556
use function array_map;
5657
use function array_reverse;
5758
use function class_exists;

src/Types/InputType.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use TheCodingMachine\GraphQLite\FieldsBuilder;
1212
use TheCodingMachine\GraphQLite\Parameters\InputTypeProperty;
1313
use TheCodingMachine\GraphQLite\Utils\PropertyAccessor;
14+
15+
use function array_diff_key;
16+
use function array_flip;
1417
use function array_key_exists;
1518

1619
/**
@@ -30,8 +33,8 @@ class InputType extends MutableInputObjectType implements ResolvableMutableInput
3033
public function __construct(string $className, string $inputName, ?string $description, bool $isUpdate, FieldsBuilder $fieldsBuilder)
3134
{
3235
$reflection = new ReflectionClass($className);
33-
if (!$reflection->isInstantiable()) {
34-
throw FailedResolvingInputType::createForNotInstantiableClass($className);
36+
if (! $reflection->isInstantiable()) {
37+
throw FailedResolvingInputType::createForNotInstantiableClass($className);
3538
}
3639

3740
$this->fields = $fieldsBuilder->getInputFields($className, $inputName, $isUpdate);
@@ -133,7 +136,7 @@ private function getClassConstructParameterNames(): array
133136
$refClass = new ReflectionClass($this->className);
134137
$constructor = $refClass->getConstructor();
135138

136-
if (!$constructor) {
139+
if (! $constructor) {
137140
return [];
138141
}
139142

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace TheCodingMachine\GraphQLite\Utils;
46

57
use LogicException;
68

9+
use function sprintf;
10+
use function ucfirst;
11+
712
class AccessPropertyException extends LogicException
813
{
914
public static function createForUnreadableProperty(string $class, string $propertyName): self
1015
{
1116
$name = ucfirst($propertyName);
1217

13-
return new self("Could not get value from property '$class::$propertyName'. Either make the property public or add a public getter for it like 'get$name' or 'is$name' with no required parameters");
18+
return new self(sprintf("Could not get value from property '%s::%s'. Either make the property public or add a public getter for it like 'get%s' or 'is%s' with no required parameters", $class, $propertyName, $name, $name));
1419
}
1520

1621
public static function createForUnwritableProperty(string $class, string $propertyName): self
1722
{
1823
$name = ucfirst($propertyName);
1924

20-
return new self("Could not set value for property '$class::$propertyName'. Either make the property public or add a public setter for it like this: 'set$name'");
25+
return new self(sprintf("Could not set value for property '%s::%s'. Either make the property public or add a public setter for it like this: 'set%s'", $class, $propertyName, $name));
2126
}
2227
}

0 commit comments

Comments
 (0)