Passed
Push — v1 ( aa6579...2b3f1f )
by Andrew
14:39 queued 08:14
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;
14
use craft\base\Element;
15
use craft\base\Plugin;
16
use craft\elements\db\ElementQuery;
17
use craft\events\PopulateElementEvent;
18
use craft\web\twig\variables\CraftVariable;
19
use nystudio107\similar\behaviors\CountBehavior;
20
use nystudio107\similar\services\ServicesTrait;
21
use nystudio107\similar\variables\SimilarVariable;
22
use yii\base\Event;
23
24
/**
25
 * Class Similar
26
 *
27
 * @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...
28
 * @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...
29
 * @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...
30
 */
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...
31
class Similar extends Plugin
32
{
33
    // Traits
34
    // =========================================================================
35
36
    use ServicesTrait;
37
38
    // Static Properties
39
    // =========================================================================
40
41
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
42
     * @var Similar
43
     */
44
    public static $plugin;
45
46
    // Public Properties
47
    // =========================================================================
48
49
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
50
     * @var string
51
     */
52
    public $schemaVersion = '1.0.0';
53
54
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
55
     * @var bool
56
     */
57
    public $hasCpSection = false;
58
59
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
60
     * @var bool
61
     */
62
    public $hasCpSettings = false;
63
64
    // Public Methods
65
    // =========================================================================
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @inheritdoc
69
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
70
    public function init()
71
    {
72
        parent::init();
73
        self::$plugin = $this;
74
75
        Event::on(
76
            CraftVariable::class,
77
            CraftVariable::EVENT_INIT,
78
            function(Event $event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
79
                /** @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...
80
                $variable = $event->sender;
81
                $variable->set('similar', SimilarVariable::class);
82
            }
83
        );
84
        Event::on(
85
            ElementQuery::class,
86
            ElementQuery::EVENT_AFTER_POPULATE_ELEMENT,
87
            function(PopulateElementEvent $event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
88
                $element = $event->element;
89
                /** @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
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...
90
                $element->attachBehavior('myCountBehavior', CountBehavior::class);
91
            });
0 ignored issues
show
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
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 12.
Loading history...
92
93
        Craft::info(
94
            Craft::t(
95
                'similar',
96
                '{name} plugin loaded',
97
                ['name' => $this->name]
98
            ),
99
            __METHOD__
100
        );
101
    }
102
103
    // Protected Methods
104
    // =========================================================================
105
}
106