Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractSocialLoginController
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
7
1<?php
2
3namespace Miniframe\SocialLogin\Controller;
4
5use Miniframe\Core\AbstractController;
6use Miniframe\Core\Config;
7use Miniframe\Core\Request;
8use Miniframe\SocialLogin\Middleware\SocialLogin;
9
10abstract class AbstractSocialLoginController extends AbstractController
11{
12    /**
13     * Config value of dark mode
14     *
15     * @var string
16     */
17    protected $darkmode = 'off';
18    /**
19     * Reference to the Social Login middleware.
20     *
21     * @var SocialLogin
22     */
23    protected $socialLogin;
24    /**
25     * Base URL for the Social Login pages.
26     *
27     * @var string
28     */
29    protected $socialLoginPrefixUrl;
30
31    /**
32     * Initializes a Social Login controller
33     *
34     * @param Request     $request              Reference to the Request object.
35     * @param Config      $config               Reference to the Config object.
36     * @param SocialLogin $socialLogin          Reference to the Social Login middleware.
37     * @param string      $socialLoginPrefixUrl Base URL for the Social Login pages.
38     */
39    public function __construct(
40        Request $request,
41        Config $config,
42        SocialLogin $socialLogin,
43        string $socialLoginPrefixUrl
44    ) {
45        parent::__construct($request, $config);
46        $this->socialLogin = $socialLogin;
47        $this->socialLoginPrefixUrl = $socialLoginPrefixUrl;
48
49        // Dark mode configuration
50        if ($config->has('sociallogin', 'darkmode')) {
51            if (
52                $config->get('sociallogin', 'darkmode') === false
53                || strtolower($config->get('sociallogin', 'darkmode')) == 'off'
54            ) {
55                $this->darkmode = 'off';
56            } elseif (
57                $config->get('sociallogin', 'darkmode') === true
58                || strtolower($config->get('sociallogin', 'darkmode')) == 'on'
59            ) {
60                $this->darkmode = 'on';
61            } elseif (
62                strtolower($config->get('sociallogin', 'darkmode')) == 'auto'
63            ) {
64                $this->darkmode = 'auto';
65            } else {
66                throw new \RuntimeException('Invalid Dark Mode flag: ' . $config->get('sociallogin', 'darkmode'));
67            }
68        }
69    }
70}