Passed
Pull Request — master (#71)
by
unknown
03:27
created

getRequestToBeSync()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 4
dl 0
loc 20
rs 9.8333
1
<?php
2
3
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use Illuminate\Support\Arr;
5
use Illuminate\Support\Facades\Config;
6
use Jenssegers\Mongodb\Eloquent\Model;
7
8
if (! function_exists('getTranslatedContent')) {
9
10
    /**
11
     * @param  array  $mlCollection
12
     * @return string
13
     */
14
    function getTranslatedContent($mlCollection)
15
    {
16
        //Get current Lang
17
        $cl = Config::get('app.locale');
18
19
        if (is_array($mlCollection) && (array_key_exists('en_EN', $mlCollection) || array_key_exists('it_IT', $mlCollection) || ! is_null($mlCollection || ! isset($destination)))) {
0 ignored issues
show
introduced by
The condition is_null($mlCollection || ! IssetNode) is always false.
Loading history...
Comprehensibility Best Practice introduced by
The variable $destination seems to never exist and therefore isset should always be false.
Loading history...
Bug Best Practice introduced by
The expression $mlCollection of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
20
            return $mlCollection[$cl];
21
        } else {
22
            return '';
23
        }
24
    }
25
}
26
27
if (! function_exists('cl')) {
28
29
    /**
30
     * @return string current Lang
31
     */
32
    function cl()
33
    {
34
        //Get current Lang
35
        return Config::get('app.locale');
36
    }
37
}
38
39
if (! function_exists('ml')) {
40
    //save a localized field
41
    /**
42
     * @param  array  $destination
43
     * @param  string  $input
44
     * @return array ready to be saved
45
     */
46
    function ml($destination, $input)
47
    {
48
        if (is_null($destination)) {
0 ignored issues
show
introduced by
The condition is_null($destination) is always false.
Loading history...
49
            $destination = [];
50
        }
51
52
        return array_merge($destination, [cl() => $input]);
53
    }
54
}
55
56
if (! function_exists('isML')) {
57
    function isML($value)
58
    {
59
        if (array_key_exists('is-ml', $value)) {
60
            return $value['is-ml'];
61
        } else {
62
            return false;
63
        }
64
    }
65
}
66
67
if (! function_exists('isMD')) {
68
    function isMD($value)
69
    {
70
        if (array_key_exists('is-md', $value)) {
71
            return $value['is-md'];
72
        } else {
73
            return false;
74
        }
75
    }
76
}
77
78
if (! function_exists('is_EM')) {
79
    function is_EM($value)
80
    {
81
        if ($value === 'EmbedsMany') {
82
            return true;
83
        } else {
84
            return false;
85
        }
86
    }
87
}
88
89
if (! function_exists('is_EO')) {
90
    function is_EO($value)
91
    {
92
        if ($value === 'EmbedsOne') {
93
            return true;
94
        } else {
95
            return false;
96
        }
97
    }
98
}
99
100
if (! function_exists('is_HM')) {
101
    function is_HM($value)
102
    {
103
        if ($value === 'HasMany') {
104
            return true;
105
        } else {
106
            return false;
107
        }
108
    }
109
}
110
111
if (! function_exists('is_HO')) {
112
    function is_HO($value)
113
    {
114
        if ($value === 'HasOne') {
115
            return true;
116
        } else {
117
            return false;
118
        }
119
    }
120
}
121
122
if (! function_exists('isEditable')) {
123
    function isEditable($value)
124
    {
125
        if (array_key_exists('is-editable', $value)) {
126
            return $value['is-editable'];
127
        } else {
128
            return true;
129
        }
130
    }
131
}
132
133
if (! function_exists('hasTarget')) {
134
    function hasTarget($value)
135
    {
136
        if (array_key_exists('has-target', $value)) {
137
            return $value['has-target'];
138
        } else {
139
            return true;
140
        }
141
    }
142
}
143
144
if (! function_exists('isFillable')) {
145
    function isFillable($value, $event)
146
    {
147
        if ($event === 'add') {
148
            return true;
149
        } else {
150
            return isEditable($value);
151
        }
152
    }
153
}
154
155
if (! function_exists('getAID')) {
156
    /**
157
     * @param  Model  $model
158
     * @return string
159
     */
160
    function getAID(Model $model)
161
    {
162
        //Get Last Obj
163
        $obj = $model->orderBy('created_at', 'desc')->first();
164
165
        return is_null($obj) ? 1 : $obj->autoincrement_id + 1;
166
    }
167
}
168
169
if (! function_exists('getArrayWithEmptyObj')) {
170
171
    /**
172
     * @param $model
173
     * @return array
174
     */
175
    function getArrayWithEmptyObj($model, $is_EO, $is_EM)
0 ignored issues
show
Unused Code introduced by
The parameter $is_EM is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

175
    function getArrayWithEmptyObj($model, $is_EO, /** @scrutinizer ignore-unused */ $is_EM)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
176
    {
177
        $arr = [];
178
        if ($is_EO) {
179
            $obj = new stdClass();
180
            $embedObj = new $model;
181
            $EOitems = $embedObj->getItems();
182
183
            //Current Obj Create
184
            foreach ($EOitems as $EOkey => $item) {
185
                $obj->$EOkey = null;
186
            }
187
188
            $arr[] = $obj;
189
        }// $is_EM == empty array
190
191
        return $arr;
192
    }
193
}
194
195
if (! function_exists('getCounterForRelationships')) {
196
197
    /**
198
     * @param $method
199
     * @param $is_EO
200
     * @param $is_EM
201
     * @param $i
202
     * @return string
203
     */
204
    function getCounterForRelationships($method, $is_EO, $is_EM, $i)
205
    {
206
        if ($method === '' || ($method !== '' && $is_EO) || ($method === '' && $is_EM)) {
207
            return '';
208
        } else {
209
            return '-'.$i;
210
        }
211
    }
212
213
    if (! function_exists('getTypeOnTarget')) {
214
        function getTypeOnTarget($relation)
215
        {
216
            return Arr::has($relation, 'typeOnTarget') ? Arr::get($relation, 'typeOnTarget') : 'EmbedsMany';
217
        }
218
    }
219
}
220