Passed
Push — v1 ( ff21ed...4ea8e1 )
by Andrew
10:09 queued 04:13
created

Recipe::createSettingsModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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 Craft;
15
use craft\base\Plugin;
16
use craft\events\PluginEvent;
17
use craft\events\RegisterComponentTypesEvent;
18
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...
19
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...
20
use craft\helpers\UrlHelper;
21
use craft\services\Fields;
22
use craft\services\Plugins;
23
use nystudio107\recipe\fields\Recipe as RecipeField;
24
use nystudio107\recipe\integrations\RecipeFeedMeField;
25
use nystudio107\recipe\models\Settings;
26
use nystudio107\recipe\services\ServicesTrait;
27
use yii\base\Event;
28
29
/**
30
 * Class Recipe
31
 *
32
 * @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...
33
 * @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...
34
 * @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...
35
 *
36
 * @property Settings $settings
37
 */
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...
38
class Recipe extends Plugin
39
{
40
    // Traits
41
    // =========================================================================
42
43
    use ServicesTrait;
44
45
    // Static Properties
46
    // =========================================================================
47
48
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
49
     * @var Recipe
50
     */
51
    public static $plugin;
52
53
    // Public Properties
54
    // =========================================================================
55
56
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
57
     * @var string
58
     */
59
    public $schemaVersion = '1.0.0';
60
61
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
62
     * @var bool
63
     */
64
    public $hasCpSection = false;
65
66
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
67
     * @var bool
68
     */
69
    public $hasCpSettings = true;
70
71
    // Public Methods
72
    // =========================================================================
73
74
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
75
     * @inheritdoc
76
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
77
    public function init()
78
    {
79
        parent::init();
80
        self::$plugin = $this;
81
82
        // Register our Field
83
        Event::on(
84
            Fields::class,
85
            Fields::EVENT_REGISTER_FIELD_TYPES,
86
            function (RegisterComponentTypesEvent $event) {
87
                $event->types[] = RecipeField::class;
88
            }
89
        );
90
91
        // Show our "Welcome to Recipe" message
92
        Event::on(
93
            Plugins::class,
94
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
95
            function (PluginEvent $event) {
96
                if (!Craft::$app->getRequest()->getIsConsoleRequest()
97
                    && ($event->plugin === $this)) {
0 ignored issues
show
Coding Style introduced by
Closing parenthesis of a multi-line IF statement must be on a new line
Loading history...
98
                    Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('recipe/welcome'))->send();
99
                }
100
            }
101
        );
102
103
        $feedMeInstalled = Craft::$app->getPlugins()->isPluginInstalled('feed-me') && Craft::$app->getPlugins()->isPluginEnabled('feed-me');
104
105
        if ($feedMeInstalled) {
106
            Event::on(FeedMeFields::class, FeedMeFields::EVENT_REGISTER_FEED_ME_FIELDS, function (RegisterFeedMeFieldsEvent $e) {
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...
107
                $e->fields[] = RecipeFeedMeField::class;
108
            });
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...
109
        }
110
111
        Craft::info(
112
            Craft::t(
113
                'recipe',
114
                '{name} plugin loaded',
115
                ['name' => $this->name]
116
            ),
117
            __METHOD__
118
        );
119
    }
120
121
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
122
     * @inheritdoc
123
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
124
    protected function createSettingsModel(): Settings
125
    {
126
        return new Settings();
127
    }
128
129
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
130
     * @inheritdoc
131
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
132
    protected function settingsHtml()
133
    {
134
        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...
135
            'settings' => $this->settings
136
        ]);
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...
137
    }
138
}
139