Test Failed
Push — master ( 62e8aa...e74fb5 )
by Julien
04:23
created

ServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 18
c 3
b 0
f 0
dl 0
loc 29
ccs 0
cts 17
cp 0
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 25 4
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Provider\Oauth2Facebook;
13
14
use League\OAuth2\Client\Provider\Facebook;
15
use Phalcon\Di\DiInterface;
16
use Phalcon\Session\Manager;
17
use Zemit\Config\ConfigInterface;
18
use Zemit\Http\Request;
19
use Zemit\Provider\AbstractServiceProvider;
20
21
/**
22
 * @link https://github.com/tegaphilip/padlock
23
 * @link https://oauth2.thephpleague.com/framework-integrations/
24
 */
25
class ServiceProvider extends AbstractServiceProvider
26
{
27
    protected string $serviceName = 'oauth2Facebook';
28
    
29
    public function register(DiInterface $di): void
30
    {
31
        $di->setShared($this->getName(), function () use ($di) {
32
    
33
            $config = $di->get('config');
34
            assert($config instanceof ConfigInterface);
35
    
36
            $session = $di->get('session');
37
            assert($session instanceof Manager);
38
    
39
            $request = $di->get('request');
40
            assert($request instanceof Request);
41
            
42
            $oauthConfig = $config->pathToArray('oauth2') ?? [];
43
            $oauthFacebookConfig = $oauthConfig['facebook'] ?? [];
44
            
45
            // Set the full url
46
            $secure = $request->isSecure();
47
            $scheme = $request->getScheme() . '://';
48
            $host = $request->getHttpHost();
49
            $port = $request->getPort();
50
            $port = ($port !== $secure ? '443' : '80') ? ':' . $port : null;
51
            $oauthFacebookConfig['redirectUri'] = $scheme . $host . $port . ($oauthFacebookConfig['redirectUri'] ?: '');
52
            
53
            return new Facebook($oauthFacebookConfig);
54
        });
55
    }
56
}
57