SectionDataType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 32
ccs 4
cts 12
cp 0.3333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMapperHandle() 0 4 1
A getRecords() 0 4 1
A afterImport() 0 10 2
1
<?php
2
3
namespace NerdsAndCompany\Schematic\DataTypes;
4
5
use Craft;
6
use NerdsAndCompany\Schematic\Schematic;
7
8
/**
9
 * Schematic Sections 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 SectionDataType 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->sections->getAllSections();
35
    }
36
37
    /**
38
     * Reset craft editable sections cache using reflection.
39
     */
40
    public function afterImport()
41
    {
42
        $obj = Craft::$app->sections;
43
        $refObject = new \ReflectionObject($obj);
44
        if ($refObject->hasProperty('_editableSectionIds')) {
45
            $refProperty1 = $refObject->getProperty('_editableSectionIds');
46
            $refProperty1->setAccessible(true);
47
            $refProperty1->setValue($obj, $obj->getAllSectionIds());
48
        }
49
    }
50
}
51