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

Step   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A options() 0 7 3
A textToCamelCase() 0 18 1
1
<?php
2
3
namespace Coco\SourceWatcher\Core;
4
5
/**
6
 * Class Step
7
 * @package Coco\SourceWatcher\Core
8
 */
9
class Step
10
{
11
    /**
12
     * @var array
13
     */
14
    protected array $availableOptions = array();
15
16
    /**
17
     * @param array $options
18
     */
19
    public function options ( array $options )
20
    {
21
        foreach ( $options as $optionName => $optionValue ) {
22
            $camelCaseOptionName = $this->textToCamelCase( $optionName );
23
24
            if ( in_array( $camelCaseOptionName, $this->availableOptions ) ) {
25
                $this->$camelCaseOptionName = $optionValue;
26
            }
27
        }
28
    }
29
30
    /**
31
     * @param string $word
32
     * @return string
33
     */
34
    protected function textToCamelCase ( string $word ) : string
35
    {
36
        // Make an array of word parts exploding the word by "_"
37
        $wordParts = explode( "_", $word );
38
39
        // Make every word part lower case
40
        $wordParts = array_map( "strtolower", $wordParts );
41
42
        // Make ever word part first character uppercase
43
        $wordParts = array_map( "ucfirst", $wordParts );
44
45
        // Make the new word as the combination of the given word parts
46
        $newWord = implode( "", $wordParts );
47
48
        // Make the new word first character lowercase
49
        $newWord = lcfirst( $newWord );
50
51
        return $newWord;
52
    }
53
}
54