amphp / amp

A non-blocking concurrency framework for PHP applications. 🐘
https://amphp.org/amp
MIT License
4.26k stars 257 forks source link

Adding documentation for static analysis tools #305

Open dantleech opened 4 years ago

dantleech commented 4 years ago

Hey,

Has any thought been given to supporting phpstan/psalm generics e.g.

class Foo
{
    /**
     * @return Promise<MyDomainThing>
     */
    public function wait(): Promise { // ... }
}

Otherewise, what's the best way to document a Promise that's compatible with SA tools?

Psalm has some stubs for Amp: https://github.com/vimeo/psalm/blob/master/src/Psalm/Internal/Stubs/Amp.php

enumag commented 4 years ago

See https://github.com/amphp/amp/pull/301

enumag commented 4 years ago

But yeah we might want to apply the rest of the Psalm stubs too.

razshare commented 2 years ago

It's been 2 years, but just to be clear you're trying to achieve something like this right? (using psalm) image

Psalm does it out of the box for me in VSCode, though you may want to disable autocompletion for Intelephense if you're using that plugin, it seems to conflict with psalm when it comes to PHPDocs ontop of duplicating some other autocompletions aswell.

Here's my psalm.xml, I hope it helps:

<?xml version="1.0"?>
<psalm
    errorLevel="7"
    resolveFromConfigFile="true"
    ensureArrayStringOffsetsExist="true"
    ensureArrayIntOffsetsExist="true"
    checkForThrowsInGlobalScope="true"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://getpsalm.org/schema/config"
    xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
    <projectFiles>
        <directory name="src" />
        <directory name="tests" />
        <ignoreFiles>
            <directory name="vendor" />
        </ignoreFiles>
    </projectFiles>
</psalm>

ps: I can't seem to get it working in PHPStorm (with psalm) unfortunately.