Disqus::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 * Disqus plugin for Craft CMS 3.x
4
 *
5
 * Integrates the Disqus commenting system into Craft 3 websites, including
6
 * Single Sign On (SSO) and custom login/logout URLs
7
 *
8
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
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...
11
12
namespace nystudio107\disqus;
13
14
use Craft;
15
use craft\base\Plugin;
16
use craft\web\twig\variables\CraftVariable;
17
use nystudio107\disqus\models\Settings;
18
use nystudio107\disqus\services\DisqusService;
19
use nystudio107\disqus\twigextensions\DisqusTwigExtension;
20
use nystudio107\disqus\variables\DisqusVariable;
21
use yii\base\Event;
22
23
/**
24
 * Class Disqus
25
 *
26
 * @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...
27
 * @package   Disqus
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
28
 * @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...
29
 *
30
 * @property  DisqusService $disqusService
0 ignored issues
show
Coding Style introduced by
Tag value for @property tag indented incorrectly; expected 1 spaces but found 2
Loading history...
31
 */
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...
32
class Disqus extends Plugin
33
{
34
    // Static Properties
35
    // =========================================================================
36
37
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
38
     * @var ?Disqus
39
     */
40
    public static ?Disqus $plugin = null;
41
42
    // Public Properties
43
    // =========================================================================
44
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
46
     * @var string
47
     */
48
    public string $schemaVersion = '1.0.0';
49
50
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
51
     * @var bool
52
     */
53
    public bool $hasCpSection = false;
54
55
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
56
     * @var bool
57
     */
58
    public bool $hasCpSettings = true;
59
60
    // Static Methods
61
    // =========================================================================
62
63
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $id should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $parent should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $config should have a doc-comment as per coding-style.
Loading history...
64
     * @inheritdoc
65
     */
66
    public function __construct($id, $parent = null, array $config = [])
67
    {
68
        $config['components'] = [
69
            'disqusService' => DisqusService::class,
70
        ];
71
72
        parent::__construct($id, $parent, $config);
73
    }
74
75
    // Public Methods
76
    // =========================================================================
77
78
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
79
     * @inheritdoc
80
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
81
    public function init(): void
82
    {
83
        parent::init();
84
        self::$plugin = $this;
85
        Event::on(
86
            CraftVariable::class,
87
            CraftVariable::EVENT_INIT,
88
            static function(Event $event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
89
                /** @var CraftVariable $variable */
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...
90
                $variable = $event->sender;
91
                $variable->set('disqus', DisqusVariable::class);
92
            }
93
        );
94
        Craft::$app->view->registerTwigExtension(new DisqusTwigExtension());
95
        Craft::info(
96
            Craft::t(
97
                'disqus',
98
                '{name} plugin loaded',
99
                ['name' => $this->name]
100
            ),
101
            __METHOD__
102
        );
103
    }
104
105
    // Protected Methods
106
    // =========================================================================
107
108
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
109
     * @inheritdoc
110
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
111
    protected function createSettingsModel(): Settings
112
    {
113
        return new Settings();
114
    }
115
116
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
117
     * @inheritdoc
118
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
119
    protected function settingsHtml(): ?string
120
    {
121
        // Render our settings template
122
        return Craft::$app->view->renderTemplate(
123
            'disqus/settings',
124
            [
125
                'settings' => $this->getSettings(),
126
            ]
127
        );
128
    }
129
}
130