ProductsRepository   C
last analyzed

Complexity

Total Complexity 55

Size/Duplication

Total Lines 387
Duplicated Lines 3.36 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 55
lcom 2
cbo 5
dl 13
loc 387
rs 6.8
c 0
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A getModel() 0 4 1
A getPublic() 0 6 1
A find() 13 13 2
B create() 0 16 10
C update() 0 22 11
A reformatDateString() 0 10 1
A dateToTimestamp() 0 6 1
A delete() 0 4 1
B getSomeRandomProducts() 0 28 4
A findDrafted() 0 7 1
A getCount() 0 7 1
A countInLotProduct() 0 6 1
B search() 0 30 5
A formatSale() 0 6 1
A getSameProduct() 0 15 1
A getPublicLatest() 0 9 1
A getFeaturedPublic() 0 10 1
A getPublicExpireSoon() 0 11 1
C getExpireSoon() 0 24 7
A createPlain() 0 18 1
A saveProduct() 0 14 2

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ProductsRepository often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ProductsRepository, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace App\Repositories;
4
5
use App\ImprovedSpec;
6
use App\SpecPrice;
7
use App\Lot;
8
use App\Product;
9
use Carbon\Carbon;
10
use Illuminate\Database\Eloquent\Model;
11
use Mockery\CountValidator\Exception;
12
13
class ProductsRepository extends Repository
14
{
15
    /**
16
     * @return Product
17
     */
18
    public function getModel()
19
    {
20
        return new Product();
21
    }
22
23
    /**
24
     * Get all published products
25
     *
26
     * @return mixed
27
     */
28
    public function getPublic()
29
    {
30
        return self::getModel()
0 ignored issues
show
Bug introduced by
The method published() does not exist on App\Product. Did you maybe mean scopePublished()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
31
            ->published()
32
            ->get();
33
    }
34
35
    /**
36
     * Find product by id/slug.
37
     *
38
     * @param $slug
39
     * @return Product
40
     */
41 View Code Duplication
    public function find($slug)
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...
42
    {
43
        if (is_numeric($slug))
44
            return $this->getModel()
0 ignored issues
show
Documentation Bug introduced by
The method whereId does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
45
                ->whereId((int) $slug)
46
//                ->whereIn('status', ['published', 'drafted', 'notverified', 'completed'])
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
                ->first();
48
49
        return $this->getModel()
0 ignored issues
show
Documentation Bug introduced by
The method whereSlug does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
50
            ->whereSlug($slug)
51
//            ->whereIn('status', ['published', 'drafted', 'notverified', 'completed'])
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52
            ->first();
53
    }
54
55
    /**
56
     * Create product.
57
     * 
58
     * @param array $data
59
     * @return Product
60
     */
61
    public function create(array $data)
62
    {
63
        return self::getModel()
64
            ->create([
65
                'vendor_id' => $data['vendor_id'],
66
                'name' => (isset($data['name']) ? $data['name'] : ''),
67
                'price' => (isset($data['price']) ? $data['price'] : ''),
68
                'sale' => (isset($data['sale'])) ? $data['sale'] : 0,
69
                'count' => (isset($data['count'])) ? $data['count'] : 1,
70
                'type' => (isset($data['type'])) ? $data['type'] : 'new',
71
                'status' => (isset($data['status'])) ? $data['status'] : 'drafted',
72
                'published_date' => (isset($data['published_date']) ? $data['published_date'] : Carbon::now()),
73
                'expiration_date' => (isset($data['expiration_date']) ? $data['expiration_date'] : Carbon::now()),
74
                'active' => (isset($data['active']) ? $data['active'] : 0)
75
            ]);
76
    }
77
78
    /**
79
     * Update data.
80
     *
81
     * @param $product
82
     * @param $data
83
     * @return mixed
84
     */
85
    public function update($product, $data)
86
    {
87
        if(! $product instanceof Model)
88
            throw new Exception('First argument MUST be an instance of '.Model::class);
89
90
        $product->fill([
91
            'name'            => (isset($data['name']) ? $data['name'] : $product->name),
92
            'price'           => (isset($data['price']) ? $data['price'] : $product->price),
93
            'sale'            => (isset($data['sale'])) ? $this->formatSale($data['sale']) : $product->sale,
94
            'count'           => (isset($data['count'])) ? $data['count'] : $product->count,
95
            'description'     => (isset($data['description'])) ? $data['description'] : $product->description,
96
            'type'            => (isset($data['type'])) ? $data['type'] : 'new',
97
            'status'          => ($product->status == 'drafted') ? 'notverified' : $product->status,
98
            'published_date'  => (isset($data['published_date']) ? $this->dateToTimestamp($data['published_date']) : $product->published_date),
99
            'expiration_date' => (isset($data['expiration_date']) ? $this->dateToTimestamp($data['expiration_date']) : $product->published_date),
100
            'active'          => 1
101
        ]);
102
103
        $product->save();
104
105
        return $product;
106
    }
107
108
    /**
109
     * Reformat date.
110
     *
111
     * @param $date
112
     * @param string $delimiter
113
     * @return mixed
114
     */
115
    public function reformatDateString($date, $delimiter = '.')
116
    {
117
        $datas = explode($delimiter, $date);
118
119
        $new_date['d'] = $datas[0];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$new_date was never initialized. Although not strictly required by PHP, it is generally a good practice to add $new_date = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
120
        $new_date['m'] = $datas[1];
121
        $new_date['y'] = $datas[2];
122
123
        return $new_date;
124
    }
125
126
    /**
127
     * Convert string date to \Carbon/Carbon timestamp.
128
     *
129
     * @param $date
130
     * @return static
131
     */
132
    public function dateToTimestamp($date)
133
    {
134
        $dates = $this->reformatDateString($date);
135
136
        return Carbon::createFromDate($dates['y'], $dates['m'], $dates['d']);
137
    }
138
139
    /**
140
     * Remove product row from table.
141
     *
142
     * @param $id
143
     * @return bool|null
144
     * @throws \Exception
145
     */
146
    public function delete($id)
147
    {
148
        return $this->find($id)->delete();
149
    }
150
151
    /**
152
     * Get random products.
153
     *
154
     * @return \Illuminate\Database\Eloquent\Collection
155
     */
156
    public function getSomeRandomProducts()
157
    {
158
        $random_element_1 = rand(1, 2);
159
        $random_element_2 = rand(1, 2);
160
        $random_element_3 = rand(1, 2);
161
162
        $query = self::getModel()->select('*');
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
163
164
        if ($random_element_1 == 1) {
165
            $query->published();
166
        } else {
167
            $query->drafted();
168
        }
169
170
        if ($random_element_2 == 1) {
171
            $query->whereType('old');
172
        } else {
173
            $query->whereType('new');
174
        }
175
176
        if ($random_element_3 == 1) {
177
            $query->whereBetween('sale', [1, 50]);
178
        } else {
179
            $query->whereBetween('sale', [51, 100]);
180
        }
181
182
        return $query->get();
183
    }
184
185
    /**
186
     * Get drafted product by id.
187
     * 
188
     * @param $id
189
     * @return mixed
190
     */
191
    public function findDrafted($id)
192
    {
193
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method whereId does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
194
            ->whereId($id)
195
            ->drafted()
196
            ->first();
197
    }
198
199
    public function getCount($id)
200
    {
201
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method whereId does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
202
            ->whereId($id)
203
            ->pluck('count')
204
            ->first();
205
    }
206
207
    public function countInLotProduct($id)
208
    {
209
        return self::getModel()
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
210
            ->where('lot_id',$id)
211
            ->count();
212
    }
213
214
    public function search($filters)
215
    {
216
217
        $product = $filters['search'];
218
219
        if(isset($filters['category']))
220
            $category = $filters['category'];
221
222
        if(empty($product) && (!isset($category)))
223
            return null;
224
225
        if(isset($category))
226
        {
227
            $query = $this->getModel()
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
228
                ->select('products.*', 'categoryable.category_id')
229
                ->where('products.name', 'like', '%'.$product.'%')
230
                ->join('categoryable', 'products.id', '=', 'categoryable.categoryable_id')
231
                ->where('categoryable.categoryable_type', get_class(self::getModel()))
232
                ->where('categoryable.category_id', $category);
233
        } else
234
        {
235
            $query = $this->getModel()
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
236
                ->where('name', 'like', '%'.$product.'%');
237
        }
238
239
        $query->where('products.active', 1);
240
            /*->whereIn('active', ['published', 'completed']);*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
241
242
        return $query->get();
243
    }
244
245
    /**
246
     * Remove percent from sale if it exists.
247
     *
248
     * @param $sale
249
     * @return int
250
     */
251
    private function formatSale($sale)
252
    {
253
        list($sale, $percent) = explode('%', $sale);
0 ignored issues
show
Unused Code introduced by
The assignment to $percent is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
254
255
        return (int) $sale;
256
    }
257
258
    /**
259
     * Get same products.
260
     *
261
     * @param mixed
262
     */
263
    public function getSameProduct($id,$limit=10)
264
    {
265
        $query = $this->getModel()
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
266
            ->select('products.*')
267
            ->where('sub_category_id',$id)
268
            ->where('products.active', 1)
269
            /*->where('lots.expire_date', '>', Carbon::now())*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
270
            ->limit($limit);
271
272
        $query->join('lots', 'lots.id', '=', 'products.lot_id')
273
            ->where('lots.verify_status', 'verified');
274
275
        return $query->get();
276
277
    }
278
279
    /**
280
     * Get public latest created products.
281
     *
282
     * @param int $count
283
     * @return mixed
284
     */
285
    public function getPublicLatest($count = 8)
286
    {
287
        return $this->getModel()
0 ignored issues
show
Bug introduced by
The method active() does not exist on App\Product. Did you maybe mean scopeActive()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
288
            ->active()
289
//            ->published() // todo: on production back it.
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
290
            ->orderBy('id', self::DESC)
291
            ->take($count)
292
            ->get();
293
    }
294
295
    /**
296
     * Get popular products.
297
     *
298
     * @return mixed
299
     */
300
    public function getFeaturedPublic($count = 8)
301
    {
302
        return $this->getModel()
0 ignored issues
show
Bug introduced by
The method featured() does not exist on App\Product. Did you maybe mean scopeFeatured()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
303
//            ->published()
304
            ->featured()
305
            ->active()
306
            ->orderBy('id', self::DESC)
307
            ->take($count)
308
            ->get();
309
    }
310
311
    /**
312
     * Get expire soon products.
313
     *
314
     * @param int $count
315
     * @return mixed
316
     */
317
    public function getPublicExpireSoon($count = 8)
318
    {
319
        return $this->getModel()
0 ignored issues
show
Bug introduced by
The method active() does not exist on App\Product. Did you maybe mean scopeActive()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
320
//            ->published()
321
            ->active()
322
//            ->where('expiration_date', '>', Carbon::now())
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
323
//            ->orderBy('expiration_date', self::ASC)
324
            ->orderBy('id', self::ASC)
325
            ->take($count)
326
            ->get();
327
    }
328
329
    /**
330
     * Expire soon products.
331
     *
332
     * @param int $paginate
333
     * @return mixed
334
     */
335
    public function getExpireSoon($paginate = 10)
336
    {
337
        $query = $this->getModel()
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Product>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
338
            ->select('products.*')
339
            ->where('products.active', 1)
340
            ->where('lots.expire_date', '>', Carbon::now())
341
            ->orderBy('lots.expire_date', self::ASC);
342
343
        if(request()->get('name'))
344
            $query->orderBy('products.name', request()->get('name') == self::ASC ? self::ASC : self::DESC);
345
346
        if(request()->get('created_at'))
347
            $query->orderBy('products.created_at', request()->get('created_at') == self::ASC ? self::ASC : self::DESC);
348
349
        if(request()->get('price'))
350
            $query->orderBy('products.price', request()->get('price') == self::ASC ? self::ASC : self::DESC);
351
352
        $query->join('lots', 'lots.id', '=', 'products.lot_id')
353
            ->where('lots.status', Lot::STATUS_COMPLETE)
354
            ->where('lots.verify_status', Lot::STATUS_VERIFY_ACCEPTED);
355
356
//        return $query->orderBy('id', self::ASC)
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
357
            return $query->paginate($paginate);
358
    }
359
360
    /**
361
     * Create plain product for \App\Lot $lot
362
     *
363
     * @param Lot $lot
364
     * @return static
365
     */
366
    public function createPlain(Lot $lot)
367
    {
368
        $product = self::getModel()
369
            ->create([
370
                'lot_id' => $lot->id,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Lot>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
371
                'uniqid' => substr(str_replace('.','',uniqid('00'.rand(),true)),0,10)
372
373
            ]);
374
        /*$spec_price =  SpecPrice::create([
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
375
            'product_id' => $product->id
376
        ]);
377
        ImprovedSpec::create([
378
            'product_id' => $product->id,
379
            'price_spec_id' => $spec_price->id
380
        ]);*/
381
382
        return $product;
383
    }
384
385
    public function saveProduct($product, array $data)
386
    {
387
        $product->fill([
388
            /*'name'            => isset($data['name']) ? $data['name'] : null,
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
389
            'old_price'       => isset($data['old_price']) ? $data['old_price'] : null,
390
            'price'           => isset($data['price']) ? $data['price'] : null,
391
            'sale'            => isset($data['sale']) ? $data['sale'] : null,*/
392
            'sub_category_id' => isset($data['sub_category']) ? $data['sub_category'] : null
393
        ]);
394
395
        $product->save();
396
397
        return $product;
398
    }
399
}