Completed
Pull Request — master (#114)
by Bart
07:03
created

Schematic   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
C getRecords() 0 26 7
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\Fields::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\TagGroups::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 'globalSets':
55
                $records = Craft::$app->globals->getAllSets();
56
                break;
57
            case 'sections':
58
                $records = Craft::$app->sections->getAllSections();
59
                break;
60
            case 'sites':
61
                $records = Craft::$app->sites->getAllSites();
62
                break;
63
            case 'volumes':
64
                $records = Craft::$app->volumes->getAllVolumes();
65
                break;
66
        }
67
68
        return $records;
69
    }
70
71
    /**
72
     * Is force enabled?
73
     *
74
     * @var bool
75
     */
76
    public static $force = false;
77
78
    /**
79
     * Logs an error message.
80
     *
81
     * @param string|array $message the message to be logged. This can be a simple string or a more
82
     *                              complex data structure, such as array.
83
     */
84
    public static function error($message)
85
    {
86
        Craft::error($message, 'schematic');
87
    }
88
89
    /**
90
     * Logs a warning message.
91
     *
92
     * @param string|array $message the message to be logged. This can be a simple string or a more
93
     *                              complex data structure, such as array.
94
     */
95
    public static function warning($message)
96
    {
97
        Craft::warning($message, 'schematic');
98
    }
99
100
    /**
101
     * Logs an info message.
102
     *
103
     * @param string|array $message the message to be logged. This can be a simple string or a more
104
     *                              complex data structure, such as array.
105
     */
106
    public static function info($message)
107
    {
108
        Craft::info($message, 'schematic');
109
    }
110
}
111