Completed
Pull Request — master (#114)
by Bart
18:08 queued 08:13
created

Schematic   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 1
dl 0
loc 109
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
D getRecords() 0 35 10
A error() 0 4 1
A warning() 0 4 1
A info() 0 4 1
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
    /**
21
     * The available datatypes.
22
     *
23
     * @TODO: Make data types and processor components configurable.
24
     *
25
     * @var array
26
     */
27
    const DATA_TYPES = [
28
        'sites' => Services\ModelProcessor::class,
29
        'volumes' => Services\ModelProcessor::class,
30
        'assetTransforms' => Services\ModelProcessor::class,
31
        'fields' => Services\ModelProcessor::class,
32
        'plugins' => Services\Plugins::class,
33
        'sections' => Services\ModelProcessor::class,
34
        'globalSets' => Services\ModelProcessor::class,
35
        'userGroups' => Services\ModelProcessor::class,
36
        'users' => Services\Users::class,
37
        'categoryGroups' => Services\ModelProcessor::class,
38
        'tagGroups' => Services\ModelProcessor::class,
39
        'elementIndexSettings' => Services\ElementIndexSettings::class,
40
    ];
41
42
    /**
43
     * Get records for datatype.
44
     *
45
     * @TODO: Make this more dynamic
46
     *
47
     * @param string $datatype
48
     *
49
     * @return Model[]
50
     */
51
    public static function getRecords(string $datatype)
52
    {
53
        $records = [];
54
        switch ($datatype) {
55
            case 'assetTransforms':
56
                $records = Craft::$app->assetTransforms->getAllTransforms();
57
                break;
58
            case 'categoryGroups':
59
                $records = Craft::$app->categories->getAllGroups();
60
                break;
61
            case 'fields':
62
                $records = Craft::$app->fields->getAllFields();
63
                break;
64
            case 'globalSets':
65
                $records = Craft::$app->globals->getAllSets();
66
                break;
67
            case 'sections':
68
                $records = Craft::$app->sections->getAllSections();
69
                break;
70
            case 'sites':
71
                $records = Craft::$app->sites->getAllSites();
72
                break;
73
            case 'userGroups':
74
                $records = Craft::$app->userGroups->getAllGroups();
75
                break;
76
            case 'volumes':
77
                $records = Craft::$app->volumes->getAllVolumes();
78
                break;
79
            case 'tagGroups':
80
                $records = Craft::$app->tags->getAllTagGroups();
81
                break;
82
        }
83
84
        return $records;
85
    }
86
87
    /**
88
     * Is force enabled?
89
     *
90
     * @var bool
91
     */
92
    public static $force = false;
93
94
    /**
95
     * Logs an error message.
96
     *
97
     * @param string|array $message the message to be logged. This can be a simple string or a more
98
     *                              complex data structure, such as array.
99
     */
100
    public static function error($message)
101
    {
102
        Craft::error($message, 'schematic');
103
    }
104
105
    /**
106
     * Logs a warning message.
107
     *
108
     * @param string|array $message the message to be logged. This can be a simple string or a more
109
     *                              complex data structure, such as array.
110
     */
111
    public static function warning($message)
112
    {
113
        Craft::warning($message, 'schematic');
114
    }
115
116
    /**
117
     * Logs an info message.
118
     *
119
     * @param string|array $message the message to be logged. This can be a simple string or a more
120
     *                              complex data structure, such as array.
121
     */
122
    public static function info($message)
123
    {
124
        Craft::info($message, 'schematic');
125
    }
126
}
127