ResponseModel::getData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alive
5
 * Date: 1/11/18
6
 * Time: 6:56 AM
7
 */
8
9
namespace Alive2212\LaravelSmartResponse;
10
11
use Alive2212\ArrayHelper\ArrayHelper;
12
use Illuminate\Support\Arr;
13
use Illuminate\Support\Collection;
14
15
class ResponseModel
16
{
17
    protected $message;
18
    protected $data;
19
    protected $error;
20
    protected $statusCode;
21
22
    public function __construct()
23
    {
24
        $this->data = new Collection();
25
        $this->message = '';
26
        $this->error = array();
27
        $this->statusCode = 200;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getMessage(): string
34
    {
35
        return $this->message;
36
    }
37
38
    /**
39
     * @param string $message
40
     */
41
    public function setMessage(string $message)
42
    {
43
        $this->message = $message;
44
    }
45
46
    /**
47
     * @return Collection
48
     */
49
    public function getData(): Collection
50
    {
51
        return $this->data;
52
    }
53
54
    /**
55
     * @param Collection $collection
56
     */
57
    public function setData(Collection $collection)
58
    {
59
        $this->data = $collection;
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function getError():array
66
    {
67
        return $this->error;
68
    }
69
70
    /**
71
     * @param array $error
72
     */
73
    public function setError(array $error)
74
    {
75
        $this->error = $error;
76
    }
77
78
    /**
79
     * @return int
80
     */
81
    public function getStatusCode():int
82
    {
83
        return $this->statusCode;
84
    }
85
86
    /**
87
     * @param mixed $statusCode
88
     */
89
    public function setStatusCode(int $statusCode)
90
    {
91
        $this->statusCode = $statusCode;
92
    }
93
94
    /**
95
     * @param Collection $data
96
     * @param array $params
97
     */
98
    public function setBeautifulData(Collection $data, array $params)
99
    {
100
        $result = [];
101
        foreach ($data->get('data') as $datum) {
102
            $innerResult = [];
103
            foreach ($params as $paramKey => $paramValue) {
104
                if (is_array($paramValue)) {
105
                    $innerResultArray = [];
106
                    foreach ($paramValue as $innerParamKey => $innerParamValues) {
107
                        $innerData = (new ArrayHelper())->getDeep($datum, $innerParamKey);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $innerData is correct as new Alive2212\ArrayHelpe...$datum, $innerParamKey) targeting Alive2212\ArrayHelper\ArrayHelper::getDeep() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
108
                        foreach ($innerData as $innerDatum) {
0 ignored issues
show
Bug introduced by
The expression $innerData of type null is not traversable.
Loading history...
109
                            $tempArray = [];
110
                            foreach ($innerParamValues as $innerParamValueKey => $innerParamValueValue) {
111
                                $tempArray = Arr::add($tempArray, $innerParamValueKey, (new ArrayHelper())->getDeep($innerDatum, $innerParamValueValue));
0 ignored issues
show
Bug introduced by
Are you sure the usage of new Alive2212\ArrayHelpe... $innerParamValueValue) targeting Alive2212\ArrayHelper\ArrayHelper::getDeep() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
112
                            }
113
                            array_push($innerResultArray, $tempArray);
114
                        }
115
                    }
116
                    if (collect($innerResultArray)->count()) {
117
                        $innerResult = Arr::add($innerResult, $paramKey, $innerResultArray);
118
                    } else {
119
                        $innerResult = Arr::add($innerResult, $paramKey, null);
120
                    }
121
                } else {
122
                    $innerResult = Arr::add($innerResult, $paramKey, (new ArrayHelper())->getDeep($datum, $paramValue));
0 ignored issues
show
Bug introduced by
Are you sure the usage of new Alive2212\ArrayHelpe...ep($datum, $paramValue) targeting Alive2212\ArrayHelper\ArrayHelper::getDeep() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
123
                }
124
            }
125
            array_push($result, $innerResult);
126
        }
127
        $data->offsetSet('data', $result);
128
        $this->data = $data;
129
    }
130
}