ProductExtraFieldValueRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A selectOneByShopIdAndSlug() 0 3 1
A __construct() 0 4 1
A selectOneByShopIdAndId() 0 3 1
A selectByProductIdAndExtraFieldId() 0 4 1
A selectAllByProductId() 0 3 1
A selectAllByProductCategoryId() 0 15 1
1
<?php
2
namespace Hideyo\Ecommerce\Framework\Services\Product\Entity;
3
 
4
use Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductExtraFieldValue;
5
use Hideyo\Ecommerce\Framework\Services\Product\Entity\ProductRepository;
6
use Hideyo\Ecommerce\Framework\Services\BaseRepository;
7
 
8
class ProductExtraFieldValueRepository extends BaseRepository 
9
{
10
11
    protected $model;
12
13
    public function __construct(ProductExtraFieldValue $model, ProductRepository $product)
14
    {
15
        $this->model = $model;
16
        $this->product = $product;
0 ignored issues
show
Bug Best Practice introduced by
The property product does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17
    }
18
  
19
 
20
    public function selectAllByProductId($productId)
21
    {
22
        return $this->model->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->where('product_id', '=', $productId)->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...
23
    }
24
25
    public function selectByProductIdAndExtraFieldId($productId, $extraFieldId)
26
    {
27
28
        return $this->model->where('shop_id', auth('hideyobackend')->user()->selected_shop_id)->where('product_id', '=', $productId)->where('extra_field_id', '=', $extraFieldId)->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...
29
    }
30
31
    function selectOneByShopIdAndSlug($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...
32
    {
33
           return $this->model->with(array('productCategory', 'productImages'))->where('shop_id', $shopId)->where('slug', $slug)->get()->first();
34
    }
35
36
    function selectOneByShopIdAndId($shopId, $id)
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...
37
    {
38
           return $this->model->with(array('productCategory', 'productImages'))->where('shop_id', $shopId)->where('id', $id)->get()->first();
39
    }
40
41
    function selectAllByProductCategoryId($productCategoryId, $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...
42
    {
43
44
         return $this->model->
45
         whereHas('product', function ($query) use ($productCategoryId, $shopId) {
46
            $query->where('product_category_id', '=', $productCategoryId);
47
            $query->where('active', 1);
48
            $query->where('shop_id', $shopId);
49
         })->with(
50
             array(
51
                'extraFieldDefaultValue',
52
                'extraField' => function ($q) {
0 ignored issues
show
Unused Code introduced by
The parameter $q 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

52
                'extraField' => function (/** @scrutinizer ignore-unused */ $q) {

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...
53
                }
54
                )
55
         )->get();
56
    }
57
}