Issues (174)

src/Library/Hybridauth/Hybridauth.php (1 issue)

1
<?php
2
3
namespace ByTIC\Hello\Library\Hybridauth;
4
5
use Exception;
6
use Hybrid_Auth;
7
use Nip\Router\Generator\UrlGenerator;
8
use function Nip\url;
9
use Nip\Utility\Traits\SingletonTrait;
10
11
/**
12
 * Class Hybridauth
13
 * @package KM42\Hello\Library\Hybridauth
14
 */
15
class Hybridauth
16
{
17
    use SingletonTrait;
18
19
    protected $hybridauth = null;
20
21
    /**
22
     * @param $provider
23
     * @return \Hybrid_User_Profile
24
     */
25
    public function authenticate($provider, $params = null)
26
    {
27
        try {
28
            /** @var \Hybrid_Provider_Model $adapter */
29
            $adapter = $this->getAuth()::authenticate($provider, $params);
30
            // then grab the user profile
31
            return $adapter->getUserProfile();
32
        } catch (Exception $e) {
33
            /** @noinspection PhpIncompatibleReturnTypeInspection */
34
            return $e;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $e returns the type Exception which is incompatible with the documented return type Hybrid_User_Profile.
Loading history...
35
        }
36
    }
37
38
    /**
39
     * @return null|Hybrid_Auth
40
     */
41
    public function getAuth()
42
    {
43
        if ($this->hybridauth === null) {
44
            $this->initAuth();
45
        }
46
47
        return $this->hybridauth;
48
    }
49
50
    protected function initAuth()
51
    {
52
        $config = config('hybridauth');
53
        $config['base_url'] = url()->generate('frontend.o_auth', [], UrlGenerator::ABSOLUTE_URL);
54
        $this->hybridauth = new Hybrid_Auth($config->toArray());
55
    }
56
}
57