Issues (181)

src/Cookies.php (19 issues)

1
<?php
2
3
/**
4
 * Cookies plugin for Craft CMS
5
 *
6
 * @link      https://nystudio107.com/
0 ignored issues
show
The tag in position 1 should be the @copyright tag
Loading history...
7
 * @copyright Copyright (c) nystudio107
0 ignored issues
show
@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
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
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
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
26
 * @package   Cookies
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
27
 * @since     1.1.0
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
28
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
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
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
    /**
48
     * @var string
49
     */
50
    public string $schemaVersion = '1.0.0';
51
52
    /**
53
     * @var bool
54
     */
55
    public bool $hasCpSection = false;
56
57
    /**
58
     * @var bool
59
     */
60
    public bool $hasCpSettings = false;
61
62
    // Public Methods
63
    // =========================================================================
64
65
    /**
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
Missing short description in doc comment
Loading history...
78
     * @inheritdoc
79
     */
0 ignored issues
show
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 {
90
                /** @var CraftVariable $variable */
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
Missing @return tag in function comment
Loading history...
113
    public function getName(): string
114
    {
115
        return Craft::t('cookies', 'Cookies');
116
    }
117
}
118