Spellcheck   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 80
Duplicated Lines 10 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 8
loc 80
ccs 0
cts 48
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 4 1
A suggestions() 0 8 2
A numFound() 0 8 2
A startOffset() 0 8 2
A endOffset() 0 8 2
A collation() 8 8 2
A __toString() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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