Completed
Push — develop ( 6fdb58...dee5cf )
by Oleg
04:27 queued 01:45
created

Metric::toArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

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