Skip to content

Commit 3eb14df

Browse files
authored
Change private properties to protected in GraphQLException (#568)
* Change private properties to protected * Resolve phpstan typehint inconsistencies and CS fixes * Additional phpstan fixes * phpstan fixes * phpstan errors
1 parent da95a99 commit 3eb14df

File tree

5 files changed

+48
-16
lines changed

5 files changed

+48
-16
lines changed

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ parameters:
1111
level: 8
1212
checkGenericClassInNonGenericObjectType: false
1313
reportUnmatchedIgnoredErrors: false
14+
treatPhpDocTypesAsCertain: false
1415
ignoreErrors:
1516
- "#PHPDoc tag \\@throws with type Psr\\\\Container\\\\ContainerExceptionInterface is not subtype of Throwable#"
1617
- "#Parameter .* of class ReflectionMethod constructor expects string(\\|null)?, object\\|string given.#"

src/Exceptions/GraphQLException.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
class GraphQLException extends Exception implements GraphQLExceptionInterface
1111
{
1212
/** @param array<string, mixed> $extensions */
13-
public function __construct(string $message, int $code = 0, Throwable|null $previous = null, private string $category = 'Exception', private array $extensions = [])
14-
{
13+
public function __construct(
14+
string $message,
15+
int $code = 0,
16+
Throwable|null $previous = null,
17+
protected string $category = 'Exception',
18+
protected array $extensions = [],
19+
) {
1520
parent::__construct($message, $code, $previous);
1621
}
1722

src/GlobControllerQueryProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
final class GlobControllerQueryProvider implements QueryProviderInterface
3232
{
33-
/** @var array<string,string>|null */
33+
/** @var array<int,string>|null */
3434
private array|null $instancesList = null;
3535
private ClassNameMapper $classNameMapper;
3636
private AggregateControllerQueryProvider|null $aggregateControllerQueryProvider = null;
@@ -73,9 +73,11 @@ private function getAggregateControllerQueryProvider(): AggregateControllerQuery
7373
private function getInstancesList(): array
7474
{
7575
if ($this->instancesList === null) {
76-
$this->instancesList = $this->cacheContract->get('globQueryProvider', function () {
77-
return $this->buildInstancesList();
78-
});
76+
$this->instancesList = $this->cacheContract->get(
77+
'globQueryProvider',
78+
fn () => $this->buildInstancesList(),
79+
);
80+
7981
if (! is_array($this->instancesList)) {
8082
throw new InvalidArgumentException('The instance list returned is not an array. There might be an issue with your PSR-16 cache implementation.');
8183
}

src/Mappers/Root/MyCLabsEnumTypeMapper.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,36 @@ class MyCLabsEnumTypeMapper implements RootTypeMapperInterface
3434
/** @var array<string, EnumType> */
3535
private array $cacheByName = [];
3636

37+
/** @var array<string, class-string<Enum>> */
38+
private array|null $nameToClassMapping = null;
39+
3740
/** @param NS[] $namespaces List of namespaces containing enums. Used when searching an enum by name. */
38-
public function __construct(private readonly RootTypeMapperInterface $next, private readonly AnnotationReader $annotationReader, private readonly CacheInterface $cacheService, private readonly array $namespaces)
39-
{
41+
public function __construct(
42+
private readonly RootTypeMapperInterface $next,
43+
private readonly AnnotationReader $annotationReader,
44+
private readonly CacheInterface $cacheService,
45+
private readonly array $namespaces,
46+
) {
4047
}
4148

42-
public function toGraphQLOutputType(Type $type, OutputType|null $subType, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): OutputType&\GraphQL\Type\Definition\Type
49+
public function toGraphQLOutputType(
50+
Type $type,
51+
OutputType|null $subType,
52+
ReflectionMethod|ReflectionProperty $reflector,
53+
DocBlock $docBlockObj,
54+
): OutputType&\GraphQL\Type\Definition\Type
4355
{
4456
$result = $this->map($type);
4557
return $result ?? $this->next->toGraphQLOutputType($type, $subType, $reflector, $docBlockObj);
4658
}
4759

48-
public function toGraphQLInputType(Type $type, InputType|null $subType, string $argumentName, ReflectionMethod|ReflectionProperty $reflector, DocBlock $docBlockObj): InputType&\GraphQL\Type\Definition\Type
60+
public function toGraphQLInputType(
61+
Type $type,
62+
InputType|null $subType,
63+
string $argumentName,
64+
ReflectionMethod|ReflectionProperty $reflector,
65+
DocBlock $docBlockObj,
66+
): InputType&\GraphQL\Type\Definition\Type
4967
{
5068
$result = $this->map($type);
5169
return $result ?? $this->next->toGraphQLInputType($type, $subType, $argumentName, $reflector, $docBlockObj);
@@ -83,6 +101,7 @@ private function mapByClassName(string $enumClass): EnumType|null
83101
return $this->cacheByName[$type->name] = $this->cache[$enumClass] = $type;
84102
}
85103

104+
86105
private function getTypeName(ReflectionClass $refClass): string
87106
{
88107
$enumType = $this->annotationReader->getEnumTypeAnnotation($refClass);
@@ -131,9 +150,6 @@ public function mapNameToType(string $typeName): NamedType&\GraphQL\Type\Definit
131150
return $this->next->mapNameToType($typeName);
132151
}
133152

134-
/** @var array<string, class-string<Enum>> */
135-
private array|null $nameToClassMapping = null;
136-
137153
/**
138154
* Go through all classes in the defined namespaces and loads the cache.
139155
*
@@ -150,6 +166,7 @@ private function getNameToClassMapping(): array
150166
continue;
151167
}
152168

169+
/** @var class-string<Enum> $className */
153170
$nameToClassMapping[$this->getTypeName($classRef)] = $className;
154171
}
155172
}

src/Utils/Namespaces/NS.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,27 @@ final class NS
3030
private array|null $classes = null;
3131

3232
/** @param string $namespace The namespace that contains the GraphQL types (they must have a `@Type` annotation) */
33-
public function __construct(private readonly string $namespace, private readonly CacheInterface $cache, private readonly ClassNameMapper $classNameMapper, private readonly int|null $globTTL, private readonly bool $recursive)
34-
{
33+
public function __construct(
34+
private readonly string $namespace,
35+
private readonly CacheInterface $cache,
36+
private readonly ClassNameMapper $classNameMapper,
37+
private readonly int|null $globTTL,
38+
private readonly bool $recursive,
39+
) {
3540
}
3641

3742
/**
3843
* Returns the array of globbed classes.
3944
* Only instantiable classes are returned.
4045
*
41-
* @return array<string,ReflectionClass<object>> Key: fully qualified class name
46+
* @return array<class-string,ReflectionClass<object>> Key: fully qualified class name
4247
*/
4348
public function getClassList(): array
4449
{
4550
if ($this->classes === null) {
4651
$this->classes = [];
4752
$explorer = new GlobClassExplorer($this->namespace, $this->cache, $this->globTTL, $this->classNameMapper, $this->recursive);
53+
/** @var array<class-string, string> $classes Override class-explorer lib */
4854
$classes = $explorer->getClassMap();
4955
foreach ($classes as $className => $phpFile) {
5056
if (! class_exists($className, false) && ! interface_exists($className, false)) {
@@ -66,6 +72,7 @@ public function getClassList(): array
6672
}
6773
}
6874

75+
// @phpstan-ignore-next-line - Not sure why we cannot annotate the $classes above
6976
return $this->classes;
7077
}
7178

0 commit comments

Comments
 (0)