GlobalSetDataType::afterImport()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace NerdsAndCompany\Schematic\DataTypes;
4
5
use Craft;
6
use NerdsAndCompany\Schematic\Schematic;
7
8
/**
9
 * Schematic GlobalSets DataType.
10
 *
11
 * Sync Craft Setups.
12
 *
13
 * @author    Nerds & Company
14
 * @copyright Copyright (c) 2015-2019, Nerds & Company
15
 * @license   MIT
16
 *
17
 * @see      http://www.nerds.company
18
 */
19
class GlobalSetDataType extends Base
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 1
    public function getMapperHandle(): string
25
    {
26 1
        return 'modelMapper';
27
    }
28
29
    /**
30
     * Get data of this type.
31
     *
32
     * @return array
33
     */
34 1
    public function getRecords(): array
35
    {
36 1
        return Craft::$app->globals->getAllSets();
37
    }
38
39
    /**
40
     * Reset craft global sets cache using reflection.
41
     */
42
    public function afterImport()
43
    {
44
        $obj = Craft::$app->globals;
45
        $refObject = new \ReflectionObject($obj);
46
        if ($refObject->hasProperty('_allGlobalSets')) {
47
            $refProperty1 = $refObject->getProperty('_allGlobalSets');
48
            $refProperty1->setAccessible(true);
49
            $refProperty1->setValue($obj, null);
50
        }
51
    }
52
}
53