Passed
Push — develop ( d665f5...608efd )
by Andrew
19:14 queued 15:01
created

Similar::__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
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * Similar plugin for Craft CMS 3.x
4
 *
5
 * Similar for Craft lets you find elements, Entries, Categories, Commerce Products, etc, that are similar, based on... other related elements.
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.com
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\similar;
12
13
use craft\base\Element;
14
use nystudio107\similar\behaviors\CountBehavior;
15
use nystudio107\similar\services\Similar as SimilarService;
16
use nystudio107\similar\variables\SimilarVariable;
17
18
use Craft;
19
use craft\base\Plugin;
20
use craft\elements\db\ElementQuery;
21
use craft\events\PluginEvent;
22
use craft\events\PopulateElementEvent;
23
use craft\services\Plugins;
24
use craft\web\twig\variables\CraftVariable;
25
26
use yii\base\Event;
27
28
/**
29
 * Class Similar
30
 *
31
 * @author    nystudio107.com
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...
32
 * @package   Similar
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
33
 * @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...
34
 *
35
 * @property  SimilarService $similar
0 ignored issues
show
Coding Style introduced by
Tag value for @property tag indented incorrectly; expected 1 spaces but found 2
Loading history...
36
 */
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...
37
class Similar extends Plugin
38
{
39
    // Static Properties
40
    // =========================================================================
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
43
     * @var Similar
44
     */
45
    public static $plugin;
46
47
    // Static Methods
48
    // =========================================================================
49
50
    /**
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...
51
     * @inheritdoc
52
     */
53
    public function __construct($id, $parent = null, array $config = [])
54
    {
55
        $config['components'] = [
56
            'similar' => SimilarService::class,
57
        ];
58
59
        parent::__construct($id, $parent, $config);
60
    }
61
62
    // Public Properties
63
    // =========================================================================
64
65
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
66
     * @var string
67
     */
68
    public $schemaVersion = '1.0.0';
69
70
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
71
     * @var bool
72
     */
73
    public $hasCpSection = false;
74
75
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
76
     * @var bool
77
     */
78
    public $hasCpSettings = false;
79
80
    // Public Methods
81
    // =========================================================================
82
83
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
84
     * @inheritdoc
85
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
86
    public function init()
87
    {
88
        parent::init();
89
        self::$plugin = $this;
90
91
        Event::on(
92
            CraftVariable::class,
93
            CraftVariable::EVENT_INIT,
94
            function (Event $event) {
95
                /** @var CraftVariable $variable */
0 ignored issues
show
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
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...
96
                $variable = $event->sender;
97
                $variable->set('similar', SimilarVariable::class);
98
            }
99
        );
100
101
        Event::on(
102
            ElementQuery::class,
103
            ElementQuery::EVENT_AFTER_POPULATE_ELEMENT,
104
            function(PopulateElementEvent $event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
105
                $element = $event->element;
106
                /** @var Element $element */
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...
107
                $element->attachBehavior('myCountBehavior', CountBehavior::class);
108
        });
0 ignored issues
show
Coding Style introduced by
Closing brace indented incorrectly; expected 12 spaces, found 8
Loading history...
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 8
Loading history...
109
110
        Event::on(
111
            Plugins::class,
112
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
113
            function (PluginEvent $event) {
114
                if ($event->plugin === $this) {
115
                }
116
            }
117
        );
118
119
        Craft::info(
120
            Craft::t(
121
                'similar',
122
                '{name} plugin loaded',
123
                ['name' => $this->name]
124
            ),
125
            __METHOD__
126
        );
127
    }
128
129
    // Protected Methods
130
    // =========================================================================
131
}
132