ConvertCaseTransformer::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Coco\SourceWatcher\Core\Transformers;
4
5
use Coco\SourceWatcher\Core\Row;
6
use Coco\SourceWatcher\Core\Transformer;
7
8
/**
9
 * Class ConvertCaseTransformer
10
 * @package Coco\SourceWatcher\Core\Transformers
11
 */
12
class ConvertCaseTransformer extends Transformer
13
{
14
    const CONVERT_CASE_MODE_UPPER = MB_CASE_UPPER;
15
16
    const CONVERT_CASE_MODE_LOWER = MB_CASE_LOWER;
17
18
    const CONVERT_CASE_MODE_TITLE = MB_CASE_TITLE;
19
20
    protected array $columns = [];
21
22
    protected string $encoding = "UTF-8";
23
24
    protected int $mode = self::CONVERT_CASE_MODE_LOWER;
25
26
    protected array $availableOptions = [ "columns", "encoding", "mode" ];
27
28
    public function transform ( Row $row )
29
    {
30
        foreach ( $this->columns as $oldColumnName ) {
31
            $value = $row->get( $oldColumnName );
32
33
            $row->remove( $oldColumnName );
34
35
            $newColumnName = mb_convert_case( $oldColumnName, $this->mode, $this->encoding );
36
37
            $row->set( $newColumnName, $value );
38
        }
39
    }
40
}
41