Passed
Push — master ( 8a350c...281cf2 )
by Josh
03:42 queued 11s
created

Spoon::getSettingsResponse()   B

Complexity

Conditions 8
Paths 2

Size

Total Lines 65
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 65
rs 8.1795
c 0
b 0
f 0
cc 8
nc 2
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Spoon::createSettingsModel() 0 3 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Spoon plugin for Craft CMS 3.x
4
 *
5
 * Enhance Matrix
6
 *
7
 * @link      https://angell.io
8
 * @copyright Copyright (c) 2018 Angell & Co
9
 */
10
11
namespace angellco\spoon;
12
13
use angellco\spoon\models\Settings;
14
use angellco\spoon\services\Fields as FieldsService;
15
use angellco\spoon\services\BlockTypes as BlockTypesService;
16
use angellco\spoon\services\Loader as LoaderService;
17
18
use Craft;
19
use craft\base\Plugin;
20
use craft\events\RegisterUrlRulesEvent;
21
use craft\services\Plugins;
22
23
use craft\web\UrlManager;
24
use yii\base\Event;
25
26
/**
27
 * Craft plugins are very much like little applications in and of themselves. We’ve made
28
 * it as simple as we can, but the training wheels are off. A little prior knowledge is
29
 * going to be required to write a plugin.
30
 *
31
 * For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL,
32
 * as well as some semi-advanced concepts like object-oriented programming and PHP namespaces.
33
 *
34
 * https://craftcms.com/docs/plugins/introduction
35
 *
36
 * @author    Angell & Co
37
 * @package   Spoon
38
 * @since     3.0.0
39
 *
40
 * @property  FieldsService $fields
41
 * @property  BlockTypesService $blockTypes
42
 * @property  LoaderService $loader
43
 * @method    Settings getSettings()
44
 */
45
class Spoon extends Plugin
46
{
47
    // Static Properties
48
    // =========================================================================
49
50
    /**
51
     * Static property that is an instance of this plugin class so that it can be accessed via
52
     * Spoon::$plugin
53
     *
54
     * @var Spoon
55
     */
56
    public static $plugin;
57
58
    // Public Properties
59
    // =========================================================================
60
61
    /**
62
     * To execute your plugin’s migrations, you’ll need to increase its schema version.
63
     *
64
     * @var string
65
     */
66
    public $schemaVersion = '3.0.0';
67
68
    /**
69
     * @var bool Whether the plugin has its own section in the CP
70
     */
71
    public $hasCpSection = true;
72
73
74
    // Public Methods
75
    // =========================================================================
76
77
    /**
78
     * Set our $plugin static property to this class so that it can be accessed via
79
     * Spoon::$plugin
80
     *
81
     * Called after the plugin class is instantiated; do any one-time initialization
82
     * here such as hooks and events.
83
     *
84
     * If you have a '/vendor/autoload.php' file, it will be loaded for you automatically;
85
     * you do not need to load it in your init() method.
86
     *
87
     */
88
    public function init()
89
    {
90
        parent::init();
91
        self::$plugin = $this;
92
93
        Event::on(
94
            UrlManager::class,
95
            UrlManager::EVENT_REGISTER_CP_URL_RULES,
96
            function(RegisterUrlRulesEvent $event) {
97
                $event->rules['spoon'] = 'spoon/block-types/index';
98
            }
99
        );
100
101
        // Wait until all the plugins have loaded before running the loader
102
        Event::on(
103
            Plugins::class,
104
            Plugins::EVENT_AFTER_LOAD_PLUGINS,
105
            function() {
106
                if ($this->isInstalled && !Craft::$app->plugins->doesPluginRequireDatabaseUpdate($this)) {
107
                    $this->loader->run();
108
                }
109
            }
110
        );
111
112
        Craft::info(
113
            Craft::t(
114
                'spoon',
115
                '{name} plugin loaded',
116
                ['name' => $this->name]
117
            ),
118
            __METHOD__
119
        );
120
    }
121
122
    // Protected Methods
123
    // =========================================================================
124
125
    /**
126
     * @inheritdoc
127
     */
128
    protected function createSettingsModel()
129
    {
130
        return new Settings();
131
    }
132
133
}
134