Passed
Push — master ( 12b03a...508f3d )
by Seth
08:34
created

Device::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.1825

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 3
dl 0
loc 16
ccs 8
cts 11
cp 0.7272
crap 3.1825
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/** Device */
3
4
namespace Battis\SharedLogs\Objects;
5
6
use Battis\SharedLogs\Exceptions\ObjectException;
7
use Battis\SharedLogs\AbstractObject;
8
9
/**
10
 * A device
11
 *
12
 * Devices are documented by logs of timestamped entries authored by users
13
 *
14
 * @property Url[] urls
15
 * @property Log[] logs
16
 * @author Seth Battis <[email protected]>
17
 */
18
class Device extends AbstractObject
19
{
20
    /** Suppress list of logs sub-object */
21
    const SUPPRESS_LOGS = false;
22
23
    const SUPPRESS_URLS = false;
24
25
    /** Canonical field name for references to devices in the database */
26
    const ID = 'device_id';
27
28
    /**
29
     * Construct a device from a database record
30
     *
31
     * @param array $databaseRecord Associative array of fields
32
     * @param Log[]|false $logs (Optional) List of logs sub-object (or `Device::SUPPRESS_LOGS`). Elements that are not
33
     *        instances of Log will be ignored.
34
     *
35
     * @throws ObjectException If `$databaseRecord` contains no fields
36
     */
37 5
    public function __construct($databaseRecord, $logs = self::SUPPRESS_LOGS, $urls = self::SUPPRESS_URLS)
38
    {
39 5
        parent::__construct($databaseRecord);
40
41 4
        if (is_array($urls)) {
42
            $this->urls = array_filter($urls, function($elt) {
43
               return $elt instanceof Url;
44
            });
45
        }
46
47 4
        if (is_array($logs)) {
48 2
            $this->logs = array_filter($logs, function ($elt) {
49 2
                return $elt instanceof Log;
50 2
            });
51
        }
52 4
    }
53
}
54