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

Document::createFromArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
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