Passed
Push — master ( 4a3b26...2c1581 )
by Matthijs
02:02
created

selectAllByShopId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hideyo\Ecommerce\Framework\Services\Order;
4
 
5
use Hideyo\Ecommerce\Framework\Services\Order\Entity\OrderStatusEmailTemplate;
6
7
use Hideyo\Ecommerce\Framework\Services\Order\Entity\OrderStatusEmailTemplateRepository;
8
use Hideyo\Ecommerce\Framework\Services\BaseService;
9
use Validator;
0 ignored issues
show
Bug introduced by
The type Validator 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...
10
11
class OrderStatusEmailTemplateService extends BaseService
12
{
13
	public function __construct(OrderStatusEmailTemplateRepository $orderStatusEmailTemplate)
14
	{
15
		$this->repo = $orderStatusEmailTemplate;
0 ignored issues
show
Bug Best Practice introduced by
The property repo does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
	} 
17
18
19
20
21
    /**
22
     * The validation rules for the model.
23
     *
24
     * @param  integer  $id id attribute model    
25
     * @return array
26
     */
27
    private function rules($id = false, $attributes = false)
0 ignored issues
show
Unused Code introduced by
The parameter $attributes 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

27
    private function rules($id = false, /** @scrutinizer ignore-unused */ $attributes = 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...
28
    {
29
        $rules = array(
30
            'title' => 'required|unique_with:order_status_email_template, shop_id',
31
            'subject' => 'required',
32
            'content' => 'required'
33
        );
34
        
35
        if ($id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $id of type integer|false is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
36
            $rules['title'] =   'required|unique_with:order_status_email_template, shop_id,'.$id;
37
        }
38
39
        return $rules;
40
    }
41
  
42
    public function create(array $attributes)
43
    {
44
        $attributes['shop_id'] = auth('hideyobackend')->user()->selected_shop_id;
0 ignored issues
show
Bug introduced by
The function auth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

44
        $attributes['shop_id'] = /** @scrutinizer ignore-call */ auth('hideyobackend')->user()->selected_shop_id;
Loading history...
45
        $validator = \Validator::make($attributes, $this->rules());
46
47
        if ($validator->fails()) {
48
            return $validator;
49
        }
50
51
        $this->repo->getModel()->fill($attributes);
52
 
53
        $this->repo->getModel()->save();
54
        
55
        return $this->repo->getModel();
56
    }
57
58
    public function selectAllByShopId($shopId) {
59
        return $this->repo->selectAllByShopId($shopId);
60
    }
61
62
    public function updateById(array $attributes, $id)
63
    {
64
        $attributes['shop_id'] = auth('hideyobackend')->user()->selected_shop_id;
0 ignored issues
show
Bug introduced by
The function auth was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

64
        $attributes['shop_id'] = /** @scrutinizer ignore-call */ auth('hideyobackend')->user()->selected_shop_id;
Loading history...
65
        $validator = \Validator::make($attributes, $this->rules($id, $attributes));
66
67
        if ($validator->fails()) {
68
            return $validator;
69
        }
70
71
       
72
        $model = $this->find($id);
73
74
        $model->fill($attributes);
75
 
76
        $model->save();
77
78
        return $model;
79
80
    }
81
82
}