Skip to content

Macros for Http facade doesn't work well #1702

@MorganGonzales

Description

@MorganGonzales

Versions:

  • ide-helper Version: 3.1.0
  • Laravel Version: 10.48.29
  • PHP Version: 8.1.28

Description:

I tried to create an Http macro inside the the boot method of my AppServiceProvider.php

        Http::macro('my_macro', function (array $headers = []): PendingRequest {
            $default_headers = [
                'Content-Type' => 'application/json',
            ];

            return Http::withHeaders(array_merge($default_headers, $headers))
                ->withToken(config('services.some_service.api_token'))
                ->baseUrl(config('services.some_service.api_url'))
                ->connectTimeout(config('services.some_service.connect_timeout', 5))
                ->timeout(config('services.some_service.timeout', 5));
        });

However, when I ran the php artisan ide-helper:generate, it seems the macro "my_macro" was created under the Illuminate\Http\Client\Factory class, instead of the Illuminate\Support\Facades\Http.

namespace Illuminate\Http\Client {
            /**
     * 
     *
     * @mixin \Illuminate\Http\Client\PendingRequest
     */        class Factory {
                    /**
         * 
         *
         * @see \App\Providers\AppServiceProvider::initializeMacrosForHttp()
         * @param array $headers
         * @return \Illuminate\Http\Client\PendingRequest 
         * @static 
         */        public static function my_macro($headers = [])
        {
                        return \Illuminate\Http\Client\Factory::my_macro($headers);
        }
            }
    }

The autocomplete (using PHPStorm) works when calling Illuminate\Http\Client\Factory::my_macro, but not on Illuminate\Support\Facades\Http::my_macro.

I'm not sure if is this the desired behavior? As the Http facade is a wrapper to the Illuminate\Http\Client\Factory class or was this fixed in the recent versions?

Please ignore or close if this is due to me using an outdated version

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions