NewsRepository::refactorAllImagesByShopId()   B
last analyzed

Complexity

Conditions 8
Paths 10

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 16
nc 10
nop 1
dl 0
loc 22
rs 8.4444
c 0
b 0
f 0
1
<?php 
2
3
namespace Hideyo\Ecommerce\Framework\Services\News\Entity;
4
 
5
use Hideyo\Ecommerce\Framework\Services\News\Entity\News;
6
use Hideyo\Ecommerce\Framework\Services\News\Entity\NewsImage;
7
use Hideyo\Ecommerce\Framework\Services\News\Entity\NewsGroup;
8
use Carbon\Carbon;
9
use Image;
10
use File;
11
use Validator;
12
use Hideyo\Ecommerce\Framework\Services\BaseRepository;
13
14
class NewsRepository  extends BaseRepository 
15
{
16
17
    /**
18
     * Note: please keep logic in this repository. Put logic not in models,
19
     * Information about models in Laravel: http://laravel.com/docs/5.1/eloquent
20
     * @author     Matthijs Neijenhuijs <[email protected]>
21
     * @copyright  DutchBridge - dont share/steel!
22
     */
23
24
    protected $model;
25
26
    public function __construct(News $model, NewsImage $modelImage, NewsGroup $modelGroup)
27
    {
28
        $this->model = $model;
29
        $this->modelImage = $modelImage;
0 ignored issues
show
Bug Best Practice introduced by
The property modelImage does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
        $this->modelGroup = $modelGroup;
0 ignored issues
show
Bug Best Practice introduced by
The property modelGroup does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
        $this->storageImagePath = storage_path() .config('hideyo.storage_path'). "/news/";
0 ignored issues
show
Bug Best Practice introduced by
The property storageImagePath does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
        $this->publicImagePath = public_path() .config('hideyo.public_path'). "/news/";
0 ignored issues
show
Bug Best Practice introduced by
The property publicImagePath does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
    }
34
  
35
    /**
36
     * The validation rules for the model.
37
     *
38
     * @param  integer  $id id attribute model    
39
     * @return array
40
     */
41
    public function rules($newsId = false, $attributes = false)
42
    {
43
        if (isset($attributes['seo'])) {
44
            $rules = array(
45
                'meta_title'                 => 'required|between:4,65|unique_with:'.$this->model->getTable().', shop_id'
46
            );
47
        } else {
48
            $rules = array(
49
                'title'                 => 'required|between:4,65|unique:'.$this->model->getTable().''
50
            );
51
            
52
            if ($newsId) {
53
                $rules['title'] =   'required|between:4,65|unique:'.$this->model->getTable().',title,'.$newsId;
54
            }
55
        }
56
57
        return $rules;
58
    }
59
60
    public function rulesGroup($newsGroupId = false, $attributes = false)
61
    {
62
        if (isset($attributes['seo'])) {
63
            $rules = array(
64
                'meta_title'                 => 'required|between:4,65|unique_with:'.$this->modelGroup->getTable().', shop_id'
65
            );
66
        } else {
67
            $rules = array(
68
                'title'                 => 'required|between:4,65|unique:'.$this->modelGroup->getTable()
69
            );
70
            
71
            if ($newsGroupId) {
72
                $rules['title'] =   'required|between:4,65|unique:'.$this->modelGroup->getTable().',title,'.$newsGroupId;
73
            }
74
        }
75
76
        return $rules;
77
    }
78
79
    public function create(array $attributes)
80
    {
81
        $attributes['shop_id'] = auth('hideyobackend')->user()->selected_shop_id;
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
82
        $validator = Validator::make($attributes, $this->rules());
83
84
        if ($validator->fails()) {
85
            return $validator;
86
        }
87
88
        $attributes['modified_by_user_id'] = auth('hideyobackend')->user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
89
        $this->model->fill($attributes);
90
        $this->model->save();
91
        return $this->model;
92
    }
93
94
    public function updateById(array $attributes, $id)
95
    {
96
        $attributes['shop_id'] = auth('hideyobackend')->user()->selected_shop_id;
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
97
        $validator = Validator::make($attributes, $this->rules($id));
98
        if ($validator->fails()) {
99
            return $validator;
100
        }
101
102
        $this->model = $this->find($id);
103
        $attributes['modified_by_user_id'] = auth('hideyobackend')->user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
104
        return $this->updateEntity($attributes);   
105
    }  
106
107
    public function createImage(array $attributes, $newsId)
108
    {
109
        $userId = auth('hideyobackend')->user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
110
        $shopId = auth('hideyobackend')->user()->selected_shop_id;
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
111
        $shop = ShopService::find($shopId);
0 ignored issues
show
Bug introduced by
The type Hideyo\Ecommerce\Framewo...News\Entity\ShopService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
112
        $attributes['modified_by_user_id'] = $userId;
113
        $destinationPath = $this->storageImagePath.$newsId;
114
        $attributes['user_id'] = $userId;
115
        $attributes['news_id'] = $newsId;
116
        $attributes['extension'] = $attributes['file']->getClientOriginalExtension();
117
        $attributes['size'] = $attributes['file']->getSize();
118
       
119
        $rules = array(
120
            'file'=>'required|image|max:1000',
121
            'rank' => 'required'
122
        );
123
124
        $validator = Validator::make($attributes, $rules);
125
126
        if ($validator->fails()) {
127
            return $validator;
128
        } 
129
130
        $filename =  str_replace(" ", "_", strtolower($attributes['file']->getClientOriginalName()));
131
        $uploadSuccess = $attributes['file']->move($destinationPath, $filename);
132
133
        if ($uploadSuccess) {
134
            $attributes['file'] = $filename;
135
            $attributes['path'] = $uploadSuccess->getRealPath();
136
     
137
            $this->modelImage->fill($attributes);
138
            $this->modelImage->save();
139
140
            if ($shop->thumbnail_square_sizes) {
141
                $sizes = explode(',', $shop->thumbnail_square_sizes);
142
                if ($sizes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $sizes of type string[] 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...
143
                    foreach ($sizes as $valueImage) {
144
                        $image = Image::make($uploadSuccess->getRealPath());
145
                        $explode = explode('x', $valueImage);
146
                        $image->resize($explode[0], $explode[1]);
147
                        $image->interlace();
148
149
                        if (!File::exists($this->publicImagePath.$valueImage."/".$newsId."/")) {
150
                            File::makeDirectory($this->publicImagePath.$valueImage."/".$newsId."/", 0777, true);
151
                        }
152
                        $image->save($this->publicImagePath.$valueImage."/".$newsId."/".$filename);
153
                    }
154
                }
155
            }
156
            
157
            return $this->modelImage;
158
        }
159
        
160
    }
161
162
163
    public function createGroup(array $attributes)
164
    {
165
        $attributes['shop_id'] = auth('hideyobackend')->user()->selected_shop_id;
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
166
        $validator = Validator::make($attributes, $this->rulesGroup());
167
168
        if ($validator->fails()) {
169
            return $validator;
170
        }
171
172
        $attributes['modified_by_user_id'] = auth('hideyobackend')->user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
173
            
174
        $this->modelGroup->fill($attributes);
175
        $this->modelGroup->save();
176
   
177
        return $this->modelGroup;
178
    }
179
    
180
    public function refactorAllImagesByShopId($shopId)
181
    {
182
        $result = $this->modelImage->get();
183
        $shop = ShopService::find($shopId);
184
        foreach ($result as $productImage) {
185
            if ($shop->thumbnail_square_sizes) {
186
                $sizes = explode(',', $shop->thumbnail_square_sizes);
187
                if ($sizes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $sizes of type string[] 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...
188
                    foreach ($sizes as $valueImage) {
189
                        if (!File::exists($this->publicImagePath.$valueImage."/".$productImage->news_id."/")) {
190
                            File::makeDirectory($this->publicImagePath.$valueImage."/".$productImage->news_id."/", 0777, true);
191
                        }
192
193
                        if (!File::exists($this->publicImagePath.$valueImage."/".$productImage->news_id."/".$productImage->file)) {
194
                            if (File::exists($this->storageImagePath.$productImage->news_id."/".$productImage->file)) {
195
                                $image = Image::make(storage_path() .config('hideyo.storage_path'). "//news/".$productImage->news_id."/".$productImage->file);
196
                                $explode = explode('x', $valueImage);
197
                                $image->fit($explode[0], $explode[1]);
198
                            
199
                                $image->interlace();
200
201
                                $image->save(public_path() .config('hideyo.storage_path'). "/news/".$valueImage."/".$productImage->news_id."/".$productImage->file);
202
                            }
203
                        }
204
                    }
205
                }
206
            }
207
        }
208
    }
209
210
    public function updateImageById(array $attributes, $newsId, $newsImageId)
0 ignored issues
show
Unused Code introduced by
The parameter $newsId 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

210
    public function updateImageById(array $attributes, /** @scrutinizer ignore-unused */ $newsId, $newsImageId)

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...
211
    {
212
        $attributes['modified_by_user_id'] = auth('hideyobackend')->user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
213
        $this->modelImage = $this->findImage($newsImageId);
0 ignored issues
show
Bug Best Practice introduced by
The property modelImage does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
214
        return $this->updateImageEntity($attributes);
215
    }
216
217
    public function updateImageEntity(array $attributes = array())
218
    {
219
        if (count($attributes) > 0) {
220
            $this->modelImage->fill($attributes);
221
            $this->modelImage->save();
222
        }
223
224
        return $this->modelImage;
225
    }
226
227
    public function updateGroupById(array $attributes, $newsGroupId)
228
    {
229
        $validator = Validator::make($attributes, $this->rulesGroup($newsGroupId, $attributes));
230
231
        if ($validator->fails()) {
232
            return $validator;
233
        }
234
235
        $attributes['modified_by_user_id'] = auth('hideyobackend')->user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
236
        $this->modelGroup = $this->findGroup($newsGroupId);
0 ignored issues
show
Bug Best Practice introduced by
The property modelGroup does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
237
        return $this->updateGroupEntity($attributes);
238
    }
239
240
    public function updateGroupEntity(array $attributes = array())
241
    {
242
        if (count($attributes) > 0) {
243
            $this->modelGroup->fill($attributes);
244
            $this->modelGroup->save();
245
        }
246
247
        return $this->modelGroup;
248
    }
249
250
    public function destroy($newsId)
251
    {
252
        $this->model = $this->find($newsId);
253
254
        if ($this->model->newsImages->count()) {
255
            foreach ($this->model->newsImages as $image) {
256
                $this->newsImage->destroy($image->id);
0 ignored issues
show
Bug Best Practice introduced by
The property newsImage does not exist on Hideyo\Ecommerce\Framewo...s\Entity\NewsRepository. Did you maybe forget to declare it?
Loading history...
257
            }
258
        }
259
260
        $directory = app_path() . "/storage/files/news/".$this->model->id;
261
        File::deleteDirectory($directory);
262
263
        return $this->model->delete();
264
    }
265
266
    public function destroyImage($newsImageId)
267
    {
268
        $this->modelImage = $this->findImage($newsImageId);
0 ignored issues
show
Bug Best Practice introduced by
The property modelImage does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
269
        $filename = $this->storageImagePath.$this->modelImage->news_id."/".$this->modelImage->file;
270
        $shopId = auth('hideyobackend')->user()->selected_shop_id;
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
271
        $shop = ShopService::find($shopId);
272
273
        if (File::exists($filename)) {
274
            File::delete($filename);
275
            if ($shop->thumbnail_square_sizes) {
276
                $sizes = explode(',', $shop->thumbnail_square_sizes);
277
                if ($sizes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $sizes of type string[] 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...
278
                    foreach ($sizes as $valueImage) {
279
                        File::delete($this->publicImagePath.$valueImage."/".$this->modelImage->news_id."/".$this->modelImage->file);
280
                    }
281
                }
282
            }
283
        }
284
285
        return $this->modelImage->delete();
286
    }
287
288
    public function destroyGroup($newsGroupId)
289
    {
290
        $this->modelGroup = $this->findGroup($newsGroupId);
0 ignored issues
show
Bug Best Practice introduced by
The property modelGroup does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
291
        $this->modelGroup->save();
292
        return $this->modelGroup->delete();
293
    }
294
295
    public function selectAllGroups()
296
    {
297
       return $this->model->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->get();
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
298
    }
299
300
    public function findGroup($groupId)
301
    {
302
        return $this->modelGroup->find($groupId);
303
    }
304
305
    public function getGroupModel()
306
    {
307
        return $this->modelGroup;
308
    }
309
310
    public function findImage($imageId)
311
    {
312
        return $this->modelImage->find($imageId);
313
    }
314
315
    public function getImageModel()
316
    {
317
        return $this->modelImage;
318
    }
319
320
    function selectOneBySlug($shopId, $slug)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Unused Code introduced by
The parameter $shopId 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

320
    function selectOneBySlug(/** @scrutinizer ignore-unused */ $shopId, $slug)

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...
321
    {
322
        $dt = Carbon::now('Europe/Amsterdam');
323
        return $this->model->where('slug', $slug)->where('published_at', '<=', $dt->toDateString('Y-m-d'))->get()->first();
0 ignored issues
show
Unused Code introduced by
The call to Carbon\Carbon::toDateString() has too many arguments starting with 'Y-m-d'. ( Ignorable by Annotation )

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

323
        return $this->model->where('slug', $slug)->where('published_at', '<=', $dt->/** @scrutinizer ignore-call */ toDateString('Y-m-d'))->get()->first();

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
324
    }
325
326
    function selectAllByBlogCategoryId($newsCategoryId)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
327
    {
328
           return $this->model->with(array('extraFields' => function ($query) {
0 ignored issues
show
Unused Code introduced by
The parameter $query 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

328
           return $this->model->with(array('extraFields' => function (/** @scrutinizer ignore-unused */ $query) {

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...
329
           }, 'taxRate', 'newsCategory',  'relatedBlogs' => function ($query) {
330
            $query->with('newsImages')->orderBy('rank', 'asc');
331
           }, 'newsImages' => function ($query) {
332
            $query->orderBy('rank', 'asc');
333
           }))->where('active', 1)->where('news_category_id', '=', $newsCategoryId)->get();
334
    }
335
336
    function selectOneById($shopId, $slug)
0 ignored issues
show
Unused Code introduced by
The parameter $slug 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

336
    function selectOneById($shopId, /** @scrutinizer ignore-unused */ $slug)

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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Unused Code introduced by
The parameter $shopId 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

336
    function selectOneById(/** @scrutinizer ignore-unused */ $shopId, $slug)

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...
337
    {
338
        $dt = Carbon::now('Europe/Amsterdam');
339
        $result = $this->model->with(array('newsCategory', 'relatedBlogs', 'newsImages' => function ($query) {
340
            $query->orderBy('rank', 'asc');
341
        }))->where('published_at', '<=', $dt->toDateString('Y-m-d'))->where('active', 1)->where('id', $id)->get()->first();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
Unused Code introduced by
The call to Carbon\Carbon::toDateString() has too many arguments starting with 'Y-m-d'. ( Ignorable by Annotation )

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

341
        }))->where('published_at', '<=', $dt->/** @scrutinizer ignore-call */ toDateString('Y-m-d'))->where('active', 1)->where('id', $id)->get()->first();

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
342
        return $result;
343
    }
344
345
    function selectAllActiveGroupsByShopId($shopId)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
346
    {
347
         return $this->modelGroup->where('shop_id', $shopId)->where('active', 1)->get();
348
    }
349
350
    function selectOneGroupByShopIdAndSlug($shopId, $slug)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
351
    {
352
        $result = $this->modelGroup->where('shop_id', $shopId)->where('slug', $slug)->get();
353
        
354
        if ($result->isEmpty()) {
355
            return false;
356
        }
357
        return $result->first();
358
    }
359
360
    public function selectByLimitAndOrderBy($shopId, $limit, $orderBy)
361
    {
362
        $dt = Carbon::now('Europe/Amsterdam');
363
364
        return $this->model->with(
365
            array('newsImages' => function ($query) {
366
                $query->orderBy('rank', 'asc');
367
            })
368
        )
369
        ->limit($limit)
370
        ->where('shop_id', $shopId)
371
        ->where('published_at', '<=', $dt->toDateString('Y-m-d'))
0 ignored issues
show
Unused Code introduced by
The call to Carbon\Carbon::toDateString() has too many arguments starting with 'Y-m-d'. ( Ignorable by Annotation )

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

371
        ->where('published_at', '<=', $dt->/** @scrutinizer ignore-call */ toDateString('Y-m-d'))

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
372
        ->orderBy('created_at', $orderBy)->get();
373
    }
374
375
    function selectAllByShopIdAndPaginate($shopId, $totalPage, $filters = false)
0 ignored issues
show
Unused Code introduced by
The parameter $filters 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

375
    function selectAllByShopIdAndPaginate($shopId, $totalPage, /** @scrutinizer ignore-unused */ $filters = false)

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...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
376
    {
377
        $dt = Carbon::now('Europe/Amsterdam');
378
379
           $result = $this->model
380
           ->where('shop_id', $shopId)
381
           ->where('published_at', '<=', $dt->toDateString('Y-m-d'));
0 ignored issues
show
Unused Code introduced by
The call to Carbon\Carbon::toDateString() has too many arguments starting with 'Y-m-d'. ( Ignorable by Annotation )

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

381
           ->where('published_at', '<=', $dt->/** @scrutinizer ignore-call */ toDateString('Y-m-d'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
382
383
            return array(
384
                'totals' => $result->get()->count(),
385
                'totalPages' => ceil($result->get()->count() / $totalPage),
386
                'result' => $result->paginate($totalPage),
387
                'totalOnPage' => $totalPage
388
            );
389
    }
390
391
    function selectByGroupAndByShopIdAndPaginate($shopId, $newsGroupSlug, $totalPage, $filters = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Unused Code introduced by
The parameter $filters 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

391
    function selectByGroupAndByShopIdAndPaginate($shopId, $newsGroupSlug, $totalPage, /** @scrutinizer ignore-unused */ $filters = false)

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...
392
    {
393
        $dt = Carbon::now('Europe/Amsterdam');
394
395
           $result = $this->model
396
           ->where('shop_id', $shopId)
397
           ->where('published_at', '<=', $dt->toDateString('Y-m-d'))
0 ignored issues
show
Unused Code introduced by
The call to Carbon\Carbon::toDateString() has too many arguments starting with 'Y-m-d'. ( Ignorable by Annotation )

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

397
           ->where('published_at', '<=', $dt->/** @scrutinizer ignore-call */ toDateString('Y-m-d'))

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
398
           ->whereHas('newsGroup', function ($query) use ($newsGroupSlug) {
399
            $query->where('slug', '=', $newsGroupSlug);
400
           });
401
402
            return array(
403
                'totals' => $result->get()->count(),
404
                'totalPages' => ceil($result->get()->count() / $totalPage),
405
                'result' => $result->paginate($totalPage),
406
                'totalOnPage' => $totalPage
407
            );
408
    }
409
}