Passed
Pull Request — develop (#26)
by
unknown
07:15
created

RecipeFeedMeField   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMappingTemplate() 0 3 1
B parseField() 0 38 8
1
<?php
2
namespace nystudio107\recipe\integrations;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use Cake\Utility\Hash;
0 ignored issues
show
Bug introduced by
The type Cake\Utility\Hash was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use craft\feedme\base\Field;
0 ignored issues
show
Bug introduced by
The type craft\feedme\base\Field was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use craft\feedme\base\FieldInterface;
0 ignored issues
show
Bug introduced by
The type craft\feedme\base\FieldInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use craft\feedme\helpers\DataHelper;
0 ignored issues
show
Bug introduced by
The type craft\feedme\helpers\DataHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class RecipeFeedMeField extends Field implements FieldInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class RecipeFeedMeField
Loading history...
10
{
11
    // Properties
12
    // =========================================================================
13
14
    public static $name = 'Recipe';
15
    public static $class = 'nystudio107\recipe\fields\Recipe';
16
17
18
    // Templates
19
    // =========================================================================
20
21
    public function getMappingTemplate()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
22
    {
23
        return 'recipe/_integrations/feed-me';
24
    }
25
26
27
    // Public Methods
28
    // =========================================================================
29
30
    public function parseField()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
31
    {
32
        $preppedData = [];
33
34
        $fields = Hash::get($this->fieldInfo, 'fields');
35
36
        if (!$fields) {
37
            return null;
38
        }
39
40
        foreach ($fields as $subFieldHandle => $subFieldInfo) {
41
            // Check for sub-sub fields - bit dirty...
42
            $subfields = Hash::get($subFieldInfo, 'fields');
43
44
            if ($subfields) {
45
                foreach ($subfields as $subSubFieldHandle => $subSubFieldInfo) {
46
                    // Handle array data, man I hate Feed Me's data mapping now...
47
                    $content = DataHelper::fetchValue($this->feedData, $subSubFieldInfo);
48
49
                    if (is_array($content)) {
50
                        foreach ($content as $key => $value) {
51
                            $preppedData[$subFieldHandle][$key][$subSubFieldHandle] = $value;
52
                        }
53
                    } else {
54
                        $preppedData[$subFieldHandle][$subSubFieldHandle] = $content;
55
                    }
56
                }
57
            } else {
58
                $preppedData[$subFieldHandle] = DataHelper::fetchValue($this->feedData, $subFieldInfo);
59
            }
60
        }
61
62
        // Protect against sending an empty array
63
        if (!$preppedData) {
64
            return null;
65
        }
66
67
        return $preppedData;
68
    }
69
70
}