Search code examples
phpwordpressgoogle-analyticsgoogle-analytics-api

Fatal error: Uncaught Error: Google\Auth\HttpHandler\HttpHandlerFactory::build()


I have two plugins MyPluginOne and MyPluginTwo. In MyPluginTwo Plugin when I configure my social login as Google (Login as Google), I get following error:

Fatal error: Uncaught Error: Google\Auth\HttpHandler\HttpHandlerFactory::build(): Argument #1 ($client) must be of type ?GuzzleHttp\ClientInterface, MyPluginOne\GuzzleHttp\Client given, called in C:\Users\WPB\Local Sites\MyPluginOne-google-login\app\public\wp-content\plugins\wp-MyPluginOne\lib\Google-GA4\vendor\google\apiclient\src\Client.php on line 220 in C:\Users\WPB\Local Sites\MyPluginOne-google-login\app\public\wp-content\plugins\MyPluginTwo-pro\addons\social-login\sdk\google-client\vendor\google\auth\src\HttpHandler\HttpHandlerFactory.php on line 34

I have worked on this by changing the MyPluginOne\GuzzleHttp\Client to GuzzleHttp\Client on which class already declared comes up. The namespaces are added to the MyPluginOne plugin using php-scoper and the scoper-inc.php code is:

<?php

declare (strict_types=1);
namespace MyPluginOne;

// scoper.inc.php
use MyPluginOne\Isolated\Symfony\Component\Finder\Finder;
return [
    'prefix' => 'MyPluginOne',
    // string|null
    'output-dir' => null,
    // string|null
    'finders' => [],
    // list<Finder>
    'patchers' => [],
    // list<callable(string $filePath, string $prefix, string $contents): string>
    'exclude-files' => [],
    // list<string>
    'exclude-namespaces' => ['Google\\', 'Grpc\\', 'Composer\\'],
    // list<string|regex>
    'exclude-constants' => [],
    // list<string|regex>
    'exclude-classes' => [],
    // list<string|regex>
    'exclude-functions' => [],
    // list<string|regex>
    'expose-global-constants' => \true,
    // bool
    'expose-global-classes' => \true,
    // bool
    'expose-global-functions' => \true,
    // bool
    'expose-namespaces' => [],
    // list<string|regex>
    'expose-constants' => [],
    // list<string|regex>
    'expose-classes' => [],
    // list<string|regex>
    'expose-functions' => [],
];

Now I want guidance in the issue that in which plugin I have to resolve the namespace issue and how can I solve the issue within MyPluginOne?

When I added namespaces to MyPluginTwo its own functionality breakdown then which is separate issue. Moreover, as I uninstall Analytfiy my Login as Google starts to work fine. But I need both plugins.


Solution

  • The issue was fixed. I first updated the libraries. Secondly I excluded the following namespaces to be namespace in the php-scoper:

    'exclude-namespaces' => ['Google\\', 'Grpc\\', 'Composer\\', 'GuzzleHttp\\', 'Monolog\\', 'Psr\\']
    

    Now my plugin has no conflict issue with the Social Login Plugins and issue is resolved.