ConvertCaseTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 10 2
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