Passed
Push — master ( 6fae9a...ddbc6b )
by Seth
01:51
created

Entry::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 3
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/** Entry */
3
4
namespace Battis\SharedLogs\Objects;
5
6
use Battis\SharedLogs\AbstractObject;
7
8
/**
9
 * A log entry
10
 *
11
 * Log entries are timestamped notes authored by users and referring to a specific device.
12
 *
13
 * @author Seth Battis <[email protected]>
14
 */
15
class Entry extends AbstractObject
16
{
17
    /** Suppress log sub-object */
18
    const SUPPRESS_LOG = false;
19
20
    /** Suppress user sub-object */
21
    const SUPPRESS_USER = false;
22
23
    /** Canonical field name for references to entry objects in the database */
24
    const ID = 'entry_id';
25
26
    /**
27
     * Construct an Entry object from a database record
28
     *
29
     * @param array $databaseRecord Associative array of fields
30
     * @param Log|false $log (Optional) Log sub-object (or `Entry::SUPPRESS_LOG`)
31
     * @param User|false $user (Optional) User sub-object (or `Entry::SUPPRESS_USER`)
32
     *
33
     * @throws \Battis\SharedLogs\Exceptions\ObjectException
34
     */
35 6
    public function __construct($databaseRecord, $log = self::SUPPRESS_LOG, $user = self::SUPPRESS_USER)
36
    {
37 6
        parent::__construct($databaseRecord);
38
39 5
        if ($log instanceof Log) {
40 3
            $this->log = $log;
0 ignored issues
show
Bug introduced by
The property log does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
        }
42 5
        if ($user instanceof User) {
43 3
            $this->user = $user;
0 ignored issues
show
Bug introduced by
The property user does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
        }
45 5
    }
46
}
47