maglnet / ComposerRequireChecker

A CLI tool to check whether a specific composer package uses imported symbols that aren't part of its direct composer dependencies
MIT License
887 stars 71 forks source link

Support attributes #527

Closed tugmaks closed 7 months ago

tugmaks commented 7 months ago

Hello, thanks for this package. I want to submit PR that covers usage of php attributes ( #404 )

The short example why it is useful: imagine that you start a symfony project from skeleton symfony new my_project_directory --version="7.0.*" --webapp As you can see it is not dependent on symfony/routing And create simple controller in src/Controllers

<?php

declare(strict_types=1);

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;

final class FooController extends AbstractController
{
    #[Route('/foo')]
    public function invoke(): JsonResponse
    {
        return new JsonResponse();
    }
}

Now it starts to depend on symfony/routing

So, if you run checker output will be:

$ XDEBUG_MODE=off vendor/bin/composer-require-checker
ComposerRequireChecker 4.8.0@1c7498e4c31ff7e467ac1b5138d277736c838393
The following 2 unknown symbols were found:
+-----------------------------------------------+--------------------+
| Unknown Symbol                                | Guessed Dependency |
+-----------------------------------------------+--------------------+
| Symfony\Component\HttpFoundation\JsonResponse |                    |
| Symfony\Component\HttpKernel\Kernel           |                    |
+-----------------------------------------------+--------------------+

No warning about Symfony\Component\Routing\Attribute\Route attribute

My branch produces that output:

XDEBUG_MODE=off vendor/bin/composer-require-checker
ComposerRequireChecker dev-php-attributes@bd0f004bd5c6b2214eb6a5fa273b0227745e0568
The following 3 unknown symbols were found:
+-----------------------------------------------+--------------------+
| Unknown Symbol                                | Guessed Dependency |
+-----------------------------------------------+--------------------+
| Symfony\Component\HttpFoundation\JsonResponse |                    |
| Symfony\Component\HttpKernel\Kernel           |                    |
| Symfony\Component\Routing\Attribute\Route     |                    |
+-----------------------------------------------+--------------------+