Completed
Push — master ( a99496...5c0b02 )
by Oleg
02:28
created

InPageEventConfig::toArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 15
loc 15
ccs 0
cts 12
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 09 May 2017
5
 * @copyright (c) 2017, Web Marketing ROI
6
 */
7
namespace WebMarketingROI\OptimizelyPHP\Resource\v2;
8
9
use WebMarketingROI\OptimizelyPHP\Exception;
10
11
/**
12
 * Optimizely InPage config.
13
 */
14
class InPageEventConfig
15
{    
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
16
    /**
17
     * CSS selector for the page element(s) that trigger an Event
18
     * @var string 
19
     */
20
    private $selector;
21
    
22
    /**
23
     * Constructor.
24
     */
25
    public function __construct($options = array())
26
    {
27
        foreach ($options as $name=>$value) {
28
            switch ($name) {                
29
                case 'selector': $this->setSelector($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
30
                default:
31
                    throw new Exception('Unknown option found in the InPageConfig entity: ' . $name);
32
            }
33
        }
34
    }
35
    
36
    /**
37
     * Returns this object as array.
38
     */
39 View Code Duplication
    public function toArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $options = array(            
42
            'selector' => $this->getSelector(),            
43
        );
44
        
45
        // Remove options with empty values
46
        $cleanedOptions = array();
47
        foreach ($options as $name=>$value) {
48
            if ($value!==null)
49
                $cleanedOptions[$name] = $value;
50
        }
51
        
52
        return $cleanedOptions;
53
    }
54
    
55
    public function getSelector()
56
    {
57
        return $this->selector;
58
    }
59
    
60
    public function setSelector($selector)
61
    {
62
        $this->selector = $selector;
63
    }        
64
}
65
66
67
68
69
70
71
72
73
74
75