Passed
Push — master ( cc3f84...4a930e )
by Timo
23:43
created

Document   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 38
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 8 2
A getFieldNames() 0 3 1
A getField() 0 3 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Solr\Document;
3
4
use RuntimeException;
5
use Solarium\QueryType\Update\Query\Document\Document as SolariumDocument;
6
7
class Document extends SolariumDocument {
8
9
    /**
10
     * Magic call method used to emulate getters as used by the template engine.
11
     *
12
     * @param    string $name method name
13
     * @param    array $arguments method arguments
14
     * @return mixed
15
     */
16 7
    public function __call($name, $arguments)
17
    {
18 7
        if (substr($name, 0, 3) == 'get') {
19 7
            $field = substr($name, 3);
20 7
            $field = strtolower($field[0]) . substr($field, 1);
21 7
            return $this->fields[$field] ?? null;
22
        } else {
23
            throw new RuntimeException('Call to undefined method. Supports magic getters only.', 1311006605);
24
        }
25
    }
26
27
    /**
28
     * @return array
29
     */
30
    public function getFieldNames()
31
    {
32
        return array_keys($this->fields);
33
    }
34
35
    /**
36
     * Backwards compatible implementation of the getField method.
37
     *
38
     * @deprecated Deprecated since EXT:solr 9.0.0 please use $document[$fieldName] instead without the array key 'value'
39
     * @param $fieldName
40
     * @return array|boolean
41
     */
42 9
    public function getField($fieldName)
43
    {
44 9
        return isset($this->fields[$fieldName]) ? ['value' => $this->fields[$fieldName]] : false;
45
    }
46
47
}