ProductUsage::setProjects()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 16 July 2019
5
 * @copyright (c) 2019, Web Marketing ROI
6
 */
7
namespace WebMarketingROI\OptimizelyPHP\Resource\v2;
8
9
use WebMarketingROI\OptimizelyPHP\Exception;
10
11
/**
12
 * An Optimizely product usage.
13
 */
14
class ProductUsage
15
{
16
    /**
17
     * The current allocation term length in months.  
18
     * @var integer
19
     */
20
    private $allocationTermInMonths;
21
    
22
    /**
23
     * The end date of the current allocation term period.
24
     * @var string
25
     */
26
    private $endTime;
27
    
28
    /**
29
     * The last time that the unit_of_measurement count was updated
30
     * @var string
31
     */
32
    private $lastUpdateTime;
33
    
34
    /**
35
     * (optional) The cost in cents for every visitor when the number of 
36
     * unit_of_measurement has exceeded the usage_allowance. This value is 
37
     * only set for accounts with a limited usage_allowance
38
     * @var number 
39
     */
40
    private $overageCentsPerVisitor;
41
    
42
    /**
43
     * The product name
44
     * @var string
45
     */
46
    private $productName;
47
    
48
    /**
49
     * Key-value map of usage per project under this account and this product. 
50
     * Keys are project IDs, values are usage numbers. Only available for the 
51
     * Impressions metrics, otherwise omitted.
52
     * @var array 
53
     */
54
    private $projects;
55
    
56
    /**
57
     * The start date of the current allocation term period. For monthly paying 
58
     * accounts, the current allocation term period means the current billing month
59
     * @var string 
60
     */
61
    private $startTime;
62
    
63
    /**
64
     * The total usage in the unit_of_measurement within the current allocation term
65
     * @var integer 
66
     */
67
    private $usage;
68
    
69
    /**
70
     * (optional) The total usage allowed in the unit_of_measurement for the 
71
     * current allocation term. This value is only set for accounts with a 
72
     * limited usage_allowance
73
     * 
74
     * @var integer 
75
     */
76
    private $usageAllowance;
77
    
78
    /**
79
     * Constructor.
80
     */
81 4
    public function __construct($options = array())
82
    {
83 4
        foreach ($options as $name=>$value) {
84
            switch ($name) {                
85 3
                case 'allocation_term_in_months': $this->setAllocationTermInMonths($value); break;
86 3
                case 'end_time': $this->setEndTime($value); break;
87 3
                case 'last_update_time': $this->setLastUpdateTime($value); break;
88 3
                case 'overage_cents_per_visitor': $this->setOverageCentsPerVisitor($value); break;
89 3
                case 'product_name': $this->setProductName($value); break;
90 3
                case 'projects': $this->setProjects($value); break;
91 3
                case 'start_time': $this->setStartTime($value); break;
92 3
                case 'usage': $this->setUsage($value); break;
93 3
                case 'usage_allowance': $this->setUsageAllowance($value); break;
94
                default:
95 3
                    throw new Exception('Unknown option found in the ProductUsage entity: ' . $name);
96
            }
97
        }
98 4
    }
99
    
100
    /**
101
     * Returns this object as array.
102
     */
103 1
    public function toArray()
104
    {
105
        $options = array(
106 1
            'allocation_term_in_months' => $this->getAllocationTermInMonths(),
107 1
            'end_time' => $this->getEndTime(),
108 1
            'last_update_time' => $this->getLastUpdateTime(),
109 1
            'overage_cents_per_visitor' => $this->getOverageCentsPerVisitor(),
110 1
            'product_name' => $this->getProductName(),
111 1
            'projects' => $this->getProjects(),
112 1
            'start_time' => $this->getStartTime(),
113 1
            'usage' => $this->getUsage(),
114 1
            'usage_allowance' => $this->getUsageAllowance(),
115
        );
116
                
117
        // Remove options with empty values
118 1
        $cleanedOptions = array();
119 1
        foreach ($options as $name=>$value) {
120 1
            if ($value!==null)
121 1
                $cleanedOptions[$name] = $value;
122
        }
123
        
124 1
        return $cleanedOptions;
125
    }
126
    
127 1
    public function getAllocationTermInMonths()
128
    {
129 1
        return $this->allocationTermInMonths;
130
    }
131
    
132 4
    public function setAllocationTermInMonths($allocationTermInMonths)
133
    {
134 4
        $this->allocationTermInMonths = $allocationTermInMonths;
135 4
    }
136
    
137 1
    public function getEndTime()
138
    {
139 1
        return $this->endTime;
140
    }
141
    
142 4
    public function setEndTime($endTime)
143
    {
144 4
        $this->endTime = $endTime;
145 4
    }
146
    
147 1
    public function getLastUpdateTime()
148
    {
149 1
        return $this->lastUpdateTime;
150
    }
151
    
152 4
    public function setLastUpdateTime($lastUpdateTime)
153
    {
154 4
        $this->lastUpdateTime = $lastUpdateTime;
155 4
    }
156
    
157 1
    public function getOverageCentsPerVisitor()
158
    {
159 1
        return $this->overageCentsPerVisitor;
160
    }
161
    
162 4
    public function setOverageCentsPerVisitor($overageCentsPerVisitor)
163
    {
164 4
        $this->overageCentsPerVisitor = $overageCentsPerVisitor;
165 4
    }
166
    
167 3
    public function getProductName()
168
    {
169 3
        return $this->productName;
170
    }
171
    
172 4
    public function setProductName($productName)
173
    {
174 4
        $this->productName = $productName;
175 4
    }
176
    
177 3
    public function getProjects()
178
    {
179 3
        return $this->projects;
180
    }
181
    
182 4
    public function setProjects($projects)
183
    {
184 4
        $this->projects = $projects;
185 4
    }
186
    
187 1
    public function getStartTime()
188
    {
189 1
        return $this->startTime;
190
    }
191
    
192 4
    public function setStartTime($startTime)
193
    {
194 4
        $this->startTime = $startTime;
195 4
    }
196
    
197 1
    public function getUsage()
198
    {
199 1
        return $this->usage;
200
    }
201
    
202 4
    public function setUsage($usage)
203
    {
204 4
        $this->usage = $usage;
205 4
    }
206
    
207 1
    public function getUsageAllowance()
208
    {
209 1
        return $this->usageAllowance;
210
    }
211
    
212 4
    public function setUsageAllowance($usageAllowance)
213
    {
214 4
        $this->usageAllowance = $usageAllowance;
215 4
    }
216
}
217
218
219
220
221
222
223
224
225
226