Failed Conditions
Push — master ( fa3649...11c8ec )
by Bas
05:38
created

Document::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent;
4
5
/**
6
 * Class Document
7
 * Loosely based on ArangoDBClient\Document;
8
 * Laravel typecasts input data to an array which causes issues with protected variables (\0*\0 is prepended).
9
 * Thus we are using a very minimum version to gather data from ArangoDB through their PHP driver.
10
 */
11
class Document
12
{
13
    protected $options;
14
15 50
    public function __construct(array $options = null)
16
    {
17 50
        $this->options = $options;
18 50
    }
19
20 50
    public static function createFromArray($values, array $options = [])
21
    {
22 50
        $document = new self($options);
23 50
        foreach ($values as $key => $value) {
24 50
            $document->set($key, $value);
25
        }
26
27 50
        return $document;
28
    }
29
30
    /**
31
     * Set a document attribute.
32
     *
33
     * The key (attribute name) must be a string.
34
     * This will validate the value of the attribute and might throw an
35
     * exception if the value is invalid.
36
     *
37
     *
38
     * @param string $key   - attribute name
39
     * @param mixed  $value - value for attribute
40
     *
41
     * @return void
42
     */
43 50
    public function set($key, $value)
44
    {
45 50
        $this->$key = $value;
46 50
    }
47
}
48