Patron::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 0
cts 35
cp 0
rs 9.232
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/patron-hubspot/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/patron-hubspot/
7
 */
8
9
namespace flipbox\patron\hubspot;
10
11
use craft\base\Plugin;
12
use flipbox\craft\ember\modules\LoggerTrait;
13
use flipbox\craft\hubspot\cp\Cp as HubSpotCp;
14
use flipbox\craft\hubspot\events\RegisterConnectionsEvent;
15
use flipbox\patron\cp\Cp as PatronCp;
16
use flipbox\patron\events\RegisterProviderInfo;
17
use flipbox\patron\events\RegisterProviders;
18
use flipbox\patron\events\RegisterProviderSettings;
19
use flipbox\patron\hubspot\connections\PatronConnection;
20
use flipbox\patron\hubspot\settings\HubSpotSettings;
21
use Flipbox\OAuth2\Client\Provider\HubSpot;
22
use yii\base\Event;
23
24
/**
25
 * @author Flipbox Factory <[email protected]>
26
 * @since 1.0.0
27
 */
28
class Patron extends Plugin
29
{
30
    use LoggerTrait;
31
32
    /**
33
     * @return string
34
     */
35
    protected static function getLogFileName(): string
36
    {
37
        return 'patron';
38
    }
39
40
    /**
41
     * @inheritdocfind
42
     */
43
    public function init()
44
    {
45
        parent::init();
46
47
        // OAuth2 Provider
48
        Event::on(
49
            PatronCp::class,
50
            RegisterProviders::REGISTER_PROVIDERS,
51
            function (RegisterProviders $event) {
52
                $event->providers[] = HubSpot::class;
53
            }
54
        );
55
56
        // OAuth2 Provider Settings
57
        Event::on(
58
            HubSpot::class,
59
            RegisterProviderSettings::REGISTER_SETTINGS,
60
            function (RegisterProviderSettings $event) {
61
                $event->class = HubSpotSettings::class;
62
            }
63
        );
64
65
        // OAuth2 Provider Icon
66
        Event::on(
67
            PatronCp::class,
68
            RegisterProviderInfo::REGISTER_INFO,
69
            function (RegisterProviderInfo $event) {
70
                $event->info[HubSpot::class] = [
71
                    'name' => 'HubSpot',
72
                    'icon' => '@vendor/flipboxfactory/patron-hubspot/icons/hubspot.svg'
73
                ];
74
            }
75
        );
76
77
        // Connection settings
78
        Event::on(
79
            HubSpotCp::class,
80
            RegisterConnectionsEvent::REGISTER_CONNECTIONS,
81
            function (RegisterConnectionsEvent $event) {
82
                $event->connections[] = PatronConnection::class;
83
            }
84
        );
85
    }
86
}
87