SocialVariable   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 10
c 6
b 0
f 0
dl 0
loc 83
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getLoginUrl() 0 3 1
A loginAccounts() 0 8 2
A getLoginAccountByLoginProvider() 0 3 1
A getLoginAccountDisconnectUrl() 0 3 1
A getLoginProviders() 0 3 1
A getLoginAccountConnectUrl() 0 3 1
1
<?php
2
/**
3
 * @link      https://dukt.net/social/
4
 * @copyright Copyright (c) Dukt
5
 * @license   https://github.com/dukt/social/blob/v2/LICENSE.md
6
 */
7
8
namespace dukt\social\web\twig\variables;
9
10
use Craft;
11
use dukt\social\elements\db\LoginAccountQuery;
12
use dukt\social\elements\LoginAccount;
13
use dukt\social\Plugin;
14
15
/**
16
 * Class SocialVariable variable.
17
 *
18
 * @author  Dukt <[email protected]>
19
 * @since   1.0
20
 */
21
class SocialVariable
22
{
23
    // Public Methods
24
    // =========================================================================
25
26
    /**
27
     * Returns a new EntryQuery instance.
28
     *
29
     * @param mixed $criteria
30
     *
31
     * @return LoginAccountQuery
32
     */
33
    public function loginAccounts($criteria = null): LoginAccountQuery
34
    {
35
        $query = LoginAccount::find();
36
        if ($criteria) {
37
            Craft::configure($query, $criteria);
38
        }
39
40
        return $query;
41
    }
42
43
    /**
44
     * Get the login URL
45
     *
46
     * @param       $providerHandle
47
     * @param array $params
48
     *
49
     * @return string
50
     * @throws \yii\base\InvalidConfigException
51
     */
52
    public function getLoginUrl($providerHandle, array $params = [])
53
    {
54
        return Plugin::getInstance()->getLoginAccounts()->getLoginUrl($providerHandle, $params);
55
    }
56
57
    /**
58
     * Get the login account by provider handle
59
     *
60
     *
61
     * @return LoginAccount|null
62
     * @throws \yii\base\InvalidConfigException
63
     */
64
    public function getLoginAccountByLoginProvider(string $loginProviderHandle)
65
    {
66
        return Plugin::getInstance()->getLoginAccounts()->getLoginAccountByLoginProvider($loginProviderHandle);
67
    }
68
69
    /**
70
     * Get the login account connect URL
71
     *
72
     *
73
     * @return string
74
     * @throws \yii\base\InvalidConfigException
75
     */
76
    public function getLoginAccountConnectUrl(string $providerHandle)
77
    {
78
        return Plugin::getInstance()->getLoginAccounts()->getLoginAccountConnectUrl($providerHandle);
79
    }
80
81
    /**
82
     * Get the login account disconnect URL
83
     *
84
     *
85
     * @return string
86
     * @throws \yii\base\InvalidConfigException
87
     */
88
    public function getLoginAccountDisconnectUrl(string $providerHandle)
89
    {
90
        return Plugin::getInstance()->getLoginAccounts()->getLoginAccountDisconnectUrl($providerHandle);
91
    }
92
93
    /**
94
     * Get a list of login providers
95
     *
96
     * @param bool|true $enabledOnly
97
     *
98
     * @return array
99
     * @throws \yii\base\InvalidConfigException
100
     */
101
    public function getLoginProviders($enabledOnly = true)
102
    {
103
        return Plugin::getInstance()->getLoginProviders()->getLoginProviders($enabledOnly);
104
    }
105
}
106