Passed
Push — master ( 534b0c...8bd354 )
by Matt
05:44
created

Droplet::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace Billow\Droplets;
3
use RuntimeException;
4
/**
5
 * @author Matt Frost<[email protected]
6
 * @package Billow
7
 * @license http://opensource.org/licenses/MIT MIT
8
 * @method validate ensure all required values are set
9
 * @method toJson represent the droplet as JSON
10
 * @method toArray represent the droplet as an Array
11
 * @method setImage set the image name
12
 */
13
abstract class Droplet 
14
{
15
    /**
16
     * ID for the droplet
17
     *
18
     * @var id
19
     */
20
    private $id;
0 ignored issues
show
Unused Code introduced by
The property $id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
21
22
    /**
23
     * Name for the droplet
24
     *
25
     * @var string name
26
     */
27
    protected $name;
28
29
    /**
30
     * Region slug in which to deploy the box
31
     *
32
     * @var string region
33
     */
34
    protected $region;
35
36
    /**
37
     * Size of the box
38
     *
39
     * @var string size
40
     */
41
    protected $size;
42
43
    /**
44
     * Size slug of the droplet
45
     *
46
     * @var string size_slug
47
     */
48
    protected $size_slug;
49
50
    /**
51
     * Image info for the droplet 
52
     *
53
     * @var array image
54
     */
55
    protected $image;
56
57
    /**
58
     * Memory for the droplet
59
     *
60
     * @var int memory
61
     */
62
    protected $memory;
63
64
    /**
65
     * Virtual CPUS for the droplet
66
     *
67
     * @var int vcpus
68
     */
69
    protected $vcpus;
70
71
    /**
72
     * Disk size for the droplet
73
     *
74
     * @var int size
75
     */
76
    protected $disk;
77
78
    /**
79
     * Lock status of droplet
80
     *
81
     * @var bool locked
82
     */
83
    protected $locked;
84
85
    /**
86
     * Status of the droplet
87
     *
88
     * @var string status
89
     */
90
    protected $status;
91
92
    /**
93
     * Kernel info for the droplet
94
     *
95
     * @var array kernel
96
     */
97
    protected $kernel;
98
99
    /**
100
     * Creation Date of the droplet
101
     *
102
     * @var string created_at
103
     */
104
    protected $created_at;
105
106
    /**
107
     * Features available on the droplet
108
     *
109
     * @var array features
110
     */
111
    protected $features;
112
113
    /**
114
     * Backup IDs for the droplet
115
     *
116
     * @var array backup_ids
117
     */
118
    protected $backup_ids;
119
120
    /**
121
     * Snapshot IDs for the droplet
122
     *
123
     * @var array snapshot_ids
124
     */
125
    protected $snapshot_ids;
126
127
    /**
128
     * Networks the droplet resides on
129
     *
130
     * @var array networks
131
     */
132
    protected $networks;
133
134
    /**
135
     * Constructor - this is a value object, so values must be set
136
     * at the time of instantiation
137
     *
138
     * @params array $boxData
139
     */
140
    public function __construct(Array $boxData)
141
    {
142
        foreach ($boxData as $key => $value) {
143
            $this->$key = $value;
144
        }
145
    }
146
147
    /**
148
     * Method to represent the box as JSON
149
     *
150
     * @return string
151
     */
152
    public function toJSON()
153
    {
154
        return json_encode($this->toArray()); 
155
    }
156
157
    /**
158
     * Method to represent the box as an Array
159
     *
160
     * @return Array
161
     */
162
    public function toArray()
163
    {
164
        return get_object_vars($this);
165
    }
166
167
    /**
168
     * PHP Magic method for handling property retrieval for non-existant
169
     * properties
170
     *
171
     * @param string $name
172
     * @return null
173
     */
174
    public function __get($name)
175
    {
176
        return null;
177
    }
178
179
    /**
180
     * PHP Magic method for handling propery assignment for non-existant
181
     * properties
182
     *
183
     * @param string $name
184
     * @param mixed $value
185
     */
186
    public function __set($name, $value)
187
    {
188
        // do not allow the setting of non-existant properties
189
    }
190
}
191