Document   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 1
dl 0
loc 86
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setBoost() 0 5 1
A getBoost() 0 4 1
A addField() 0 5 1
A __set() 0 8 2
A asXml() 0 9 2
A __toString() 0 4 1
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