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

Class missing in stubs #9

Closed kkmuffme closed 2 years ago

kkmuffme commented 2 years ago

Package installed with composer: abraham/twitteroauth (I need the stubs as I'm doing something like you do with the WP stubs which do not use composer, so I need stubs)

generate-stubs --force --functions --classes --interfaces --traits --out="a.php" --no-interaction twitter (package is installed in twitter folder)

It generates the stubs (10 classes), but stubs for class TwitterOAuth extends Config are missing. But e.g. class TwitterOAuthException extends \Exception and all other classes are there (total 11 classes, but only 10 have stubs created).

Is this a bug or is there something I'm doing wrong?

szepeviktor commented 2 years ago

Hello @kkmuffme! Try to generate from that specific file.

It is very easy to debug this project.

kkmuffme commented 2 years ago

If I run it for that file only, there are no errors either (but no stubs generated) it even says "OK":

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

 [OK] Stubs written to /some/path/a.php

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

and the output file contains only:

<?php
szepeviktor commented 2 years ago

Try debugging in this try/catch block https://github.com/php-stubs/generator/blob/53c2cbb0ab3049d73d4490d47c9f2f9028580ef8/src/StubsGenerator.php#L133 Please see #4

dingo-d commented 2 years ago

I'm also experiencing the same issue. When manually trying to generate the stubs from the command line I get the correct number of stubs recognized, but when I check the file, it's empty.

image

When I don't specify out parameter I don't get anything out.

No error is thrown.

I var dumped the visitor in the StubsGenerator.php, and I can see the correct class and traits mentioned, the $unparsed variable is empty, which is ok.

Not sure why nothing is getting parsed out.

szepeviktor commented 2 years ago

Dear Denis! You may be hit by #14

dingo-d commented 2 years ago

My PHP parsing is not strong, so I'll wait for a fix, but when you'll have something feel free to ping me to test it 👍🏼

szepeviktor commented 2 years ago

I went the wrong way: temporarily commented out that line mentioned in #14

dingo-d commented 2 years ago

Tried that, but didn't do anything (nothing was generated)

szepeviktor commented 2 years ago

I've just commented out all four *exists conditions (func, trait, class, interface) and generate-stubs gave me 909 lines of stubs :)

szepeviktor commented 2 years ago
$ vendor/bin/generate-stubs --functions --classes --interfaces --traits src/Helpers/ | wc -l
909
dingo-d commented 2 years ago

Yup can confirm, commenting those lines out seems to generate a correct stub 👍🏼

herndlm commented 2 years ago

Would a new config switch for that behaviour (include "existing" things) be useful? Maybe such issues can then be avoided

szepeviktor commented 2 years ago

I'm sorry, Martin! This is a highly dangerous ⚡ fork for php-stubs organization stubs only. Without php-stubs this would be https://github.com/GiacoCorsiglia/php-stubs-generator