Device   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 57
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getFieldValue() 0 12 3
A setCreated() 0 4 1
1
<?php
2
3
namespace PHPushbullet;
4
5
class Device
6
{
7
    /**
8
     * The fields that we want to retrieve for the device
9
     *
10
     * @var array $fields
11
     */
12
13
    protected $fields = [
14
        'nickname',
15
        'iden',
16
        'model',
17
        'type',
18
        'active',
19
        'pushable',
20
        'manufacturer',
21
        'created',
22
    ];
23
24 12
    public function __construct(array $attr)
25
    {
26 12
        foreach ($this->fields as $field) {
27 12
            $this->{$field} = $this->getFieldValue($attr, $field);
28 12
        }
29 12
    }
30
31
    /**
32
     * @param array $attr
33
     * @param string $field
34
     *
35
     * @return string
36
     */
37 12
    protected function getFieldValue(array $attr, $field)
38
    {
39 12
        $method = 'set' . ucwords($field);
40
41 12
        if (method_exists($this, $method)) {
42
            // If there is a setter for this field, use that
43 12
            return $this->{$method}($attr[$field]);
44
        }
45
46
        // Otherwise just set the property
47 12
        return (isset($attr[$field])) ? $attr[$field] : null;
48
    }
49
50
    /**
51
     * Format the date so that it's readable
52
     *
53
     * @param integer $date
54
     * @return string
55
     */
56
57 12
    protected function setCreated($date)
58
    {
59 12
        return date('Y-m-d h:i:sA T', $date);
60
    }
61
}
62