InPageEventConfig   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 29.41 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 15
loc 51
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A toArray() 15 15 3
A getSelector() 0 4 1
A setSelector() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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