Passed
Push — v1 ( 50544a...1d78fb )
by Andrew
06:16 queued 13s
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
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) 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 Craft;
14
use craft\base\Plugin;
15
use craft\web\twig\variables\CraftVariable;
16
use nystudio107\cookies\services\ServicesTrait;
17
use nystudio107\cookies\twigextensions\CookiesTwigExtension;
18
use nystudio107\cookies\variables\CookiesVariable;
19
use yii\base\Event;
20
21
/**
22
 * Class Cookies
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   Cookies
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.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...
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 Cookies extends Plugin
29
{
30
    // Traits
31
    // =========================================================================
32
33
    use ServicesTrait;
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
36
     * @var Cookies
37
     */
38
    public static $plugin;
39
40
    // Public Properties
41
    // =========================================================================
42
43
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
44
     * @var string
45
     */
46
    public $schemaVersion = '1.0.0';
47
48
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
49
     * @var bool
50
     */
51
    public $hasCpSection = false;
52
53
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
54
     * @var bool
55
     */
56
    public $hasCpSettings = false;
57
58
    // Public Methods
59
    // =========================================================================
60
61
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
62
     * @inheritdoc
63
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
64
    public function init()
65
    {
66
        parent::init();
67
        self::$plugin = $this;
68
        $this->name = $this->getName();
69
70
        Event::on(
71
            CraftVariable::class,
72
            CraftVariable::EVENT_INIT,
73
            function(Event $event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
74
                /** @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...
75
                $variable = $event->sender;
76
                $variable->set('cookies', CookiesVariable::class);
77
            }
78
        );
79
80
        // Add in our Twig extensions
81
        Craft::$app->view->registerTwigExtension(new CookiesTwigExtension());
82
83
        Craft::info(
84
            Craft::t(
85
                'cookies',
86
                '{name} plugin loaded',
87
                ['name' => $this->name]
88
            ),
89
            __METHOD__
90
        );
91
    }
92
93
    /**
94
     * Returns the user-facing name of the plugin, which can override the name
95
     * in composer.json
96
     *
97
     * @return string
98
     */
99
    public function getName()
100
    {
101
        return Craft::t('cookies', 'Cookies');
102
    }
103
}
104