Completed
Push — cat-api ( f87ad4 )
by Daniel
03:23
created

AbstractAliasesCatResponse::processData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
ccs 8
cts 8
cp 1
rs 9.4286
cc 3
eloc 5
nc 3
nop 0
crap 3
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\Shared\Cat;
19
20
use Elastification\Client\Response\Response;
21
22
/**
23
 * Class AbstractAliasesCatResponse
24
 *
25
 * @package Elastification\Client\Response\Shared\Cat
26
 * @author  Daniel Wendlandt
27
 */
28
abstract class AbstractAliasesCatResponse extends Response
29
{
30
    const PROP_ALIAS = 'alias';
31
    const PROP_INDEX = 'index';
32
    const PROP_FILTER = 'filter';
33
    const PROP_ROUTING_INDEX = 'routing.index';
34
    const PROP_ROUTING_SEARCH = 'routing.search';
35
36
    /**
37
     * @inheritdoc
38
     */
39 2 View Code Duplication
    protected function processData()
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...
40
    {
41 2
        if (null === $this->data) {
42 2
            $rawData = $this->getRawData();
43
44 2
            if (null !== $rawData) {
45 2
                $this->data = $this->processCatData($rawData);
46 2
            }
47 2
        }
48 2
    }
49
50
    /**
51
     * This is our serializer ;)
52
     *
53
     * @param string $rawData
54
     *
55
     * @return array
56
     */
57 2
    protected function processCatData($rawData)
58
    {
59 2
        $data = array();
60 2
        $properties = $this->getProperties();
61 2
        $rows = explode(PHP_EOL, $rawData);
62
63 2
        foreach ($rows as $row) {
64 2
            if (mb_strlen($row) > 3) {
65 2
                $fields = array_filter(explode(' ', $row), function($value) {
66 2
                    return mb_strlen($value) !== 0;
67 2
                });
68
69 2
                $data[] = array_combine($properties, $fields);
70 2
            }
71 2
        }
72
73 2
        return $data;
74
    }
75
76
    /**
77
     * Provides properties of this cat request
78
     *
79
     * @return array
80
     */
81 2
    protected function getProperties()
82
    {
83
        return array(
84 2
            self::PROP_ALIAS,
85 2
            self::PROP_INDEX,
86 2
            self::PROP_FILTER,
87 2
            self::PROP_ROUTING_INDEX,
88
            self::PROP_ROUTING_SEARCH
89 2
        );
90
    }
91
}
92