Completed
Pull Request — master (#114)
by Bart
10:00 queued 43s
created

Schematic   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 1
dl 0
loc 99
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
D getRecords() 0 32 9
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
    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\UserGroups::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 'volumes':
67
                $records = Craft::$app->volumes->getAllVolumes();
68
                break;
69
            case 'tagGroups':
70
                $records = Craft::$app->tags->getAllTagGroups();
71
                break;
72
        }
73
74
        return $records;
75
    }
76
77
    /**
78
     * Is force enabled?
79
     *
80
     * @var bool
81
     */
82
    public static $force = false;
83
84
    /**
85
     * Logs an error message.
86
     *
87
     * @param string|array $message the message to be logged. This can be a simple string or a more
88
     *                              complex data structure, such as array.
89
     */
90
    public static function error($message)
91
    {
92
        Craft::error($message, 'schematic');
93
    }
94
95
    /**
96
     * Logs a warning message.
97
     *
98
     * @param string|array $message the message to be logged. This can be a simple string or a more
99
     *                              complex data structure, such as array.
100
     */
101
    public static function warning($message)
102
    {
103
        Craft::warning($message, 'schematic');
104
    }
105
106
    /**
107
     * Logs an info message.
108
     *
109
     * @param string|array $message the message to be logged. This can be a simple string or a more
110
     *                              complex data structure, such as array.
111
     */
112
    public static function info($message)
113
    {
114
        Craft::info($message, 'schematic');
115
    }
116
}
117