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

Document   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createFromArray() 0 8 2
A set() 0 3 1
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