Lever   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 75
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createSettingsModel() 0 3 1
A defineTemplateComponent() 0 3 1
A init() 0 25 1
A settingsHtml() 0 6 1
1
<?php
2
/**
3
 * Lever plugin for Craft CMS 3.x
4
 *
5
 * Craft + Lever.
6
 *
7
 * @link      https://workingconcept.com
8
 * @copyright Copyright (c) 2018 Working Concept Inc.
9
 */
10
11
namespace workingconcept\lever;
12
13
use workingconcept\lever\services\LeverService;
14
use workingconcept\lever\variables\LeverVariable;
15
use workingconcept\lever\models\Settings;
16
use Craft;
17
use craft\web\twig\variables\CraftVariable;
18
use yii\base\Event;
19
20
/**
21
 * Class Lever
22
 *
23
 * @author    Working Concept
24
 * @package   Lever
25
 * @since     1.0.0
26
 *
27
 * @property  LeverService $api
28
 */
29
class Lever extends \craft\base\Plugin
30
{
31
    /**
32
     * @var Lever
33
     */
34
    public static $plugin;
35
36
    /**
37
     * @var bool
38
     */
39
    public $hasCpSettings = true;
40
41
    /**
42
     * @var string
43
     */
44
    public $t9nCategory = 'lever';
45
46
    /**
47
     * @var string
48
     */
49
    public $schemaVersion = '1.0.0';
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function init()
55
    {
56
        parent::init();
57
        self::$plugin = $this;
58
59
        $this->setComponents([
60
            'api' => LeverService::class,
61
        ]);
62
63
        Event::on(
64
            CraftVariable::class,
65
            CraftVariable::EVENT_INIT,
66
            function (Event $event) {
67
                $variable = $event->sender;
68
                $variable->set('lever', LeverVariable::class);
69
            }
70
        );        
71
72
        Craft::info(
73
            Craft::t(
74
                'lever',
75
                '{name} plugin loaded',
76
                ['name' => $this->name]
77
            ),
78
            __METHOD__
79
        );
80
    }
81
82
    public function defineTemplateComponent()
83
    {
84
        return LeverVariable::class;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90
    protected function createSettingsModel()
91
    {
92
        return new Settings();
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98
    protected function settingsHtml(): string
99
    {
100
        return Craft::$app->view->renderTemplate(
101
            'lever/settings',
102
            [
103
                'settings' => $this->getSettings()
104
            ]
105
        );
106
    }
107
108
}
109