Add   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 97
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A overwrite() 0 5 1
A commitWithin() 0 5 1
A addDocument() 0 5 1
B renderBody() 0 21 5
1
<?php
2
3
namespace PSolr\Request;
4
5
/**
6
 * @see http://wiki.apache.org/solr/UpdateXmlMessages#add.2Freplace_documents
7
 */
8
class Add extends SolrRequest
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $handlerName = 'update';
14
15
    /**
16
     * @var string
17
     */
18
    protected $responseClass = '\PSolr\Response\Response';
19
20
    /**
21
     * @var \PSolr\Request\Document[]
22
     */
23
    protected $documents = array();
24
25
    /**
26
     * @var boolean
27
     */
28
    protected $overwrite = null;
29
30
    /**
31
     * @var int
32
     */
33
    protected $commitWithin = 0;
34
35
    /**
36
     * @param array $params
37
     */
38
    public function __construct(array $params = array())
39
    {
40
        parent::__construct($params, null);
0 ignored issues
show
Unused Code introduced by
The call to SolrRequest::__construct() has too many arguments starting with null.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
41
    }
42
43
    /**
44
     * @param boolean $overwrite
45
     *
46
     * @return \PSolr\Request\Add
47
     *
48
     * @see http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22add.22
49
     */
50
    public function overwrite($overwrite = true)
51
    {
52
        $this->overwrite = $overwrite;
53
        return $this;
54
    }
55
56
    /**
57
     * @param int $commitWithin
58
     *
59
     * @return \PSolr\Request\Add
60
     *
61
     * @see http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22add.22
62
     */
63
    public function commitWithin($commitWithin)
64
    {
65
        $this->commitWithin = $commitWithin;
66
        return $this;
67
    }
68
69
    /**
70
     * @param \PSolr\Request\Document
71
     *
72
     * @return \PSolr\Request\Add
73
     */
74
    public function addDocument(Document $document)
75
    {
76
        $this->documents[] = $document;
77
        return $this;
78
    }
79
80
    /**
81
     * {@inheritDoc}
82
     */
83
    public function renderBody()
84
    {
85
        $attributes = '';
86
87
        if (isset($this->overwrite)) {
88
            $overwriteValue = $this->overwrite ? 'true' : 'false';
89
            $attributes .= ' overwrite="' . $overwriteValue . '"';
90
        }
91
92
        if (isset($this->commitWithin)) {
93
            $attributes .= ' commitWithin="' . (int) $this->commitWithin . '"';
94
        }
95
96
        $xml = '<add' . $attributes . '>';
97
        foreach ($this->documents as $document) {
98
            $xml .= $document;
99
        }
100
        $xml .= '</add>';
101
102
        return self::stripCtrlChars($xml);
103
    }
104
}
105