Completed
Push — master ( fe2892...6427ed )
by Oleg
03:03
created

Audience::__construct()   B

Complexity

Conditions 12
Paths 12

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 13.8759

Importance

Changes 0
Metric Value
cc 12
eloc 15
nc 12
nop 1
dl 0
loc 19
ccs 13
cts 17
cp 0.7647
crap 13.8759
rs 7.4259
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 07 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 audience.
13
 */
14
class Audience
15
{
16
    /**
17
     * The project the Audience was created in
18
     * @var integer 
19
     */
20
    private $projectId;
21
    
22
    /**
23
     * Whether the Audience has been archived
24
     * @var boolean 
25
     */
26
    private $archived;
27
    
28
    /**
29
     * A string defining the targeting rules for an audience.
30
     * @var string 
31
     */
32
    private $conditions;
33
    
34
    /**
35
     * A short description of the Audience
36
     * @var string 
37
     */
38
    private $description;
39
    
40
    /**
41
     * The name of the Audience
42
     * @var string 
43
     */
44
    private $name;
45
    
46
    /**
47
     * True if the audiences is available for segmentation on the results page (Platinum only).
48
     * @var boolean 
49
     */
50
    private $segmentation;
51
    
52
    /**
53
     * The time the Audience was initially created
54
     * @var string 
55
     */
56
    private $created;
57
    
58
    /**
59
     * The unique identifier for the Audience.
60
     * @var integer 
61
     */
62
    private $id;
63
    
64
    /**
65
     * The last time the Audience was modified
66
     * @var string 
67
     */
68
    private $lastModified;
69
    
70
    /**
71
     * Whether or not Audience is a classic Audience. If true, the Audience is 
72
     * only compatible with classic Experiments. Otherwise, the Audience may be 
73
     * used in Optimizely X Campaigns.
74
     * @var boolean 
75
     */
76
    private $isClassic;
77
    
78
    /**
79
     * Constructor.
80
     */
81 7
    public function __construct($options = array())
82
    {
83 7
        foreach ($options as $name=>$value) {
84
            switch ($name) {                
85 6
                case 'project_id': $this->setProjectId($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...
86 6
                case 'archived': $this->setArchived($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...
87 6
                case 'conditions': $this->setConditions($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...
88 6
                case 'description': $this->setDescription($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...
89 6
                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...
90 6
                case 'segmentation': $this->setSegmentation($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...
91 4
                case 'created': $this->setCreated($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...
92 4
                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...
93 4
                case 'last_modified': $this->setLastModified($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...
94
                case 'is_classic': $this->getIsClassic($value); break;
0 ignored issues
show
Unused Code introduced by
The call to Audience::getIsClassic() has too many arguments starting with $value.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to the method WebMarketingROI\Optimize...udience::getIsClassic() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
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...
95
                default:
96
                    throw new Exception('Unknown option: ' . $name);
97
            }
98 7
        }
99 7
    }
100
    
101
    /**
102
     * Returns this object as array.
103
     */
104 3
    public function toArray()
105
    {
106
        $options = array(
107 3
            'project_id' => $this->projectId,
108 3
            'archived' => $this->archived,
109 3
            'conditions' => $this->conditions,
110 3
            'description' => $this->description,
111 3
            'name' => $this->name,
112 3
            'segmentation' => $this->segmentation,
113 3
            'created' => $this->created,
114 3
            'id' => $this->id,
115 3
            'last_modified' => $this->lastModified,
116 3
            'is_classic' => $this->isClassic
117 3
        );
118
        
119
        // Remove options with empty values
120 3
        $cleanedOptions = array();
121 3
        foreach ($options as $name=>$value) {
122 3
            if ($value!==null)
123 3
                $cleanedOptions[$name] = $value;
124 3
        }
125
        
126 3
        return $cleanedOptions;
127
    }
128
    
129 2
    public function getProjectId()
130
    {
131 2
        return $this->projectId;
132
    }
133
    
134 7
    public function setProjectId($projectId)
135
    {
136 7
        $this->projectId = $projectId;
137 7
    }
138
    
139 2
    public function getArchived()
140
    {
141 2
        return $this->archived;
142
    }
143
    
144 7
    public function setArchived($archived)
145
    {
146 7
        $this->archived = $archived;
147 7
    }
148
    
149 2
    public function getConditions()
150
    {
151 2
        return $this->conditions;
152
    }
153
    
154 7
    public function setConditions($conditions)
155
    {
156 7
        $this->conditions = $conditions;
157 7
    }
158
    
159 2
    public function getDescription()
160
    {
161 2
        return $this->description;
162
    }
163
    
164 7
    public function setDescription($description)
165
    {
166 7
        $this->description = $description;
167 7
    }
168
        
169 6
    public function getName()
170
    {
171 6
        return $this->name;
172
    }
173
    
174 7
    public function setName($name)
175
    {
176 7
        $this->name = $name;
177 7
    }
178
        
179 2
    public function getSegmentation()
180
    {
181 2
        return $this->segmentation;
182
    }
183
    
184 7
    public function setSegmentation($segmentation)
185
    {
186 7
        $this->segmentation = $segmentation;
187 7
    }
188
    
189 1
    public function getCreated()
190
    {
191 1
        return $this->created;
192
    }
193
    
194 5
    public function setCreated($created)
195
    {
196 5
        $this->created = $created;
197 5
    }
198
    
199 1
    public function getId()
200
    {
201 1
        return $this->id;
202
    }
203
    
204 5
    public function setId($id)
205
    {
206 5
        $this->id = $id;
207 5
    }
208
    
209 1
    public function getLastModified()
210
    {
211 1
        return $this->lastModified;
212
    }
213
    
214 5
    public function setLastModified($lastModified)
215
    {
216 5
        $this->lastModified = $lastModified;
217 5
    }
218
    
219
    public function getIsClassic()
220
    {
221
        return $this->isClassic;
222
    }
223
    
224
    public function setIsClassic($isClassic)
225
    {
226
        $this->isClassic = $isClassic;
227
    }
228
}
229
230
231
232
233
234
235