YoutubeLiveEmbed::createSettingsModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * YouTube Live Embed plugin for Craft CMS
4
 *
5
 * This plugin allows you to embed a YouTube live stream and/or live chat on your webpage
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2019 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\youtubeliveembed;
12
13
use Craft;
14
use craft\base\Plugin;
15
use craft\web\twig\variables\CraftVariable;
16
use nystudio107\youtubeliveembed\models\Settings;
17
use nystudio107\youtubeliveembed\services\ServicesTrait;
18
use nystudio107\youtubeliveembed\variables\YoutubeLiveEmbedVariable;
19
use yii\base\Event;
20
21
/**
22
 * Class YoutubeLiveEmbed
23
 *
24
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
25
 * @package   YoutubeLiveEmbed
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
26
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
27
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
28
class YoutubeLiveEmbed extends Plugin
29
{
30
    // Traits
31
    // =========================================================================
32
33
    use ServicesTrait;
34
35
    // Static Properties
36
    // =========================================================================
37
38
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
39
     * @var YoutubeLiveEmbed
40
     */
41
    public static $plugin;
42
43
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
44
     * @var string
45
     */
46
    public static $youtubeChannelId;
47
48
    // Public Properties
49
    // =========================================================================
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
52
     * @var string
53
     */
54
    public $schemaVersion = '1.0.10';
55
56
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
57
     * @var bool
58
     */
59
    public $hasCpSection = false;
60
61
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
62
     * @var bool
63
     */
64
    public $hasCpSettings = true;
65
66
    // Public Methods
67
    // =========================================================================
68
69
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
70
     * @inheritdoc
71
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
72
    public function init()
73
    {
74
        parent::init();
75
        self::$plugin = $this;
76
        /** @var Settings $settings */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
77
        $settings = $this->getSettings();
78
        self::$youtubeChannelId = $settings->youtubeChannelId;
79
80
        Event::on(
81
            CraftVariable::class,
82
            CraftVariable::EVENT_INIT,
83
            function(Event $event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
84
                /** @var CraftVariable $variable */
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
85
                $variable = $event->sender;
86
                $variable->set('youtubelive', YoutubeLiveEmbedVariable::class);
87
            }
88
        );
89
90
        Craft::info(
91
            Craft::t(
92
                'youtubeliveembed',
93
                '{name} plugin loaded',
94
                ['name' => $this->name]
95
            ),
96
            __METHOD__
97
        );
98
    }
99
100
    // Protected Methods
101
    // =========================================================================
102
103
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
104
     * @inheritdoc
105
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
106
    protected function createSettingsModel()
107
    {
108
        return new Settings();
109
    }
110
111
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
112
     * @inheritdoc
113
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
114
    protected function settingsHtml(): string
115
    {
116
        return Craft::$app->view->renderTemplate(
117
            'youtubeliveembed/settings',
118
            [
119
                'settings' => $this->getSettings(),
120
            ]
121
        );
122
    }
123
}
124