Skip to content

Commit 8711488

Browse files
authored
Merge pull request #128 from moufmouf/backport_optim_reflection
Backporting public method optimization
2 parents 1fa0023 + 54ad150 commit 8711488

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/FieldsBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private function getFieldsByAnnotations($controller, string $annotationName, boo
233233
}
234234
}
235235

236-
foreach ($refClass->getMethods() as $refMethod) {
236+
foreach ($refClass->getMethods(ReflectionMethod::IS_PUBLIC) as $refMethod) {
237237
if ($closestMatchingTypeClass !== null && $closestMatchingTypeClass === $refMethod->getDeclaringClass()->getName()) {
238238
// Optimisation: no need to fetch annotations from parent classes that are ALREADY GraphQL types.
239239
// We will merge the fields anyway.

src/Mappers/GlobTypeMapper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ private function buildMap(): void
329329

330330
$isAbstract = $refClass->isAbstract();
331331

332-
foreach ($refClass->getMethods() as $method) {
333-
if (!$method->isPublic() || ($isAbstract && !$method->isStatic())) {
332+
foreach ($refClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
333+
if ($isAbstract && !$method->isStatic()) {
334334
continue;
335335
}
336336
$factory = $this->annotationReader->getFactoryAnnotation($method);

tests/Mappers/GlobTypeMapperTest.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,19 @@ public function testGlobTypeMapperDuplicateInputTypesException()
7979

8080
$mapper = new GlobTypeMapper('TheCodingMachine\GraphQLite\Fixtures\DuplicateInputTypes', $typeGenerator, $this->getInputTypeGenerator(), $this->getInputTypeUtils(), $container, new \TheCodingMachine\GraphQLite\AnnotationReader(new AnnotationReader()), new NamingStrategy(), $this->getLockFactory(), new NullCache());
8181

82-
$this->expectException(DuplicateMappingException::class);
83-
$this->expectExceptionMessage('The class \'TheCodingMachine\GraphQLite\Fixtures\TestObject\' should be mapped to only one GraphQL Input type. Two methods are pointing via the @Factory annotation to this class: \'TheCodingMachine\GraphQLite\Fixtures\DuplicateInputTypes\TestFactory::myFactory\' and \'TheCodingMachine\GraphQLite\Fixtures\DuplicateInputTypes\TestFactory2::myFactory\'');
84-
$mapper->canMapClassToInputType(TestObject::class);
82+
$caught = false;
83+
try {
84+
$mapper->canMapClassToInputType(TestObject::class);
85+
} catch (DuplicateMappingException $e) {
86+
// Depending on the environment, one of the messages can be returned.
87+
$this->assertContains($e->getMessage(),
88+
[
89+
'The class \'TheCodingMachine\GraphQLite\Fixtures\TestObject\' should be mapped to only one GraphQL Input type. Two methods are pointing via the @Factory annotation to this class: \'TheCodingMachine\GraphQLite\Fixtures\DuplicateInputTypes\TestFactory::myFactory\' and \'TheCodingMachine\GraphQLite\Fixtures\DuplicateInputTypes\TestFactory2::myFactory\'',
90+
'The class \'TheCodingMachine\GraphQLite\Fixtures\TestObject\' should be mapped to only one GraphQL Input type. Two methods are pointing via the @Factory annotation to this class: \'TheCodingMachine\GraphQLite\Fixtures\DuplicateInputTypes\TestFactory2::myFactory\' and \'TheCodingMachine\GraphQLite\Fixtures\DuplicateInputTypes\TestFactory::myFactory\''
91+
]);
92+
$caught = true;
93+
}
94+
$this->assertTrue($caught, 'DuplicateMappingException is thrown');
8595
}
8696

8797
public function testGlobTypeMapperClassNotFoundException()

0 commit comments

Comments
 (0)