Passed
Push — v1 ( cee1bd...d527b0 )
by Andrew
11:40 queued 04:39
created

Recipe::__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
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 * Recipe plugin for Craft CMS 3.x
4
 *
5
 * A comprehensive recipe FieldType for Craft CMS that includes metric/imperial
6
 * conversion, portion calculation, and JSON-LD microdata support
7
 *
8
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
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...
11
12
namespace nystudio107\recipe;
13
14
use nystudio107\recipe\fields\Recipe as RecipeField;
15
use nystudio107\recipe\integrations\RecipeFeedMeField;
16
17
use Craft;
18
use craft\base\Plugin;
19
use craft\services\Fields;
20
use craft\services\Plugins;
21
use craft\events\RegisterComponentTypesEvent;
22
use craft\events\PluginEvent;
23
use craft\helpers\UrlHelper;
24
use nystudio107\recipe\models\Settings;
25
use nystudio107\recipe\services\NutritionApi;
26
use yii\base\Event;
27
28
use craft\feedme\events\RegisterFeedMeFieldsEvent;
0 ignored issues
show
Bug introduced by
The type craft\feedme\events\RegisterFeedMeFieldsEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use craft\feedme\services\Fields as FeedMeFields;
0 ignored issues
show
Bug introduced by
The type craft\feedme\services\Fields was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
31
/**
32
 * Class Recipe
33
 *
34
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
35
 * @package   Recipe
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
36
 * @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...
37
 *
38
 * @property NutritionApi $nutritionApi
39
 * @property Settings $settings
40
 */
0 ignored issues
show
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
41
class Recipe extends Plugin
42
{
43
    // Static Properties
44
    // =========================================================================
45
46
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
47
     * @var Recipe
48
     */
49
    public static $plugin;
50
51
    // Static Methods
52
    // =========================================================================
53
54
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $config 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 $id should have a doc-comment as per coding-style.
Loading history...
55
     * @inheritdoc
56
     */
57
    public function __construct($id, $parent = null, array $config = [])
58
    {
59
        $config['components'] = [
60
            'nutritionApi' => NutritionApi::class,
61
        ];
62
63
        parent::__construct($id, $parent, $config);
64
    }
65
66
    // Public Methods
67
    // =========================================================================
68
69
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
70
     * @inheritdoc
71
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
72
    public function init()
73
    {
74
        parent::init();
75
        self::$plugin = $this;
76
77
        // Register our Field
78
        Event::on(
79
            Fields::class,
80
            Fields::EVENT_REGISTER_FIELD_TYPES,
81
            function (RegisterComponentTypesEvent $event) {
82
                $event->types[] = RecipeField::class;
83
            }
84
        );
85
86
        // Show our "Welcome to Recipe" message
87
        Event::on(
88
            Plugins::class,
89
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
90
            function (PluginEvent $event) {
91
                if (!Craft::$app->getRequest()->getIsConsoleRequest()
92
                && ($event->plugin === $this)) {
0 ignored issues
show
Coding Style introduced by
Multi-line IF statement not indented correctly; expected 20 spaces but found 16
Loading history...
Coding Style introduced by
Closing parenthesis of a multi-line IF statement must be on a new line
Loading history...
93
                    Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('recipe/welcome'))->send();
94
                }
95
            }
96
        );
97
98
        $feedMeInstalled = Craft::$app->getPlugins()->isPluginInstalled('feed-me') && Craft::$app->getPlugins()->isPluginEnabled('feed-me');
99
100
        if ($feedMeInstalled) {
101
            Event::on(FeedMeFields::class, FeedMeFields::EVENT_REGISTER_FEED_ME_FIELDS, function(RegisterFeedMeFieldsEvent $e) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
102
                $e->fields[] = RecipeFeedMeField::class;
103
            });
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...
104
        }
105
106
        Craft::info(
107
            Craft::t(
108
                'recipe',
109
                '{name} plugin loaded',
110
                ['name' => $this->name]
111
            ),
112
            __METHOD__
113
        );
114
    }
115
116
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
117
     * @inheritdoc
118
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
119
    protected function createSettingsModel(): Settings
120
    {
121
        return new Settings();
122
    }
123
124
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
125
     * @inheritdoc
126
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
127
    protected function settingsHtml()
128
    {
129
        return Craft::$app->getView()->renderTemplate('recipe/settings', [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
130
            'settings' => $this->settings
131
        ]);
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...
132
    }
133
}
134