Skip to content

Try olvlvl/composer-attribute-collector #4064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jun 16, 2025

No description provided.

@ondrejmirtes
Copy link
Member

Won't work on PHP 7.4. But the idea is to rebase my fork on top of it and only have minimal changes there.

@staabm
Copy link
Contributor Author

staabm commented Jun 16, 2025

yeah, the problem is that it currently doesn't even work on PHP 8.x

@olvlvl
Copy link

olvlvl commented Jun 16, 2025

I cloned phpstan-src:2.1.x on my machine, but composer install hangs on this step:

  - Applying patches for composer/ca-bundle
    patches/cloudflare-ca.patch (0)

I removed all the "patches" and used my package. After the autoload dump I see the attribute file with collected target parameters. I guess the collector is doing its job.

    targetParameters: array (
  'PHPStan\\DependencyInjection\\AutowiredParameter' => 
  array (
    0 => 
    array (
      0 => 
      array (
        'ref' => '%currentWorkingDirectory%',
      ),
      1 => 'PHPStan\\File\\ParentDirectoryRelativePathHelper',
      2 => '__construct',
      3 => 'parentDirectory',
    ),
    1 => 
    array (
      0 => 
      array (
        'ref' => '%currentWorkingDirectory%',
      ),
      1 => 'PHPStan\\File\\FileHelper',
      2 => '__construct',
      3 => 'workingDirectory',
    ),

Running make tests I get the following error:

  Service of type PHPStan\Reflection\SignatureMap\NativeFunctionReflectionProvider: Service of type PHPStan\Reflection\SignatureMap\SignatureMapProvider re
  quired by $signatureMapProvider in NativeFunctionReflectionProvider::__construct() not found. Did you add it to configuration file?

I see SignatureMapProvider is an interface, not a class. The collector filters out interfaces.

After removing the interface filter I see the class in the dump:

    225 => 
    array (
      0 => 
      array (
        'factory' => '@PHPStan\\Reflection\\SignatureMap\\SignatureMapProviderFactory::create',
      ),
      1 => 'PHPStan\\Reflection\\SignatureMap\\SignatureMapProvider',
    ),

which matches the definition:

#[AutowiredService(factory: '@PHPStan\Reflection\SignatureMap\SignatureMapProviderFactory::create')]
interface SignatureMapProvider

After that, I get tons of these errors, but I guess that's because I'm running PHP 8.4.

Deprecated: Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in /Volumes/git/phpstan-src/vendor/nette/di/src/DI/DependencyChecker.php on line 150
PHP Deprecated:  Calling ReflectionMethod::__construct() with 1 argument is deprecated, use ReflectionMethod::createFromMethodName() instead in /Volumes/git/phpstan-src/vendor/nette/di/src/DI/DependencyChecker.php on line 150

Can you try on your side if removing the interface filter works? I don't mind collecting attributes on interfaces, it's just I never thought of this usage. In Plugin.php:

    private static function buildFileFilter(): Filter
    {
        return new Filter\Chain([
            new ContentFilter(),
            //new InterfaceFilter()
        ]);
    }

I created a Dockerfile with PHP 8.2, restored the "patches", and ran composer up. All patches were applied except this one:

  - Applying patches for react/http
    patches/Sender.patch (0)
   Could not apply patch! Skipping. The error was: Cannot apply patch patches/Sender.patch

Then, running make test gave me the following error:

In Processor.php line 94:
                                           
  Unexpected item 'parameters › baseUrl'.  
                                           

It would be great to have a Dockerfile for reproducible runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants