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

Improve auto IDE support of reveal #448

Closed
mpoiriert opened this issue Oct 21, 2019 · 6 comments
Closed

Improve auto IDE support of reveal #448

mpoiriert opened this issue Oct 21, 2019 · 6 comments

Comments

@mpoiriert
Copy link

I am using PHPStorm and using prophecy (via PHPUnit) cause a lot of warning because on wrong argument when using the reveal return value directly.

What I end up doing it this:

$prophecy = $this->prophesize(Connection::class);
// ...
/** @var Connection $connection */
$connection = $prophecy->reveal();
$object = new Object($connection);

To do this a bit "cleaner" a and using the phpstorm.meta this could be change to

$prophecy = $this->prophesize(Connection::class);
// ...
$object = new Object($ $prophecy->reveal(Connection::class));

This work but I have a warning because the reveal method doesn't have any argument.

Adding a file .phpstorm.meta.php with this would solve that

<?php namespace PHPSTORM_META {

    $STATIC_METHOD_TYPES = [
        \Prophecy\Prophecy\ObjectProphecy::reveal('') => [
            "" == "@",
        ],
    ];
}

namespace Prophecy\Prophecy {
    class ObjectProphecy
    {
        public function reveal(string $class = null)
        {

        }
    }
}
@sstok
Copy link
Contributor

sstok commented Dec 1, 2019

Given you use PHPUnit, this plug-in might help you : https://plugins.jetbrains.com/plugin/9674-phpunit-enhancement/ 👍

@ciaranmcnulty
Copy link
Member

@mpoiriert I don't know how phpstorm does this, you're saying we can add this to our project and it'll be found in the vendor folder?

@mpoiriert
Copy link
Author

@ciaranmcnulty Yes exactly. I tested it by putting this file manually in the vendor/phpspec/prophecy direcoty and it worked.

You can read about it here https://blog.jetbrains.com/phpstorm/2019/02/new-phpstorm-meta-php-features/

But the plugin that @sstok mention is working great. So it might be better to recommend it on the ream me documentation instead of adding the file...

@danepowell
Copy link
Contributor

PhpStorm handles Prophecy objects natively now (pretty well, not perfectly). I'm not sure what value that plugin adds. Maybe this issue can be closed.

@mpoiriert
Copy link
Author

No body seems to care and I am not using prophecy anymore so I will close it.

@stof
Copy link
Member

stof commented May 23, 2023

We indeed solved this by using generics, which makes it work for any static analysis tool supporting them instead of only solving it for phpstorm.

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

5 participants