Completed
Pull Request — master (#114)
by Bart
04:12
created

Schematic   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecords() 0 17 4
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\Sites::class,
22
        'volumes' => Services\Volumes::class,
23
        'assetTransforms' => Services\ModelProcessor::class,
24
        'fields' => Services\Fields::class,
25
        'plugins' => Services\Plugins::class,
26
        'sections' => Services\Sections::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
     * @param string $datatype
39
     *
40
     * @return Model[]
41
     */
42
    public static function getRecords(string $datatype)
43
    {
44
        $records = [];
45
        switch ($datatype) {
46
            case 'assetTransforms':
47
                $records = Craft::$app->assetTransforms->getAllTransforms();
48
                break;
49
            case 'categoryGroups':
50
                $records = Craft::$app->categories->getAllGroups();
51
                break;
52
            case 'globalSets':
53
                $records = Craft::$app->globals->getAllSets();
54
                break;
55
        }
56
57
        return $records;
58
    }
59
60
    /**
61
     * Is force enabled?
62
     *
63
     * @var bool
64
     */
65
    public static $force = false;
66
67
    /**
68
     * Logs an error message.
69
     *
70
     * @param string|array $message the message to be logged. This can be a simple string or a more
71
     *                              complex data structure, such as array.
72
     */
73
    public static function error($message)
74
    {
75
        Craft::error($message, 'schematic');
76
    }
77
78
    /**
79
     * Logs a warning 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 warning($message)
85
    {
86
        Craft::warning($message, 'schematic');
87
    }
88
89
    /**
90
     * Logs an info 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 info($message)
96
    {
97
        Craft::info($message, 'schematic');
98
    }
99
}
100