Field   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setKey() 0 5 1
A getKey() 0 4 1
A getFieldNameFrom() 0 14 2
1
<?php
2
3
namespace StoutLogic\ACF\Migrations;
4
5
class Field
6
{
7
8
    private $key;
9
10
    /**
11
     * Field constructor.
12
     * @param string $key
13
     */
14
    public function __construct($key)
15
    {
16
        $this->key = $key;
17
    }
18
19
    /**
20
     * @param string $key
21
     * @return Field
22
     */
23
    public function setKey($key)
24
    {
25
        $this->key = $key;
26
        return $this;
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getKey()
33
    {
34
        return $this->key;
35
    }
36
37
    public function getFieldNameFrom(HasMetaData $subject)
38
    {
39
        $metaData = $subject->getAllMetaData();
40
41
        $fieldName = array_merge(
42
            array_keys($metaData, [$this->getKey()]),
43
            array_keys($metaData, $this->getKey())
44
        );
45
46
        if (is_array($fieldName)) {
47
            $fieldName = array_shift($fieldName);
48
        }
49
        return ltrim($fieldName, '_');
50
    }
51
52
53
}