Completed
Pull Request — master (#114)
by Bart
01:47
created

ExportController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 9 1
B exportToYaml() 0 22 4
1
<?php
2
3
namespace NerdsAndCompany\Schematic\Controllers;
4
5
use Craft;
6
use craft\helpers\FileHelper;
7
use NerdsAndCompany\Schematic\Models\Data;
8
use NerdsAndCompany\Schematic\Schematic;
9
use Symfony\Component\Yaml\Yaml;
10
11
/**
12
 * Schematic Export Controller.
13
 *
14
 * Sync Craft Setups.
15
 *
16
 * @author    Nerds & Company
17
 * @copyright Copyright (c) 2015-2018, Nerds & Company
18
 * @license   MIT
19
 *
20
 * @see      http://www.nerds.company
21
 */
22
class ExportController extends Base
23
{
24
    /**
25
     * Exports the Craft datamodel.
26
     *
27
     * @param string $file    file to write the schema to
0 ignored issues
show
Bug introduced by
There is no parameter named $file. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     * @param array  $exclude Data to not export
0 ignored issues
show
Bug introduced by
There is no parameter named $exclude. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
29
     *
30
     * @return int
31
     */
32
    public function actionIndex(): int
33
    {
34
        $dataTypes = $this->getDataTypes();
35
36
        $this->exportToYaml($this->file, $dataTypes);
37
        Schematic::info('Exported schema to '.$this->file);
38
39
        return 0;
40
    }
41
42
    /**
43
     * Export to Yaml file.
44
     *
45
     * @param string $file
46
     * @param bool   $autoCreate
0 ignored issues
show
Bug introduced by
There is no parameter named $autoCreate. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
47
     */
48
    public function exportToYaml($file, $dataTypes): void
49
    {
50
        $this->disableLogging();
51
        $result = [];
52
        foreach ($dataTypes as $dataTypeHandle) {
53
            $dataType = $this->module->getDataType($dataTypeHandle);
54
            if (null == $dataType) {
55
                continue;
56
            }
57
58
            $mapper = $dataType->getMapperHandle();
59
            if (!$this->module->checkMapper($mapper)) {
60
                continue;
61
            }
62
63
            Schematic::info('Exporting '.$dataTypeHandle);
64
            $records = $dataType->getRecords();
65
            $result[$dataTypeHandle] = $this->module->$mapper->export($records);
66
        }
67
68
        FileHelper::writeToFile($file, Data::toYaml($result));
69
    }
70
}
71