Completed
Pull Request — master (#114)
by Bart
04:26
created

ExportController::actionIndex()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 16
nc 4
nop 0
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
10
/**
11
 * Schematic Export Controller.
12
 *
13
 * Sync Craft Setups.
14
 *
15
 * @author    Nerds & Company
16
 * @copyright Copyright (c) 2015-2018, Nerds & Company
17
 * @license   MIT
18
 *
19
 * @see      http://www.nerds.company
20
 */
21
class ExportController extends Base
22
{
23
    /**
24
     * Exports the Craft datamodel.
25
     *
26
     * @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...
27
     * @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...
28
     *
29
     * @return int
30
     */
31
    public function actionIndex(): int
32
    {
33
        $this->disableLogging();
34
        $result = [];
35
        foreach ($this->getDataTypes() as $dataTypeHandle) {
36
            $dataType = $this->module->getDataType($dataTypeHandle);
37
            if (null == $dataType) {
38
                continue;
39
            }
40
41
            $mapper = $dataType->getMapperHandle();
42
            if (!$this->module->checkMapper($mapper)) {
43
                continue;
44
            }
45
46
            Schematic::info('Exporting '.$dataTypeHandle);
47
            $records = $dataType->getRecords();
48
            $result[$dataTypeHandle] = $this->module->$mapper->export($records);
49
        }
50
51
        FileHelper::writeToFile($this->file, Data::toYaml($result));
52
        Schematic::info('Exported schema to '.$this->file);
53
54
        return 0;
55
    }
56
}
57