Result   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 107
Duplicated Lines 20.56 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 85.19%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 22
loc 107
ccs 23
cts 27
cp 0.8519
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTotalRows() 0 4 1
A getOffset() 0 4 1
A getRows() 0 4 1
A getFirstRow() 11 11 2
A getLastRow() 11 11 2
A toArray() 0 4 1
A getIterator() 0 4 1
A count() 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 CouchDB\DesignDocument;
4
5
/**
6
 * @author Markus Bachmann <[email protected]>
7
 */
8
class Result implements ResultInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $data;
14
15
    /**
16
     * Constructor.
17
     *
18
     * @param array $data
19
     */
20 7
    public function __construct(array $data)
21
    {
22 7
        $this->data = $data;
23 7
    }
24
25
    /**
26
     * Return the total amount of rows.
27
     *
28
     * @return int
29
     */
30 1
    public function getTotalRows()
31
    {
32 1
        return $this->data['total_rows'];
33
    }
34
35
    /**
36
     * Gets the offset.
37
     *
38
     * @return int
39
     */
40 1
    public function getOffset()
41
    {
42 1
        return $this->data['offset'];
43
    }
44
45
    /**
46
     * Return all rows.
47
     *
48
     * @return array
49
     */
50 1
    public function getRows()
51
    {
52 1
        return $this->data['rows'];
53
    }
54
55
    /**
56
     * Return the first row.
57
     *
58
     * @return bool|array
59
     */
60 1 View Code Duplication
    public function getFirstRow()
61
    {
62 1
        $rows = $this->data['rows'];
63 1
        if (empty($rows)) {
64
            return false;
65
        }
66
67 1
        $row = array_slice($rows, 0, 1);
68
69 1
        return current($row);
70
    }
71
72
    /**
73
     * Return the last row.
74
     *
75
     * @return bool|array
76
     */
77 1 View Code Duplication
    public function getLastRow()
78
    {
79 1
        $rows = $this->data['rows'];
80 1
        if (empty($rows)) {
81
            return false;
82
        }
83
84 1
        $row = array_slice($rows, count($rows) - 1);
85
86 1
        return current($row);
87
    }
88
89
    /**
90
     * Return the array.
91
     *
92
     * @return array
93
     */
94
    public function toArray()
95
    {
96
        return $this->data;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 1
    public function getIterator()
103
    {
104 1
        return new \ArrayIterator($this->data['rows']);
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110 1
    public function count()
111
    {
112 1
        return count($this->data['rows']);
113
    }
114
}
115