php-stubs / generator

Generate stubs from any PHP code for IDE completion and static analysis.
https://packagist.org/packages/php-stubs/generator
MIT License
52 stars 11 forks source link

For some source directories, output file is blank #27

Closed aayla-secura closed 1 month ago

aayla-secura commented 1 month ago

I was trying to generate stubs today for phpunit/phpunit and yoast/phpunit-polyfills and the resulting php stubs file is blank, even though the generator's report says it's found classes, etc. For example:

$ composer exec -- generate-stubs vendor/yoast/phpunit-polyfills/ --out=php-stubs/yoast-phpunit-polyfills.php

PHP Stubs Generator
===================

 [OK] Stubs written to XXXXXX/php-stubs/yoast-phpunit-polyfills.php

 ----------- --------- ------------ -------- ----------- ---------
  functions   classes   interfaces   traits   constants   globals
 ----------- --------- ------------ -------- ----------- ---------
  0           6         0            17       0           0
 ----------- --------- ------------ -------- ----------- ---------

Duplicate declarations found
----------------------------

 --------- ------------------------------------------------------------------------ -------
  type      name                                                                     count
 --------- ------------------------------------------------------------------------ -------
  classes   Yoast\PHPUnitPolyfills\TestCases\TestCase                                2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertArrayWithListKeys                 2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource                    2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertEqualsSpecializations             2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertFileEqualsSpecializations         2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertIgnoringLineEndings               2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertIsList                            2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertIsType                            2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals                      2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertObjectNotEquals                   2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertObjectProperty                    2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains                    2
  traits    Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames                        2
  traits    Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations                  2
  traits    Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches           2
  traits    Yoast\PHPUnitPolyfills\Polyfills\ExpectUserDeprecation                   2
  traits    Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation   2
 --------- ------------------------------------------------------------------------ -------

but the output is blank:

$ cat php-stubs/yoast-phpunit-polyfills.php
<?php

Same with vendor/phpunit/phpunit... Am I using it in the wrong way?

I'm using generator v0.8.4 with PHP 8.4

szepeviktor commented 1 month ago

Hello @aayla-secura!

This is not really a software. We forked it because the original is abandoned. I have no clue what is going on. Try running it on a single file. e.g. vendor/yoast/phpunit-polyfills/src/Polyfills/AssertIsList.php

szepeviktor commented 1 month ago

... maybe not on the distributed pkg but on the original source from https://github.com/Yoast/PHPUnit-Polyfills

aayla-secura commented 1 month ago

Hi @szepeviktor and thank you for replying. I tried both: running it on a single test file (I tried with each one individually), and with the source repository. They are all blank... It works with other sources, but not these two that I pointed out, very bizarre.

szepeviktor commented 1 month ago

In the checked out generator repo: composer u git clone git@github.com:Yoast/PHPUnit-Polyfills.git bin/generate-stubs --out=testy.stubs PHPUnit-Polyfills/src/ generated a 38246 byte file PHP 7.4 That is all I can do for you.

aayla-secura commented 1 month ago

Hmm, ok, weird, I tried the same thing inside a php Docker image, in 3 different versions: 7.4.33, 8.3.12 and 8.4.0 (which is the one I have locally installed), and they all succeeded... So something else is causing it to fail on my machine, not the PHP version. I'll investigate more.

szepeviktor commented 1 month ago

Thank you!

Please share your findings for the benefit of others.

aayla-secura commented 1 month ago

Ok, I started with a clean composer project and installed php-stubs/generator. It was working to generate the stubs mentioned above. Then I installed yoast/phpunit-polyfills into the project and it stopped working. Removed yoast/phpunit-polyfills: working again... Somehow yoast/phpunit-polyfills breaks it but I can't figure out how and why. But oh well, that's good enough for me!

szepeviktor commented 1 month ago

https://github.com/Yoast/PHPUnit-Polyfills/blob/c3c90aa50c7176220f101b871b6124785a4e174f/composer.json#L39-L43 👀

aayla-secura commented 1 month ago

https://github.com/Yoast/PHPUnit-Polyfills/blob/c3c90aa50c7176220f101b871b6124785a4e174f/composer.json#L39-L43 👀

Ah, so the autoloader that phpunitpolyfills-autoload.php defines an for Yoast\PHPUnitPolyfills classes is what breaks it? I don't really understand why, but also I don't have a clue about how the generator works 🙃 so perhaps this is an expected side effect.