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