Document::addField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace PSolr\Request;
4
5
/**
6
 * @see http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema
7
 */
8
class Document
9
{
10
    /**
11
     * @var \PSolr\Request\Field[]
12
     */
13
    protected $fields = array();
14
15
    /**
16
     * @var float
17
     */
18
    protected $boost;
19
20
    /**
21
     * @param float $boost
22
     */
23
    public function __construct($boost = 0.0)
24
    {
25
        $this->setBoost($boost);
26
    }
27
28
    /**
29
     * @param float $boost
30
     *
31
     * @return \PSolr\Request\Document
32
     *
33
     * @see http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_on_.22doc.22
34
     */
35
    public function setBoost($boost)
36
    {
37
        $this->boost = $boost;
38
        return $this;
39
    }
40
41
    /**
42
     * @return float
43
     */
44
    public function getBoost($boost)
0 ignored issues
show
Unused Code introduced by
The parameter $boost is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        return $this->boost;
47
    }
48
49
    /**
50
     * @param \PSolr\Request\Field $field
51
     *
52
     * @return \PSolr\Request\Document
53
     */
54
    public function addField(Field $field)
55
    {
56
        $this->fields[$field->getName()] = $field;
57
        return $this;
58
    }
59
60
    /**
61
     * @param type $name
62
     * @param type $value
63
     */
64
    public function __set($name, $value)
65
    {
66
        if (isset($this->fields[$name])) {
67
            $this->fields[$name]->addValue($value);
68
        } else {
69
            $this->addField(new Field($name, $value));
70
        }
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function asXml()
77
    {
78
        $xml = '<doc>';
79
        foreach ($this->fields as $field) {
80
            $xml .= $field;
81
        }
82
        $xml .= '</doc>';
83
        return $xml;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function __toString()
90
    {
91
        return $this->asXml();
92
    }
93
}
94