Passed
Push — master ( 3b373d...6530d8 )
by Giacomo
02:21 queued 11s
created

PlainMongoTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 28
c 1
b 0
f 0
dl 0
loc 51
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B storeEditAllItems() 0 43 9
1
<?php
2
3
namespace OfflineAgency\MongoAutoSync\Traits;
4
5
use Exception;
6
use Illuminate\Http\Request;
7
use MongoDB\BSON\UTCDateTime;
8
9
trait PlainMongoTrait
10
{
11
    /**
12
     * @param Request $request
13
     * @param string $event
14
     * @param array $options
15
     * @throws Exception
16
     */
17
    public function storeEditAllItems(Request $request, string $event, array $options)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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

17
    public function storeEditAllItems(Request $request, string $event, /** @scrutinizer ignore-unused */ array $options)

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...
18
    {
19
        //Get the item name
20
        $items = $this->getItems();
0 ignored issues
show
Bug introduced by
It seems like getItems() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

20
        /** @scrutinizer ignore-call */ 
21
        $items = $this->getItems();
Loading history...
21
22
        //Current Obj Create
23
        foreach ($items as $key => $item) {
24
            $is_ML = isML($item);
25
            $is_MD = isMD($item);
26
27
            $is_fillable = isFillable($item, $event);
28
            $is_skippable = $this->getIsSkippable($request->has($key));
0 ignored issues
show
Bug introduced by
It seems like getIsSkippable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

28
            /** @scrutinizer ignore-call */ 
29
            $is_skippable = $this->getIsSkippable($request->has($key));
Loading history...
29
30
            if ($is_skippable) {
31
                continue;
32
            } else {
33
                $this->checkRequestExistence(
0 ignored issues
show
Bug introduced by
It seems like checkRequestExistence() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

33
                $this->/** @scrutinizer ignore-call */ 
34
                       checkRequestExistence(
Loading history...
34
                    $request,
35
                    $key
36
                );
37
            }
38
39
            if ($is_fillable) {
40
                if ($is_ML) {
41
                    if (is_null($this->$key)) {
42
                        $old_value = [];
43
                    } else {
44
                        $old_value = $this->$key;
45
                    }
46
                    $this->$key = ml($old_value, $request->input($key));
47
                } elseif ($is_MD) {
48
                    if ($request->input($key) == '' || $request->input($key) == null) {
49
                        $this->$key = null;
50
                    } else {
51
                        $this->$key = new UTCDateTime(new DateTime($request->input($key)));
0 ignored issues
show
Bug introduced by
The type OfflineAgency\MongoAutoSync\Traits\DateTime was not found. Did you mean DateTime? If so, make sure to prefix the type with \.
Loading history...
Bug introduced by
new OfflineAgency\MongoA...($request->input($key)) of type OfflineAgency\MongoAutoSync\Traits\DateTime is incompatible with the type integer expected by parameter $milliseconds of MongoDB\BSON\UTCDateTime::__construct(). ( Ignorable by Annotation )

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

51
                        $this->$key = new UTCDateTime(/** @scrutinizer ignore-type */ new DateTime($request->input($key)));
Loading history...
52
                    }
53
                } else {
54
                    $this->$key = $request->input($key);
55
                }
56
            }
57
        }
58
59
        $this->save();
0 ignored issues
show
Bug introduced by
It seems like save() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

59
        $this->/** @scrutinizer ignore-call */ 
60
               save();
Loading history...
60
    }
61
}
62