Completed
Push — master ( 1d1446...5246d9 )
by Oleg
02:12
created

Metric   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 89.66%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 69
ccs 26
cts 29
cp 0.8966
rs 10
c 1
b 0
f 0
wmc 11
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 4
A toArray() 0 16 3
A getKind() 0 4 1
A setKind() 0 4 1
A getId() 0 4 1
A setId() 0 4 1
1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 10 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
 * An Optimizely campaign metric.
13
 */
14
class Metric
15
{
16
    /**
17
     * The kind of a Metric
18
     * @var string 
19
     */
20
    private $kind;
21
    
22
    /**
23
     * The unique identifier for the Metric
24
     * @var integer 
25
     */
26
    private $id;
27
    
28
    /**
29
     * Constructor.
30
     */
31 14
    public function __construct($options = array())
32
    {
33 14
        foreach ($options as $name=>$value) {
34
            switch ($name) {                
35 12
                case 'kind': $this->setKind($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...
36 8
                case 'id': $this->setId($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...
37
                default:
38
                    throw new Exception('Unknown option: ' . $name);
39
            }
40 14
        }
41 14
    }
42
    
43
    /**
44
     * Returns this object as array.
45
     */
46 6
    public function toArray()
47
    {
48
        $options = array(
49 6
            'kind' => $this->getKind(),
50 6
            'id' => $this->getId(),            
51 6
        );
52
        
53
        // Remove options with empty values
54 6
        $cleanedOptions = array();
55 6
        foreach ($options as $name=>$value) {
56 6
            if ($value!==null)
57 6
                $cleanedOptions[$name] = $value;
58 6
        }
59
        
60 6
        return $cleanedOptions;
61
    }
62
    
63 9
    public function getKind()
64
    {
65 9
        return $this->kind;
66
    }
67
    
68 14
    public function setKind($kind)
69
    {
70 14
        $this->kind = $kind;
71 14
    }
72
    
73 6
    public function getId()
74
    {
75 6
        return $this->id;
76
    }
77
    
78 9
    public function setId($id)
79
    {
80 9
        $this->id = $id;
81 9
    }
82
}
83
84
85
86
87
88