Completed
Push — master ( 1589ee...153d10 )
by Nate
08:23
created

LimitsController::getBaseCpPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
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://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\cp\controllers\view;
10
11
use flipbox\craft\hubspot\criteria\HubCriteria;
12
use flipbox\craft\hubspot\transformers\DynamicModelResponse;
13
use yii\web\Response;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class LimitsController extends AbstractController
20
{
21
    /**
22
     * The template base path
23
     */
24
    const TEMPLATE_BASE = parent::TEMPLATE_BASE . '/limits';
25
26
    /**
27
     * The index view template path
28
     */
29
    const TEMPLATE_INDEX = self::TEMPLATE_BASE . '/index';
30
31
    /**
32
     * @return Response
33
     */
34
    public function actionIndex(): Response
35
    {
36
        $variables = [];
37
        $this->baseVariables($variables);
38
39
        if (null !== ($connection = $this->findActiveConnection())) {
40
            $criteria = new HubCriteria([
41
                'connection' => $connection->getConnection()
42
            ]);
43
44
            $model = call_user_func_array(
45
                new DynamicModelResponse(),
46
                [
47
                    $criteria->dailyLimit()
48
                ]
49
            );
50
        }
51
52
        $variables['limits'] = $model ?? $this->invalidConnectionModel();
53
54
        return $this->renderTemplate(
55
            static::TEMPLATE_INDEX,
56
            $variables
57
        );
58
    }
59
60
    /*******************************************
61
     * BASE PATHS
62
     *******************************************/
63
64
    /**
65
     * @return string
66
     */
67
    protected function getBaseCpPath(): string
68
    {
69
        return parent::getBaseCpPath() . '/limits';
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    protected function getBaseActionPath(): string
76
    {
77
        return parent::getBaseActionPath() . '/limits';
78
    }
79
}
80