Cp   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 33
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 14 1
A beforeAction() 0 9 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\cp;
10
11
use Craft;
12
use craft\events\RegisterTemplateRootsEvent;
13
use craft\web\View;
14
use flipbox\organizations\Organizations;
15
use yii\base\Event;
16
use yii\base\Module as BaseModule;
17
use yii\web\NotFoundHttpException;
18
19
/**
20
 * @author Flipbox Factory <[email protected]>
21
 * @since 1.0.0
22
 *
23
 * @property Organizations $module
24
 */
25
class Cp extends BaseModule
26
{
27
    /**
28
     * @inheritdoc
29
     */
30
    public function init()
31
    {
32
        parent::init();
33
34
        // Base template directory
35
        Event::on(
36
            View::class,
37
            View::EVENT_REGISTER_CP_TEMPLATE_ROOTS,
38
            function (RegisterTemplateRootsEvent $e) {
39
                $e->roots['nested-element-index'] = Craft::$app->getPath()->getVendorPath() .
40
                    '/flipboxfactory/craft-elements-nested-index/src/templates';
41
            }
42
        );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function beforeAction($action)
49
    {
50
        if (!Craft::$app->request->getIsCpRequest()) {
51
            /** @noinspection PhpUnhandledExceptionInspection */
52
            throw new NotFoundHttpException();
53
        }
54
55
        return parent::beforeAction($action);
56
    }
57
}
58