ChangeKeyTransform   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A transformSubject() 0 5 1
A transformField() 0 4 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