Completed
Pull Request — master (#147)
by Joel
06:10 queued 03:25
created

Container   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 531
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 44
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 531
rs 8.3396

44 Methods

Rating   Name   Duplication   Size   Complexity  
A getAppArmorProfile() 0 4 1
A setAppArmorProfile() 0 6 1
A getArgs() 0 4 1
A setArgs() 0 6 1
A getConfig() 0 4 1
A setConfig() 0 6 1
A getCreated() 0 4 1
A setCreated() 0 6 1
A getDriver() 0 4 1
A setDriver() 0 6 1
A getExecDriver() 0 4 1
A setExecDriver() 0 6 1
A getExecIDs() 0 4 1
A setExecIDs() 0 6 1
A getHostConfig() 0 4 1
A setHostConfig() 0 6 1
A getHostnamePath() 0 4 1
A setHostnamePath() 0 6 1
A getHostsPath() 0 4 1
A setHostsPath() 0 6 1
A getLogPath() 0 4 1
A setLogPath() 0 6 1
A getId() 0 4 1
A setId() 0 6 1
A getImage() 0 4 1
A setImage() 0 6 1
A getMountLabel() 0 4 1
A setMountLabel() 0 6 1
A getName() 0 4 1
A setName() 0 6 1
A getNetworkSettings() 0 4 1
A setNetworkSettings() 0 6 1
A getPath() 0 4 1
A setPath() 0 6 1
A getProcessLabel() 0 4 1
A setProcessLabel() 0 6 1
A getResolvConfPath() 0 4 1
A setResolvConfPath() 0 6 1
A getRestartCount() 0 4 1
A setRestartCount() 0 6 1
A getState() 0 4 1
A setState() 0 6 1
A getMounts() 0 4 1
A setMounts() 0 6 1

How to fix   Complexity   

Complex Class

Complex classes like Container often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Container, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Docker\API\Model;
4
5
class Container
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $appArmorProfile;
11
    /**
12
     * @var string[]
13
     */
14
    protected $args;
15
    /**
16
     * @var ContainerConfig
17
     */
18
    protected $config;
19
    /**
20
     * @var string
21
     */
22
    protected $created;
23
    /**
24
     * @var string
25
     */
26
    protected $driver;
27
    /**
28
     * @var string
29
     */
30
    protected $execDriver;
31
    /**
32
     * @var string
33
     */
34
    protected $execIDs;
35
    /**
36
     * @var HostConfig
37
     */
38
    protected $hostConfig;
39
    /**
40
     * @var string
41
     */
42
    protected $hostnamePath;
43
    /**
44
     * @var string
45
     */
46
    protected $hostsPath;
47
    /**
48
     * @var string
49
     */
50
    protected $logPath;
51
    /**
52
     * @var string
53
     */
54
    protected $id;
55
    /**
56
     * @var string
57
     */
58
    protected $image;
59
    /**
60
     * @var string
61
     */
62
    protected $mountLabel;
63
    /**
64
     * @var string
65
     */
66
    protected $name;
67
    /**
68
     * @var NetworkConfig
69
     */
70
    protected $networkSettings;
71
    /**
72
     * @var string
73
     */
74
    protected $path;
75
    /**
76
     * @var string
77
     */
78
    protected $processLabel;
79
    /**
80
     * @var string
81
     */
82
    protected $resolvConfPath;
83
    /**
84
     * @var int
85
     */
86
    protected $restartCount;
87
    /**
88
     * @var ContainerState
89
     */
90
    protected $state;
91
    /**
92
     * @var Mount[]
93
     */
94
    protected $mounts;
95
96
    /**
97
     * @return string
98
     */
99
    public function getAppArmorProfile()
100
    {
101
        return $this->appArmorProfile;
102
    }
103
104
    /**
105
     * @param string $appArmorProfile
106
     *
107
     * @return self
108
     */
109
    public function setAppArmorProfile($appArmorProfile = null)
110
    {
111
        $this->appArmorProfile = $appArmorProfile;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return string[]
118
     */
119
    public function getArgs()
120
    {
121
        return $this->args;
122
    }
123
124
    /**
125
     * @param string[] $args
126
     *
127
     * @return self
128
     */
129
    public function setArgs(array $args = null)
130
    {
131
        $this->args = $args;
0 ignored issues
show
Documentation Bug introduced by
It seems like $args can be null. However, the property $args is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
132
133
        return $this;
134
    }
135
136
    /**
137
     * @return ContainerConfig
138
     */
139
    public function getConfig()
140
    {
141
        return $this->config;
142
    }
143
144
    /**
145
     * @param ContainerConfig $config
146
     *
147
     * @return self
148
     */
149
    public function setConfig(ContainerConfig $config = null)
150
    {
151
        $this->config = $config;
152
153
        return $this;
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    public function getCreated()
160
    {
161
        return $this->created;
162
    }
163
164
    /**
165
     * @param string $created
166
     *
167
     * @return self
168
     */
169
    public function setCreated($created = null)
170
    {
171
        $this->created = $created;
172
173
        return $this;
174
    }
175
176
    /**
177
     * @return string
178
     */
179
    public function getDriver()
180
    {
181
        return $this->driver;
182
    }
183
184
    /**
185
     * @param string $driver
186
     *
187
     * @return self
188
     */
189
    public function setDriver($driver = null)
190
    {
191
        $this->driver = $driver;
192
193
        return $this;
194
    }
195
196
    /**
197
     * @return string
198
     */
199
    public function getExecDriver()
200
    {
201
        return $this->execDriver;
202
    }
203
204
    /**
205
     * @param string $execDriver
206
     *
207
     * @return self
208
     */
209
    public function setExecDriver($execDriver = null)
210
    {
211
        $this->execDriver = $execDriver;
212
213
        return $this;
214
    }
215
216
    /**
217
     * @return string
218
     */
219
    public function getExecIDs()
220
    {
221
        return $this->execIDs;
222
    }
223
224
    /**
225
     * @param string $execIDs
226
     *
227
     * @return self
228
     */
229
    public function setExecIDs($execIDs = null)
230
    {
231
        $this->execIDs = $execIDs;
232
233
        return $this;
234
    }
235
236
    /**
237
     * @return HostConfig
238
     */
239
    public function getHostConfig()
240
    {
241
        return $this->hostConfig;
242
    }
243
244
    /**
245
     * @param HostConfig $hostConfig
246
     *
247
     * @return self
248
     */
249
    public function setHostConfig(HostConfig $hostConfig = null)
250
    {
251
        $this->hostConfig = $hostConfig;
252
253
        return $this;
254
    }
255
256
    /**
257
     * @return string
258
     */
259
    public function getHostnamePath()
260
    {
261
        return $this->hostnamePath;
262
    }
263
264
    /**
265
     * @param string $hostnamePath
266
     *
267
     * @return self
268
     */
269
    public function setHostnamePath($hostnamePath = null)
270
    {
271
        $this->hostnamePath = $hostnamePath;
272
273
        return $this;
274
    }
275
276
    /**
277
     * @return string
278
     */
279
    public function getHostsPath()
280
    {
281
        return $this->hostsPath;
282
    }
283
284
    /**
285
     * @param string $hostsPath
286
     *
287
     * @return self
288
     */
289
    public function setHostsPath($hostsPath = null)
290
    {
291
        $this->hostsPath = $hostsPath;
292
293
        return $this;
294
    }
295
296
    /**
297
     * @return string
298
     */
299
    public function getLogPath()
300
    {
301
        return $this->logPath;
302
    }
303
304
    /**
305
     * @param string $logPath
306
     *
307
     * @return self
308
     */
309
    public function setLogPath($logPath = null)
310
    {
311
        $this->logPath = $logPath;
312
313
        return $this;
314
    }
315
316
    /**
317
     * @return string
318
     */
319
    public function getId()
320
    {
321
        return $this->id;
322
    }
323
324
    /**
325
     * @param string $id
326
     *
327
     * @return self
328
     */
329
    public function setId($id = null)
330
    {
331
        $this->id = $id;
332
333
        return $this;
334
    }
335
336
    /**
337
     * @return string
338
     */
339
    public function getImage()
340
    {
341
        return $this->image;
342
    }
343
344
    /**
345
     * @param string $image
346
     *
347
     * @return self
348
     */
349
    public function setImage($image = null)
350
    {
351
        $this->image = $image;
352
353
        return $this;
354
    }
355
356
    /**
357
     * @return string
358
     */
359
    public function getMountLabel()
360
    {
361
        return $this->mountLabel;
362
    }
363
364
    /**
365
     * @param string $mountLabel
366
     *
367
     * @return self
368
     */
369
    public function setMountLabel($mountLabel = null)
370
    {
371
        $this->mountLabel = $mountLabel;
372
373
        return $this;
374
    }
375
376
    /**
377
     * @return string
378
     */
379
    public function getName()
380
    {
381
        return $this->name;
382
    }
383
384
    /**
385
     * @param string $name
386
     *
387
     * @return self
388
     */
389
    public function setName($name = null)
390
    {
391
        $this->name = $name;
392
393
        return $this;
394
    }
395
396
    /**
397
     * @return NetworkConfig
398
     */
399
    public function getNetworkSettings()
400
    {
401
        return $this->networkSettings;
402
    }
403
404
    /**
405
     * @param NetworkConfig $networkSettings
406
     *
407
     * @return self
408
     */
409
    public function setNetworkSettings(NetworkConfig $networkSettings = null)
410
    {
411
        $this->networkSettings = $networkSettings;
412
413
        return $this;
414
    }
415
416
    /**
417
     * @return string
418
     */
419
    public function getPath()
420
    {
421
        return $this->path;
422
    }
423
424
    /**
425
     * @param string $path
426
     *
427
     * @return self
428
     */
429
    public function setPath($path = null)
430
    {
431
        $this->path = $path;
432
433
        return $this;
434
    }
435
436
    /**
437
     * @return string
438
     */
439
    public function getProcessLabel()
440
    {
441
        return $this->processLabel;
442
    }
443
444
    /**
445
     * @param string $processLabel
446
     *
447
     * @return self
448
     */
449
    public function setProcessLabel($processLabel = null)
450
    {
451
        $this->processLabel = $processLabel;
452
453
        return $this;
454
    }
455
456
    /**
457
     * @return string
458
     */
459
    public function getResolvConfPath()
460
    {
461
        return $this->resolvConfPath;
462
    }
463
464
    /**
465
     * @param string $resolvConfPath
466
     *
467
     * @return self
468
     */
469
    public function setResolvConfPath($resolvConfPath = null)
470
    {
471
        $this->resolvConfPath = $resolvConfPath;
472
473
        return $this;
474
    }
475
476
    /**
477
     * @return int
478
     */
479
    public function getRestartCount()
480
    {
481
        return $this->restartCount;
482
    }
483
484
    /**
485
     * @param int $restartCount
486
     *
487
     * @return self
488
     */
489
    public function setRestartCount($restartCount = null)
490
    {
491
        $this->restartCount = $restartCount;
492
493
        return $this;
494
    }
495
496
    /**
497
     * @return ContainerState
498
     */
499
    public function getState()
500
    {
501
        return $this->state;
502
    }
503
504
    /**
505
     * @param ContainerState $state
506
     *
507
     * @return self
508
     */
509
    public function setState(ContainerState $state = null)
510
    {
511
        $this->state = $state;
512
513
        return $this;
514
    }
515
516
    /**
517
     * @return Mount[]
518
     */
519
    public function getMounts()
520
    {
521
        return $this->mounts;
522
    }
523
524
    /**
525
     * @param Mount[] $mounts
526
     *
527
     * @return self
528
     */
529
    public function setMounts(array $mounts = null)
530
    {
531
        $this->mounts = $mounts;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mounts can be null. However, the property $mounts is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
532
533
        return $this;
534
    }
535
}
536