Passed
Branch etl-core (c0e492)
by Jean Paul
01:52
created

RenameColumnsTransformer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 6 2
1
<?php
2
3
namespace Coco\SourceWatcher\Core\Transformers;
4
5
use Coco\SourceWatcher\Core\Transformer;
6
use Coco\SourceWatcher\Core\Row;
7
8
class RenameColumnsTransformer extends Transformer
9
{
10
    /**
11
     * @var array
12
     */
13
    protected array $columns = [];
14
15
    /**
16
     * @var array
17
     */
18
    protected array $availableOptions = [ "columns" ];
19
20
    /**
21
     * @param Row $row
22
     */
23
    public function transform ( Row $row )
24
    {
25
        foreach ( $this->columns as $oldColumnName => $newColumnName ) {
26
            $value = $row->get( $oldColumnName );
27
            $row->remove( $oldColumnName );
28
            $row->set( $newColumnName, $value );
29
        }
30
    }
31
}
32