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

Document::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0185
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
}