BrianHenryIE / strauss

Prefix PHP namespaces and classnames to allow multiple versions of libraries to exist without conflict.
https://brianhenryie.github.io/strauss/
MIT License
143 stars 23 forks source link

Update prefixes in function document #111

Closed ravinderk closed 2 weeks ago

ravinderk commented 4 months ago

I found that the function document does not update which creates a false flag with tools like PHPStan. I expect it to auto-update @param and @return in the function document.

image
BrianHenryIE commented 4 months ago

That makes sense. Please include an example composer.json and specific file lines that can be used in a test.

ravinderk commented 4 months ago

That makes sense. Please include an example composer.json and specific file lines that can be used in a test.

I noticed PHP tags (@param, @return) in function description updates. The only issue I see when variable type is in <> like Collection<\Stripe\Payout>

BrianHenryIE commented 4 months ago

Please include an example composer.json and specific file lines that can be used in a test.

I don't know what the name of the package you're referring to is. I need to recreate this if I am to fix it.

The only issue I see when variable type is in <> like Collection<\Stripe\Payout>

File and line number would be hugely helpful here.

ravinderk commented 4 months ago

Please include an example composer.json and specific file lines that can be used in a test.

I don't know what the name of the package you're referring to is. I need to recreate this if I am to fix it.

The only issue I see when variable type is in <> like Collection<\Stripe\Payout>

File and line number would be hugely helpful here.

@BrianHenryIE this is line: https://github.com/stripe/stripe-php/blob/dbcb2820703dd36f6375c7b3c5bf696bd0cff260/lib/Payout.php#L107

BrianHenryIE commented 1 month ago

I just wrote a test to try to address this but it is behaving as desired for me

    /**
     * Returns a list of existing payouts sent to third-party bank accounts or payouts
     * that Stripe sent to you. The payouts return in sorted order, with the most
     * recently created payouts appearing first.
     *
     * @param null|array $params
     * @param null|array|string $opts
     *
     * @throws \Strauss\Issue111\Stripe\Exception\ApiErrorException if the request fails
     *
     * @return \Strauss\Issue111\Stripe\Collection<\Stripe\Payout> of ApiResources
     */
    public static function all($params = null, $opts = null)
    {
        $url = static::classUrl();

        return static::_requestPage($url, \Strauss\Issue111\Stripe\Collection::class, $params, $opts);
    }

Is this maybe a case of PhpStorm's rendering of the PhpDoc hiding the full namespace?

Test:

<?php
/**
 * Should prefix modified classnames in phpdoc
 *
 * @see https://github.com/BrianHenryIE/strauss/pull/111
 */

namespace BrianHenryIE\Strauss\Tests\Issues;

use BrianHenryIE\Strauss\Tests\Integration\Util\IntegrationTestCase;

/**
 * @package BrianHenryIE\Strauss\Tests\Issues
 * @coversNothing
 */
class StraussIssue111Test extends IntegrationTestCase
{
    public function test_phpdoc()
    {
        $composerJsonString = <<<'EOD'
{
  "name": "strauss/issue111",
  "require": {
    "stripe/stripe-php": "16.1.0"
  },
  "extra": {
    "strauss": {
      "namespace_prefix": "Strauss\\Issue111\\"
    }
  }
}
EOD;

        chdir($this->testsWorkingDir);

        file_put_contents($this->testsWorkingDir . '/composer.json', $composerJsonString);

        exec('composer install');

        $this->runStrauss();

        $php_string = file_get_contents($this->testsWorkingDir . '/vendor-prefixed/stripe/stripe-php/lib/Payout.php');

        self::assertStringNotContainsString('@throws \Stripe\Exception\ApiErrorException', $php_string);
        self::assertStringContainsString('@throws \Strauss\Issue111\Stripe\Exception\ApiErrorException', $php_string);
    }
}
BrianHenryIE commented 2 weeks ago

Fixed in v0.20.0

ravinderk commented 2 weeks ago

@BrianHenryIE thank you