1313use Symfony \Component \Cache \Psr16Cache ;
1414use TheCodingMachine \GraphQLite \Mappers \StaticClassListTypeMapper ;
1515use TheCodingMachine \GraphQLite \Mappers \StaticClassListTypeMapperFactory ;
16+ use Webmozart \Assert \Assert ;
1617use function class_exists ;
1718use Doctrine \Common \Annotations \AnnotationException ;
1819use Doctrine \Common \Annotations \AnnotationReader as DoctrineAnnotationReader ;
@@ -102,14 +103,19 @@ class GraphqliteCompilerPass implements CompilerPassInterface
102103 public function process (ContainerBuilder $ container ): void
103104 {
104105 $ reader = $ this ->getAnnotationReader ();
105- $ this ->cacheDir = $ container ->getParameter ('kernel.cache_dir ' );
106+ $ cacheDir = $ container ->getParameter ('kernel.cache_dir ' );
107+ Assert::string ($ cacheDir );
108+ $ this ->cacheDir = $ cacheDir ;
106109 //$inputTypeUtils = new InputTypeUtils($reader, $namingStrategy);
107110
108111 // Let's scan the whole container and tag the services that belong to the namespace we want to inspect.
109112 $ controllersNamespaces = $ container ->getParameter ('graphqlite.namespace.controllers ' );
113+ Assert::isIterable ($ controllersNamespaces );
110114 $ typesNamespaces = $ container ->getParameter ('graphqlite.namespace.types ' );
115+ Assert::isIterable ($ typesNamespaces );
111116
112117 $ firewallName = $ container ->getParameter ('graphqlite.security.firewall_name ' );
118+ Assert::string ($ firewallName );
113119 $ firewallConfigServiceName = 'security.firewall.map.config. ' .$ firewallName ;
114120
115121 // 2 seconds of TTL in environment mode. Otherwise, let's cache forever!
@@ -183,14 +189,23 @@ public function process(ContainerBuilder $container): void
183189 if ($ container ->getParameter ('graphqlite.security.introspection ' ) === false ) {
184190 $ rulesDefinition [] = $ container ->findDefinition (DisableIntrospection::class);
185191 }
186- if ($ container ->getParameter ('graphqlite.security.maximum_query_complexity ' )) {
187- $ complexity = (int ) $ container ->getParameter ('graphqlite.security.maximum_query_complexity ' );
188- $ rulesDefinition [] = $ container ->findDefinition (QueryComplexity::class)->setArgument (0 , $ complexity );
192+
193+ $ complexity = $ container ->getParameter ('graphqlite.security.maximum_query_complexity ' );
194+ if ($ complexity ) {
195+ Assert::integerish ($ complexity );
196+
197+ $ rulesDefinition [] = $ container ->findDefinition (QueryComplexity::class)
198+ ->setArgument (0 , (int ) $ complexity );
189199 }
190- if ($ container ->getParameter ('graphqlite.security.maximum_query_depth ' )) {
191- $ depth = (int ) $ container ->getParameter ('graphqlite.security.maximum_query_depth ' );
192- $ rulesDefinition [] = $ container ->findDefinition (QueryDepth::class)->setArgument (0 , $ depth );
200+
201+ $ depth = $ container ->getParameter ('graphqlite.security.maximum_query_depth ' );
202+ if ($ depth ) {
203+ Assert::integerish ($ depth );
204+
205+ $ rulesDefinition [] = $ container ->findDefinition (QueryDepth::class)
206+ ->setArgument (0 , (int ) $ depth );
193207 }
208+
194209 $ serverConfigDefinition ->addMethodCall ('setValidationRules ' , [$ rulesDefinition ]);
195210
196211 if ($ disableMe === false ) {
@@ -332,7 +347,7 @@ private function mapAdderToTag(string $tag, string $methodName, ContainerBuilder
332347 */
333348 private function makePublicInjectedServices (ReflectionClass $ refClass , AnnotationReader $ reader , ContainerBuilder $ container , bool $ isController ): void
334349 {
335- $ services = $ this ->getCodeCache ()->get ($ refClass , function () use ($ refClass , $ reader , $ container , $ isController ) {
350+ $ services = $ this ->getCodeCache ()->get ($ refClass , function () use ($ refClass , $ reader , $ container , $ isController ): array {
336351 $ services = [];
337352 foreach ($ refClass ->getMethods (ReflectionMethod::IS_PUBLIC ) as $ method ) {
338353 $ field = $ reader ->getRequestAnnotation ($ method , Field::class) ?? $ reader ->getRequestAnnotation ($ method , Query::class) ?? $ reader ->getRequestAnnotation ($ method , Mutation::class);
@@ -346,6 +361,7 @@ private function makePublicInjectedServices(ReflectionClass $refClass, Annotatio
346361 }
347362 }
348363 }
364+
349365 return $ services ;
350366 });
351367
@@ -484,7 +500,7 @@ private function getClassList(string $namespace, int $globTtl = 2, bool $recursi
484500 // The autoloader might trigger errors if the file does not respect PSR-4 or if the
485501 // Symfony DebugAutoLoader is installed. (see https://github.com/thecodingmachine/graphqlite/issues/216)
486502 require_once $ phpFile ;
487- // Does it exists now?
503+ // @phpstan-ignore-next-line Does it exist now?
488504 if (! class_exists ($ className , false )) {
489505 continue ;
490506 }
0 commit comments