Issues (446)

src/Recipe.php (34 issues)

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
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
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;
19
use craft\feedme\services\Fields as FeedMeFields;
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
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
33
 * @package   Recipe
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
34
 * @since     1.0.0
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
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
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
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
Missing short description in doc comment
Loading history...
49
     * @var ?Recipe
50
     */
51
    public static ?Recipe $plugin = null;
52
53
    // Public Properties
54
    // =========================================================================
55
56
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
57
     * @var string
58
     */
59
    public string $schemaVersion = '1.0.0';
60
61
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
62
     * @var bool
63
     */
64
    public bool $hasCpSection = false;
65
66
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
67
     * @var bool
68
     */
69
    public bool $hasCpSettings = true;
70
71
    // Public Methods
72
    // =========================================================================
73
74
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
75
     * @inheritdoc
76
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
77
    public function init(): void
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
            static function(RegisterComponentTypesEvent $event): void {
0 ignored issues
show
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
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): void {
0 ignored issues
show
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
96
                if (($event->plugin === $this) && !Craft::$app->getRequest()->getIsConsoleRequest()) {
0 ignored issues
show
The condition $event->plugin === $this is always false.
Loading history...
97
                    Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('recipe/welcome'))->send();
98
                }
99
            }
100
        );
101
102
        $feedMeInstalled = Craft::$app->getPlugins()->isPluginInstalled('feed-me') && Craft::$app->getPlugins()->isPluginEnabled('feed-me');
103
104
        if ($feedMeInstalled) {
105
            Event::on(FeedMeFields::class, FeedMeFields::EVENT_REGISTER_FEED_ME_FIELDS, function(RegisterFeedMeFieldsEvent $e) {
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
106
                $e->fields[] = RecipeFeedMeField::class;
107
            });
0 ignored issues
show
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...
108
        }
109
110
        Craft::info(
111
            Craft::t(
112
                'recipe',
113
                '{name} plugin loaded',
114
                ['name' => $this->name]
115
            ),
116
            __METHOD__
117
        );
118
    }
119
120
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
121
     * @inheritdoc
122
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
123
    protected function createSettingsModel(): Settings
124
    {
125
        return new Settings();
126
    }
127
128
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
129
     * @inheritdoc
130
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
131
    protected function settingsHtml(): ?string
132
    {
133
        return Craft::$app->getView()->renderTemplate('recipe/settings', [
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
134
            'settings' => $this->settings,
135
        ]);
0 ignored issues
show
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...
136
    }
137
}
138