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

Cp   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 43
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeAction() 0 8 2
A getAvailableConnections() 0 15 2
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