Passed
Push — develop ( b5b90c...4239f4 )
by Andrew
07:40
created

Disqus::__construct()   A

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 nystudio107\disqus\services\DisqusService as DisqusService;
15
use nystudio107\disqus\variables\DisqusVariable;
16
use nystudio107\disqus\twigextensions\DisqusTwigExtension;
17
use nystudio107\disqus\models\Settings;
18
19
use Craft;
20
use craft\base\Plugin;
21
use craft\web\twig\variables\CraftVariable;
22
23
use yii\base\Event;
24
25
/**
26
 * Class Disqus
27
 *
28
 * @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...
29
 * @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...
30
 * @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...
31
 *
32
 * @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...
33
 */
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...
34
class Disqus extends Plugin
35
{
36
    // Static Properties
37
    // =========================================================================
38
39
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
40
     * @var Disqus
41
     */
42
    public static $plugin;
43
44
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
45
     * @var bool
46
     */
47
    public static $craft31 = false;
48
49
    // Public Properties
50
    // =========================================================================
51
52
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
53
     * @var string
54
     */
55
    public $schemaVersion = '1.0.0';
56
57
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
58
     * @var bool
59
     */
60
    public $hasCpSection = false;
61
62
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
63
     * @var bool
64
     */
65
    public $hasCpSettings = true;
66
67
    // Static Methods
68
    // =========================================================================
69
70
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $parent should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $id 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...
71
     * @inheritdoc
72
     */
73
    public function __construct($id, $parent = null, array $config = [])
74
    {
75
        $config['components'] = [
76
            'disqusService' => DisqusService::class,
77
        ];
78
79
        parent::__construct($id, $parent, $config);
80
    }
81
82
    // Public Methods
83
    // =========================================================================
84
85
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
86
     * @inheritdoc
87
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
88
    public function init()
89
    {
90
        parent::init();
91
        self::$plugin = $this;
92
93
        // Version helpers
94
        self::$craft31 = version_compare(Craft::$app->getVersion(), '3.1', '>=');
0 ignored issues
show
Documentation Bug introduced by
It seems like version_compare(Craft::a...Version(), '3.1', '>=') can also be of type integer. However, the property $craft31 is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
95
96
        Event::on(
97
            CraftVariable::class,
98
            CraftVariable::EVENT_INIT,
99
            function (Event $event) {
100
                /** @var CraftVariable $variable */
0 ignored issues
show
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
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...
101
                $variable = $event->sender;
102
                $variable->set('disqus', DisqusVariable::class);
103
            }
104
        );
105
106
        Craft::$app->view->registerTwigExtension(new DisqusTwigExtension());
107
108
        Craft::info(
109
            Craft::t(
110
                'disqus',
111
                '{name} plugin loaded',
112
                ['name' => $this->name]
113
            ),
114
            __METHOD__
115
        );
116
    }
117
118
    // Protected Methods
119
    // =========================================================================
120
121
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
122
     * @inheritdoc
123
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
124
    protected function createSettingsModel()
125
    {
126
        return new Settings();
127
    }
128
129
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
130
     * @inheritdoc
131
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
132
    protected function settingsHtml(): string
133
    {
134
        // Render our settings template
135
        return Craft::$app->view->renderTemplate(
136
            'disqus/settings',
137
            [
138
                'settings' => $this->getSettings(),
139
            ]
140
        );
141
    }
142
}
143