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

Schematic::warning()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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\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 '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
        }
70
71
        return $records;
72
    }
73
74
    /**
75
     * Is force enabled?
76
     *
77
     * @var bool
78
     */
79
    public static $force = false;
80
81
    /**
82
     * Logs an error message.
83
     *
84
     * @param string|array $message the message to be logged. This can be a simple string or a more
85
     *                              complex data structure, such as array.
86
     */
87
    public static function error($message)
88
    {
89
        Craft::error($message, 'schematic');
90
    }
91
92
    /**
93
     * Logs a warning message.
94
     *
95
     * @param string|array $message the message to be logged. This can be a simple string or a more
96
     *                              complex data structure, such as array.
97
     */
98
    public static function warning($message)
99
    {
100
        Craft::warning($message, 'schematic');
101
    }
102
103
    /**
104
     * Logs an info message.
105
     *
106
     * @param string|array $message the message to be logged. This can be a simple string or a more
107
     *                              complex data structure, such as array.
108
     */
109
    public static function info($message)
110
    {
111
        Craft::info($message, 'schematic');
112
    }
113
}
114