Passed
Push — master ( a535f0...f38dcf )
by Jean Paul
08:30
created

Step   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 46
rs 10
c 1
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A options() 0 7 3
A textToCamelCase() 0 5 1
A getType() 0 12 4
A getArrayRepresentation() 0 9 2
1
<?php
2
3
namespace Coco\SourceWatcher\Core;
4
5
use Coco\SourceWatcher\Utils\TextUtils;
6
7
/**
8
 * Class Step
9
 *
10
 * @package Coco\SourceWatcher\Core
11
 */
12
class Step
13
{
14
    protected array $availableOptions = [];
15
16
    public function options ( array $options ) : void
17
    {
18
        foreach ( $options as $optionName => $optionValue ) {
19
            $camelCaseOptionName = $this->textToCamelCase( $optionName );
20
21
            if ( in_array( $camelCaseOptionName, $this->availableOptions ) ) {
22
                $this->$camelCaseOptionName = $optionValue;
23
            }
24
        }
25
    }
26
27
    protected function textToCamelCase ( string $word ) : string
28
    {
29
        $textUtils = new TextUtils();
30
31
        return $textUtils->textToCamelCase( $word );
32
    }
33
34
    public function getType () : string
35
    {
36
        if ( $this instanceof Extractor ) {
37
            return "Extractor";
38
        }
39
40
        if ( $this instanceof Transformer ) {
41
            return "Transformer";
42
        }
43
44
        if ( $this instanceof Loader ) {
45
            return "Loader";
46
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 44 is false. This is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
47
    }
48
49
    public function getArrayRepresentation () : array
50
    {
51
        $result = [ "type" => $this->getType(), "class" => get_class( $this ), "options" => [] ];
52
53
        foreach ( $this->availableOptions as $currentOption ) {
54
            $result["options"][$currentOption] = $this->$currentOption;
55
        }
56
57
        return $result;
58
    }
59
}
60