InPageEventConfig::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
ccs 0
cts 10
cp 0
crap 12
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
{    
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;
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