Spellcheck::suggestions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
namespace PSolr\Response;
4
5
class Spellcheck extends Response
6
{
7
    /**
8
     * Iterates over the suggestions
9
     *
10
     * @return \ArrayIterator
11
     */
12
    public function getIterator()
13
    {
14
        return new \ArrayIterator($this->suggestions());
15
    }
16
17
    /**
18
     * @return array
19
     */
20
    public function suggestions()
21
    {
22
        if (isset($this['spellcheck']['suggestions'][$this->params['q']]['suggestion'])) {
23
            return $this['spellcheck']['suggestions'][$this->params['q']]['suggestion'];
24
        } else {
25
            return array();
26
        }
27
    }
28
29
    /**
30
     * @return int
31
     */
32
    public function numFound()
33
    {
34
        if (isset($this['spellcheck']['suggestions'][$this->params['q']]['numFound'])) {
35
            return $this['spellcheck']['suggestions'][$this->params['q']]['numFound'];
36
        } else {
37
            return 0;
38
        }
39
    }
40
41
    /**
42
     * @return int
43
     */
44
    public function startOffset()
45
    {
46
        if (isset($this['spellcheck']['suggestions'][$this->params['q']]['startOffset'])) {
47
            return $this['spellcheck']['suggestions'][$this->params['q']]['startOffset'];
48
        } else {
49
            return 0;
50
        }
51
    }
52
53
    /**
54
     * @return int
55
     */
56
    public function endOffset()
57
    {
58
        if (isset($this['spellcheck']['suggestions'][$this->params['q']]['endOffset'])) {
59
            return $this['spellcheck']['suggestions'][$this->params['q']]['endOffset'];
60
        } else {
61
            return 0;
62
        }
63
    }
64
65
    /**
66
     * @return string
67
     */
68 View Code Duplication
    public function collation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        if (isset($this['spellcheck']['suggestions']['collation'])) {
71
            return $this['spellcheck']['suggestions']['collation'];
72
        } else {
73
            return '';
74
        }
75
    }
76
77
    /**
78
     * Returns the "collation", or recommendation.
79
     */
80
    public function __toString()
81
    {
82
        return $this->collation();
83
    }
84
}
85