Completed
Push — V2x ( ef7ee8 )
by Daniel
02:49
created

DocumentResponse   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 71
loc 71
ccs 22
cts 22
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hasSource() 6 6 1
A getSource() 8 8 2
A found() 6 6 1
A getId() 6 6 1
A getVersion() 6 6 1
A getIndex() 6 6 1
A getType() 6 6 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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
namespace Elastification\Client\Response\V2x;
19
20
use Elastification\Client\Exception\ResponseException;
21
use Elastification\Client\Response\Response;
22
23
/**
24
 * @package Elastification\Client\Response\V2x
25
 * @author  Daniel Wendlandt
26
 */
27 View Code Duplication
class DocumentResponse extends Response
0 ignored issues
show
Duplication introduced by
This class 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...
28
{
29
    const PROP_ID = '_id';
30
    const PROP_SOURCE = '_source';
31
    const PROP_FOUND = 'found';
32
    const PROP_VERSION = '_version';
33
    const PROP_INDEX = '_index';
34
    const PROP_TYPE = '_type';
35
36
    /**
37
     * checks if source exists
38
     *
39
     * @return bool
40
     */
41 5
    public function hasSource()
42
    {
43 5
        $this->processData();
44
45 5
        return $this->has(self::PROP_SOURCE);
46
    }
47
48
    /**
49
     * gets the source of the response
50
     *
51
     * @return array
52
     * @throws \Elastification\Client\Exception\ResponseException
53
     */
54 3
    public function getSource()
55
    {
56 3
        if (!$this->hasSource()) {
57 1
            throw new ResponseException(self::PROP_SOURCE . ' is not set.');
58
        }
59
60 2
        return $this->get(self::PROP_SOURCE);
61
    }
62
63 2
    public function found()
64
    {
65 2
        $this->processData();
66
67 2
        return $this->get(self::PROP_FOUND);
68
    }
69
70 2
    public function getId()
71
    {
72 2
        $this->processData();
73
74 2
        return $this->get(self::PROP_ID);
75
    }
76
77 2
    public function getVersion()
78
    {
79 2
        $this->processData();
80
81 2
        return $this->get(self::PROP_VERSION);
82
    }
83
84 2
    public function getIndex()
85
    {
86 2
        $this->processData();
87
88 2
        return $this->get(self::PROP_INDEX);
89
    }
90
91 2
    public function getType()
92
    {
93 2
        $this->processData();
94
95 2
        return $this->get(self::PROP_TYPE);
96
    }
97
}
98