Skip to content
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

Stubs loses "use" statements #8

Closed
andreasciamanna opened this issue Oct 20, 2020 · 4 comments
Closed

Stubs loses "use" statements #8

andreasciamanna opened this issue Oct 20, 2020 · 4 comments

Comments

@andreasciamanna
Copy link

andreasciamanna commented Oct 20, 2020

Looking at its activities, I'm not sure if this project is still maintained.
However, would still like to report an issue hoping for a fix :)

When exporting a class which has one or more "use" statements, these are not included in the stub.

This issue cases PHPStan to think that a returned value (which is the scope of the namespace of one of these "use" statements) is not defined.

In other words, this:

namespace WPML\LIB\WP;

use WPML\FP\Either;
use WPML\FP\Promise;

class Hooks {

	/**
	 * @param string|string[] $action
	 * @param int             $priority
	 * @param int             $accepted_args
	 *
	 * @return Promise
	 */
	public static function onAction( $action, $priority = 10, $accepted_args = 1 ) {
		return self::onHook( 'add_action', $action, $priority, $accepted_args );
	}

Is stubbed as:

namespace WPML\LIB\WP;

class Hooks {
    /**
     * @param string|string[] $action
     * @param int             $priority
     * @param int             $accepted_args
     *
     * @return Promise
     */
    public static function onAction($action, $priority = 10, $accepted_args = 1)
    {
    }

PHPStan, when validating the stub, shows Return typehint of method WPML\LIB\WP\Hooks::onAction() has invalid type WPML\LIB\WP\Promise. because it obviously assumes Promise is part of \WPML\LIB\WP.

Manually adding the missing "use" statements, the error goes away.

The problem is that I've hundred of stubs like these :(

@szepeviktor
Copy link
Contributor

You should always typehint in phpdoc block with FQCN.

@andreasciamanna
Copy link
Author

Right.

A rule I forgot.

Thanks!

@mundschenk-at
Copy link

You should always typehint in phpdoc block with FQCN.

Not actually true (anymore): https://docs.phpdoc.org/3.0/guide/guides/types.html

@szepeviktor
Copy link
Contributor

It's not that it is not supported but highly misleading if you put only the last word from the FQCN in PHPDoc.

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

No branches or pull requests

3 participants