Passed
Push — master ( 86795a...5148d0 )
by Jean Paul
06:50
created

ConvertCaseTransformer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 52
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
    /**
15
     *
16
     */
17
    const CONVERT_CASE_MODE_UPPER = MB_CASE_UPPER;
18
19
    /**
20
     *
21
     */
22
    const CONVERT_CASE_MODE_LOWER = MB_CASE_LOWER;
23
24
    /**
25
     *
26
     */
27
    const CONVERT_CASE_MODE_TITLE = MB_CASE_TITLE;
28
29
30
    /**
31
     * @var array
32
     */
33
    protected array $columns = [];
34
35
    /**
36
     * @var string
37
     */
38
    protected string $encoding = "UTF-8";
39
40
    /**
41
     * @var int
42
     */
43
    protected int $mode = self::CONVERT_CASE_MODE_LOWER;
44
45
    /**
46
     * @var array|string[]
47
     */
48
    protected array $availableOptions = [ "columns", "encoding", "mode" ];
49
50
    /**
51
     * @param Row $row
52
     * @return mixed|void
53
     */
54
    public function transform ( Row $row )
55
    {
56
        foreach ( $this->columns as $oldColumnName ) {
57
            $value = $row->get( $oldColumnName );
58
59
            $row->remove( $oldColumnName );
60
61
            $newColumnName = mb_convert_case( $oldColumnName, $this->mode, $this->encoding );
62
63
            $row->set( $newColumnName, $value );
64
        }
65
    }
66
}
67