Completed
Push — master ( fa30b9...467c9d )
by Bart
15s queued 10s
created

FieldDataType   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 41
ccs 4
cts 14
cp 0.2857
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMapperHandle() 0 4 1
A getRecords() 0 4 1
A afterImport() 0 7 2
A clearEmptyGroups() 0 8 3
1
<?php
2
3
namespace NerdsAndCompany\Schematic\DataTypes;
4
5
use Craft;
6
use NerdsAndCompany\Schematic\Schematic;
7
8
/**
9
 * Schematic Fields DataType.
10
 *
11
 * Sync Craft Setups.
12
 *
13
 * @author    Nerds & Company
14
 * @copyright Copyright (c) 2015-2018, Nerds & Company
15
 * @license   MIT
16
 *
17
 * @see      http://www.nerds.company
18
 */
19
class FieldDataType extends Base
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 1
    public function getMapperHandle(): string
25
    {
26 1
        return 'modelMapper';
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 1
    public function getRecords(): array
33
    {
34 1
        return Craft::$app->fields->getAllFields();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function afterImport()
41
    {
42
        Craft::$app->fields->updateFieldVersion();
43
        if (Schematic::$force) {
44
            $this->clearEmptyGroups();
45
        }
46
    }
47
48
    /**
49
     * Clear empty field groups
50
     */
51
    private function clearEmptyGroups()
52
    {
53
        foreach (Craft::$app->fields->getAllGroups() as $group) {
54
            if (count($group->getFields()) == 0) {
55
                Craft::$app->fields->deleteGroup($group);
56
            }
57
        }
58
    }
59
}
60