Completed
Push — develop ( 6cec8f...ae3a0e )
by Nate
05:35
created

Cp::getAvailableConnections()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 12
cp 0
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\cp;
10
11
use Craft;
12
use flipbox\craft\hubspot\connections\SavableConnectionInterface;
13
use flipbox\craft\hubspot\events\RegisterConnectionsEvent;
14
use flipbox\hubspot\HubSpot;
15
use yii\base\Module as BaseModule;
16
use yii\web\NotFoundHttpException;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 *
22
 * @property HubSpot $module
23
 */
24
class Cp extends BaseModule
25
{
26
    /**
27
     * @var SavableConnectionInterface[]
28
     */
29
    private $registeredConnections;
30
31
    /**
32
     * @inheritdoc
33
     * @throws NotFoundHttpException
34
     */
35
    public function beforeAction($action)
36
    {
37
        if (!Craft::$app->request->getIsCpRequest()) {
38
            throw new NotFoundHttpException();
39
        }
40
41
        return parent::beforeAction($action);
42
    }
43
44
    /*******************************************
45
     * CONNECTIONS
46
     *******************************************/
47
48
    /**
49
     * @return SavableConnectionInterface[]
50
     */
51
    public function getAvailableConnections(): array
52
    {
53
        if ($this->registeredConnections === null) {
54
            $event = new RegisterConnectionsEvent();
55
56
            $this->trigger(
57
                $event::REGISTER_CONNECTIONS,
58
                $event
59
            );
60
61
            $this->registeredConnections = $event->connections;
62
        }
63
64
        return $this->registeredConnections;
65
    }
66
}
67