Completed
Push — master ( 96059f...fe2237 )
by Oleg
06:07
created

VariationReach   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.02%

Importance

Changes 0
Metric Value
dl 0
loc 105
ccs 40
cts 43
cp 0.9302
rs 10
c 0
b 0
f 0
wmc 17
lcom 1
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 13 6
A toArray() 0 18 3
A getCount() 0 4 1
A setCount() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getVariationId() 0 4 1
A setVariationId() 0 4 1
A getVariationReach() 0 4 1
A setVariationReach() 0 4 1
1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 12 October 2016
5
 * @copyright (c) 2016, Web Marketing ROI
6
 */
7
namespace WebMarketingROI\OptimizelyPHP\Resource\v2;
8
9
use WebMarketingROI\OptimizelyPHP\Exception;
10
11
/**
12
 * Optimizely variation reach.
13
 */
14
class VariationReach
15
{
16
    /**
17
     * Total number of visitors exposed to this particular variation
18
     * @var integer
19
     */
20
    private $count;
21
    
22
    /**
23
     * The name of the variation
24
     * @var string
25
     */
26
    private $name;
27
    
28
    /**
29
     * The unique identifier for the variation
30
     * @var string
31
     */
32
    private $variationId;
33
    
34
    /**
35
     *
36
     * @var number
37
     */
38
    private $variationReach;
39
    
40
    /**
41
     * Constructor.
42
     */
43 3
    public function __construct($options = array())
44
    {
45 3
        foreach ($options as $name=>$value) {
46
            switch ($name) {                
47 3
                case 'count': $this->setCount($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...
48 3
                case 'name': $this->setName($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...
49 3
                case 'variation_id': $this->setVariationId($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...
50 3
                case 'variation_reach': $this->setVariationReach($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...
51
                default:
52
                    throw new Exception('Unknown option found in VariationReach entity: ' . $name);
53
            }
54 3
        }
55 3
    }
56
    
57
    /**
58
     * Returns this object as array.
59
     */
60 1
    public function toArray()
61
    {
62
        $options = array(
63 1
            'count' => $this->getCount(),
64 1
            'name' => $this->getName(),
65 1
            'variation_id' => $this->getVariationId(),
66 1
            'variation_reach' => $this->getVariationReach(),            
67 1
        );
68
        
69
        // Remove options with empty values
70 1
        $cleanedOptions = array();
71 1
        foreach ($options as $name=>$value) {
72 1
            if ($value!==null)
73 1
                $cleanedOptions[$name] = $value;
74 1
        }
75
        
76 1
        return $cleanedOptions;
77
    }
78
    
79 1
    public function getCount()
80
    {
81 1
        return $this->count;
82
    }
83
    
84 3
    public function setCount($count)
85
    {
86 3
        $this->count = $count;
87 3
    }
88
    
89 1
    public function getName()
90
    {
91 1
        return $this->name;
92
    }
93
    
94 3
    public function setName($name)
95
    {
96 3
        $this->name = $name;
97 3
    }
98
    
99 1
    public function getVariationId()
100
    {
101 1
        return $this->variationId;
102
    }
103
    
104 3
    public function setVariationId($variationId)
105
    {
106 3
        $this->variationId = $variationId;
107 3
    }
108
    
109 1
    public function getVariationReach()
110
    {
111 1
        return $this->variationReach;
112
    }
113
    
114 3
    public function setVariationReach($variationReach)
115
    {
116 3
        $this->variationReach = $variationReach;
117 3
    }
118
}
119
120
121
122
123
124
125
126
127
128
129
130