-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected
6.0.4
Description
AnnotationDirectoryLoader::load()
has a return type RouteCollection
, but it may return null
in some situations
symfony/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php
Lines 28 to 31 in 4a31c29
public function load(mixed $path, string $type = null): RouteCollection | |
{ | |
if (!is_dir($dir = $this->locator->locate($path))) { | |
return parent::supports($path, $type) ? parent::load($path, $type) : new RouteCollection(); |
Because it calls parent::load(), which is AnnotationFileLoader::load()
, which has return type ?RouteCollection
public function load(mixed $file, string $type = null): ?RouteCollection |
How to reproduce
- have an abstract class that extends
\Symfony\Bundle\FrameworkBundle\Controller\AbstractController
(e.g.abstract class AdminController extends AbstractController
) - have
config/routes/annotations.yaml
similar to:
controllers:
resource: '../../src/**/*Controller.php'
type: annotation
kernel:
resource: ../../src/Kernel.php
type: annotation
- upgrade from 5.4.4 to 6.0.4
Symfony\Component\Routing\Loader\AnnotationDirectoryLoader::load(): Return value must be of type Symfony\Component\Routing\RouteCollection, null returned
Possible Solution
Change the return type of AnnotationDirectoryLoader::load()
to ?RouteCollection
Additional Context
No response