Completed
Pull Request — master (#114)
by Bart
08:58
created

Schematic::getRecords()   D

Complexity

Conditions 10
Paths 10

Size

Total Lines 35
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 4.8196
c 0
b 0
f 0
cc 10
eloc 31
nc 10
nop 1

How to fix   Complexity   

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
namespace NerdsAndCompany\Schematic;
4
5
use Craft;
6
7
/**
8
 * Schematic.
9
 *
10
 * Sync Craft Setups.
11
 *
12
 * @author    Nerds & Company
13
 * @copyright Copyright (c) 2015-2018, Nerds & Company
14
 * @license   MIT
15
 *
16
 * @see      http://www.nerds.company
17
 */
18
class Schematic
19
{
20
    const DATA_TYPES = [
21
        'sites' => Services\ModelProcessor::class,
22
        'volumes' => Services\ModelProcessor::class,
23
        'assetTransforms' => Services\ModelProcessor::class,
24
        'fields' => Services\ModelProcessor::class,
25
        'plugins' => Services\Plugins::class,
26
        'sections' => Services\ModelProcessor::class,
27
        'globalSets' => Services\ModelProcessor::class,
28
        'userGroups' => Services\ModelProcessor::class,
29
        'users' => Services\Users::class,
30
        'categoryGroups' => Services\ModelProcessor::class,
31
        'tagGroups' => Services\ModelProcessor::class,
32
        'elementIndexSettings' => Services\ElementIndexSettings::class,
33
    ];
34
35
    /**
36
     * Get records for datatype.
37
     *
38
     * @TODO: Make this more dynamic
39
     *
40
     * @param string $datatype
41
     *
42
     * @return Model[]
43
     */
44
    public static function getRecords(string $datatype)
45
    {
46
        $records = [];
47
        switch ($datatype) {
48
            case 'assetTransforms':
49
                $records = Craft::$app->assetTransforms->getAllTransforms();
50
                break;
51
            case 'categoryGroups':
52
                $records = Craft::$app->categories->getAllGroups();
53
                break;
54
            case 'fields':
55
                $records = Craft::$app->fields->getAllFields();
56
                break;
57
            case 'globalSets':
58
                $records = Craft::$app->globals->getAllSets();
59
                break;
60
            case 'sections':
61
                $records = Craft::$app->sections->getAllSections();
62
                break;
63
            case 'sites':
64
                $records = Craft::$app->sites->getAllSites();
65
                break;
66
            case 'userGroups':
67
                $records = Craft::$app->userGroups->getAllGroups();
68
                break;
69
            case 'volumes':
70
                $records = Craft::$app->volumes->getAllVolumes();
71
                break;
72
            case 'tagGroups':
73
                $records = Craft::$app->tags->getAllTagGroups();
74
                break;
75
        }
76
77
        return $records;
78
    }
79
80
    /**
81
     * Is force enabled?
82
     *
83
     * @var bool
84
     */
85
    public static $force = false;
86
87
    /**
88
     * Logs an error message.
89
     *
90
     * @param string|array $message the message to be logged. This can be a simple string or a more
91
     *                              complex data structure, such as array.
92
     */
93
    public static function error($message)
94
    {
95
        Craft::error($message, 'schematic');
96
    }
97
98
    /**
99
     * Logs a warning message.
100
     *
101
     * @param string|array $message the message to be logged. This can be a simple string or a more
102
     *                              complex data structure, such as array.
103
     */
104
    public static function warning($message)
105
    {
106
        Craft::warning($message, 'schematic');
107
    }
108
109
    /**
110
     * Logs an info message.
111
     *
112
     * @param string|array $message the message to be logged. This can be a simple string or a more
113
     *                              complex data structure, such as array.
114
     */
115
    public static function info($message)
116
    {
117
        Craft::info($message, 'schematic');
118
    }
119
}
120