ChangeKeyTransform::transformSubject()   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
/**
6
 * Class ChangeKeyTransform
7
 * @package StoutLogic\ACF\Migrations
8
 *
9
 * Changes the key of an ACF field, maintaining the field name and field value
10
 */
11
class ChangeKeyTransform extends Transform
12
{
13
    /**
14
     * @var string
15
     */
16
    private $newKey;
17
18
    /**
19
     * @param string $newKey
20
     */
21
    public function __construct($newKey)
22
    {
23
        $this->newKey = $newKey;
24
    }
25
26
    public function transformSubject(HasMetaData $subject)
27
    {
28
        $fieldName = $this->getField()->getFieldNameFrom($subject);
29
        $subject->updateMetaData("_$fieldName", $this->newKey);
30
    }
31
32
    public function transformField()
33
    {
34
        $this->getField()->setKey($this->newKey);
35
    }
36
}
37