Field::setKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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
}