FieldProcessor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processFieldAliases() 0 12 3
A hasUnstructuredFieldAccess() 0 7 3
1
<?php
2
namespace Consolidation\OutputFormatters\StructuredData;
3
4
use Consolidation\OutputFormatters\Options\FormatterOptions;
5
use Consolidation\OutputFormatters\StructuredData\RestructureInterface;
6
use Consolidation\OutputFormatters\Transformations\UnstructuredDataListTransformation;
7
8
/**
9
 * FieldProcessor will do various alterations on field sets.
10
 */
11
class FieldProcessor
12
{
13
    public static function processFieldAliases($fields)
14
    {
15
        if (!is_array($fields)) {
16
            $fields = array_filter(explode(',', $fields));
17
        }
18
        $transformed_fields = [];
19
        foreach ($fields as $field) {
20
            list($machine_name,$label) = explode(' as ', $field) + [$field, preg_replace('#.*\.#', '', $field)];
21
            $transformed_fields[$machine_name] = $label;
22
        }
23
        return $transformed_fields;
24
    }
25
26
    /**
27
     * Determine whether the data structure has unstructured field access,
28
     * e.g. `a.b.c` or `foo as bar`.
29
     * @param type $fields
30
     * @return type
31
     */
32
    public static function hasUnstructuredFieldAccess($fields)
33
    {
34
        if (is_array($fields)) {
35
            $fields = implode(',', $fields);
36
        }
37
        return (strpos($fields, ' as ') !== false) || (strpos($fields, '.') !== false);
38
    }
39
}
40