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

Wrong namespaces generated in _ide_helper.php file #1659

Open
ayrtonandino opened this issue Jan 14, 2025 · 7 comments
Open

Wrong namespaces generated in _ide_helper.php file #1659

ayrtonandino opened this issue Jan 14, 2025 · 7 comments
Labels

Comments

@ayrtonandino
Copy link

Versions:

  • ide-helper Version: 3.5.3
  • Laravel Version: 11.37.0
  • PHP Version: 8.3.15

Description:

Recent version fixed namespaces for @template and phpdoc types, but there are some types still getting wrong namespaces prepended to them.

These are the ones I could find in _ide_helper.php file:

  • array shape => \Illuminate\Cache\array{ **shape** }, should be array{ **shape** }
  • \Closure => \Illuminate\Events\Queued\Closure, should be \Closure
  • specific string => \Illuminate\Foundation\'waterfall'|\Illuminate\Foundation\'aggressive' , should be 'waterfall'|'aggressive'
  • callable with function parameters => \Illuminate\Database\Eloquent\callable(something)| \Symfony\Component\HttpFoundation\callable(something) should be callable(something)

Examples of wrong namespaces:

array shape

/**
 * Retrieve an item from the cache by key, refreshing it in the background if it is stale.
 *
 * @template TCacheValue
 *
 * @param  string  $key
 * @param \Illuminate\Cache\array{  0: \DateTimeInterface|\DateInterval|int, 1: \DateTimeInterface|\DateInterval|int }  $ttl
 * @param  (callable(): TCacheValue)  $callback
 * @param \Illuminate\Cache\array{  seconds?: int, owner?: string }|null  $lock
 * @return TCacheValue
 *
 * @static
 */
public static function flexible($key, $ttl, $callback, $lock = null)
{
    /** @var \Illuminate\Cache\Repository $instance */
    return $instance->flexible($key, $ttl, $callback, $lock);
}
wrong

@param \Illuminate\Cache\array{ 0: \DateTimeInterface|\DateInterval|int, 1: \DateTimeInterface|\DateInterval|int } $ttl

correct

@param array{ 0: \DateTimeInterface|\DateInterval|int, 1: \DateTimeInterface|\DateInterval|int } $ttl

\Closure

/**
 * Register an event listener with the dispatcher.
 *
 * @param  \Illuminate\Events\Queued\Closure|callable|array|class-string|string  $events
 * @param  \Illuminate\Events\Queued\Closure|callable|array|class-string|null  $listener
 * @return void
 *
 * @static
 */
public static function listen($events, $listener = null)
{
    /** @var \Illuminate\Events\Dispatcher $instance */
    $instance->listen($events, $listener);
}
wrong

@param \Illuminate\Events\Queued\Closure|callable|array|class-string|string $events

correct

@param \Closure|callable|array|class-string|string $events

specific string

/**
 * Set the prefetching strategy.
 *
 * @param \Illuminate\Foundation\'waterfall'|\Illuminate\Foundation\'aggressive'|null $strategy
 * @param  array  $config
 * @return \Illuminate\Foundation\Vite
 *
 * @static
 */
public static function usePrefetchStrategy($strategy, $config = [])
{
    /** @var \Illuminate\Foundation\Vite $instance */
    return $instance->usePrefetchStrategy($strategy, $config);
}
wrong

@param \Illuminate\Foundation\'waterfall'|\Illuminate\Foundation\'aggressive'|null $strategy

correct

@param 'waterfall'|'aggressive'|null $strategy

callable

/**
 * Chunk the results of the query.
 *
 * @param  int  $count
 * @param  \Illuminate\Database\Eloquent\callable(\Illuminate\Support\Collection<int, TValue>, int):  mixed  $callback
 * @return bool
 *
 * @static
 */
public static function chunk($count, $callback)
{
    /** @var \Illuminate\Database\Eloquent\Builder $instance */
    return $instance->chunk($count, $callback);
}
wrong

@param \Illuminate\Database\Eloquent\callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback

correct

@param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback

@barryvdh
Copy link
Owner

@chack1172 can you check?

@chack1172
Copy link
Contributor

@barryvdh I can take a look in the weekend. We should fix them in ReflectionDocBlock.

@chack1172
Copy link
Contributor

@barryvdh fixed in ReflectionDocBlock: barryvdh/ReflectionDocBlock#27

@barryvdh
Copy link
Owner

Merged and tagged, thanks!

@ayrtonandino
Copy link
Author

Tested with barryvdh/[email protected], works great, only thing missing is \Closure, only in this method:

/**
 * @see \Illuminate\Events\Dispatcher
 * @see \Illuminate\Support\Testing\Fakes\EventFake
 */
class Event
{
    /**
     * Register an event listener with the dispatcher.
     *
     * @param  \Illuminate\Events\Queued\Closure|callable|array|class-string|string  $events
     * @param  \Illuminate\Events\Queued\Closure|callable|array|class-string|null  $listener
     * @return void
     *
     * @static
     */
    public static function listen($events, $listener = null)
    {
        /** @var \Illuminate\Events\Dispatcher $instance */
        $instance->listen($events, $listener);
    }

   ...

Looking at Illuminate\Events\Dispatcher, listen method has the following types:

/**
 * Register an event listener with the dispatcher.
 *
 * @param  \Illuminate\Events\QueuedClosure|callable|array|class-string|string  $events
 * @param  \Illuminate\Events\QueuedClosure|callable|array|class-string|null  $listener
 * @return void
 */
public function listen($events, $listener = null)

So in this case, \Illuminate\Events\Queued\Closure should be \Illuminate\Events\QueuedClosure

@chack1172
Copy link
Contributor

@barryvdh this change is causing the last issue. Do you remember what was it for?
97a16c9#diff-6496b5955fed1ad5fac954f2a7c211dd225b3a780c8251ed87f4d73e4b19f2e3R219

@ayrtonandino
Copy link
Author

I went to my vendors folder and commented out those 3 lines, everything works as expected, including the QueuedClosure

vendor\barryvdh\laravel-ide-helper\src\Method.php

protected function convertKeywords($string)
{
    // $string = str_replace('\Closure', 'Closure', $string);
    // $string = str_replace('Closure', '\Closure', $string);
    // $string = str_replace('dynamic', 'mixed', $string);

    return $string;
}

I also didn't see any dynamic in _ide_helper.php, _ide_helper_models.php, .phpstorm.meta.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants