ICalendar::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 10
1
<?php
2
/**
3
 * iCalendar plugin for Craft CMS 3.x
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
4
 *
5
 * Tools for parsing & formatting the RFC 2445 iCalendar (.ics) specification
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2018 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
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...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\icalendar;
12
13
use Craft;
14
use craft\base\Plugin;
15
use craft\web\twig\variables\CraftVariable;
16
use nystudio107\icalendar\services\Convert as ConvertService;
17
use nystudio107\icalendar\services\Parse as ParseService;
18
use nystudio107\icalendar\twigextensions\ICalendarTwigExtension;
19
use nystudio107\icalendar\variables\ICalendarVariable;
20
use yii\base\Event;
21
22
/**
23
 * Class ICalendar
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   ICalendar
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.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...
28
 *
29
 * @property  ConvertService $convert
0 ignored issues
show
Coding Style introduced by
Tag value for @property tag indented incorrectly; expected 1 spaces but found 2
Loading history...
30
 * @property  ParseService $parse
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 ICalendar extends Plugin
33
{
34
    // Static Properties
35
    // =========================================================================
36
37
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
38
     * @var ?ICalendar
39
     */
40
    public static ?ICalendar $plugin = null;
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
43
     * @var ?ICalendarVariable
44
     */
45
    public static ?ICalendarVariable $variable = null;
46
47
    // Public Properties
48
    // =========================================================================
49
50
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
51
     * @var string
52
     */
53
    public string $schemaVersion = '1.0.0';
54
55
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
56
     * @var bool
57
     */
58
    public bool $hasCpSection = false;
59
60
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
61
     * @var bool
62
     */
63
    public bool $hasCpSettings = false;
64
65
    // Public Methods
66
    // =========================================================================
67
68
    /**
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...
69
     * @inheritdoc
70
     */
71
    public function __construct($id, $parent = null, array $config = [])
72
    {
73
        $config['components'] = [
74
            'convert' => ConvertService::class,
75
            'parse' => ParseService::class,
76
        ];
77
78
        parent::__construct($id, $parent, $config);
79
    }
80
81
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
82
     * @inheritdoc
83
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
84
    public function init(): void
85
    {
86
        parent::init();
87
        self::$plugin = $this;
88
        self::$variable = new ICalendarVariable();
89
        // Register Twig extension
90
        Craft::$app->view->registerTwigExtension(new ICalendarTwigExtension());
91
        // Register variable
92
        Event::on(
93
            CraftVariable::class,
94
            CraftVariable::EVENT_INIT,
95
            static function(Event $event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
96
                /** @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...
97
                $variable = $event->sender;
98
                $variable->set('icalendar', self::$variable);
99
            }
100
        );
101
102
        Craft::info(
103
            Craft::t(
104
                'icalendar',
105
                '{name} plugin loaded',
106
                ['name' => $this->name]
107
            ),
108
            __METHOD__
109
        );
110
    }
111
112
    // Protected Methods
113
    // =========================================================================
114
}
115