Passed
Push — develop ( d04037...1f3570 )
by Andrew
07:37
created

Cookies::__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
/**
4
 * Cookies plugin for Craft CMS 3.x
5
 *
6
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
7
 * @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...
8
 * @license   MIT License https://opensource.org/licenses/MIT
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...
10
11
namespace nystudio107\cookies;
12
13
use nystudio107\cookies\services\CookiesService;
14
use nystudio107\cookies\twigextensions\CookiesTwigExtension;
15
use nystudio107\cookies\variables\CookiesVariable;
16
17
use Craft;
18
use craft\base\Plugin;
19
use craft\web\twig\variables\CraftVariable;
20
21
use yii\base\Event;
22
23
/**
24
 * Class Cookies
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   Cookies
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.1.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  CookiesService    cookies
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 Cookies extends Plugin
33
{
34
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
35
     * @var Cookies
36
     */
37
    public static $plugin;
38
39
    // Public Properties
40
    // =========================================================================
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
43
     * @var string
44
     */
45
    public $schemaVersion = '1.0.0';
46
47
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
48
     * @var bool
49
     */
50
    public $hasCpSection = false;
51
52
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
53
     * @var bool
54
     */
55
    public $hasCpSettings = true;
56
57
    // Static Methods
58
    // =========================================================================
59
60
    /**
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...
61
     * @inheritdoc
62
     */
63
    public function __construct($id, $parent = null, array $config = [])
64
    {
65
        $config['components'] = [
66
            'cookies' => CookiesService::class,
67
        ];
68
69
        parent::__construct($id, $parent, $config);
70
    }
71
72
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
73
     * @inheritdoc
74
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
75
    public function init()
76
    {
77
        parent::init();
78
        self::$plugin = $this;
79
        $this->name = $this->getName();
80
81
        Event::on(
82
            CraftVariable::class,
83
            CraftVariable::EVENT_INIT,
84
            function (Event $event) {
85
                /** @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
The close comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
86
                $variable = $event->sender;
87
                $variable->set('cookies', CookiesVariable::class);
88
            }
89
        );
90
91
        // Add in our Twig extensions
92
        Craft::$app->view->registerTwigExtension(new CookiesTwigExtension());
93
94
        Craft::info(
95
            Craft::t(
96
                'cookies',
97
                '{name} plugin loaded',
98
                ['name' => $this->name]
99
            ),
100
            __METHOD__
101
        );
102
    }
103
104
    /**
105
     * Returns the user-facing name of the plugin, which can override the name
106
     * in composer.json
107
     *
108
     * @return string
109
     */
110
    public function getName()
111
    {
112
        return Craft::t('cookies', 'Cookies');
113
    }
114
}
115