Test Failed
Pull Request — master (#33)
by Giacomo
03:45
created

PlainMongoTrait::storeEditAllItems()   B

Complexity

Conditions 9
Paths 8

Size

Total Lines 43
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 43
rs 8.0555
cc 9
nc 8
nop 3
1
<?php
2
3
4
namespace OfflineAgency\MongoAutoSync\Traits;
5
6
7
use Exception;
8
use Illuminate\Http\Request;
9
use MongoDB\BSON\UTCDateTime;
10
11
trait PlainMongoTrait
12
{
13
    /**
14
     * @param Request $request
15
     * @param string $event
16
     * @param array $options
17
     * @throws Exception
18
     */
19
    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

19
    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...
20
    {
21
        //Get the item name
22
        $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

22
        /** @scrutinizer ignore-call */ 
23
        $items = $this->getItems();
Loading history...
23
24
        //Current Obj Create
25
        foreach ($items as $key => $item) {
26
            $is_ML = isML($item);
27
            $is_MD = isMD($item);
28
29
            $is_fillable = isFillable($item, $event);
30
            $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

30
            /** @scrutinizer ignore-call */ 
31
            $is_skippable = $this->getIsSkippable($request->has($key));
Loading history...
31
32
            if ($is_skippable) {
33
                continue;
34
            } else {
35
                $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

35
                $this->/** @scrutinizer ignore-call */ 
36
                       checkRequestExistence(
Loading history...
36
                    $request,
37
                    $key
38
                );
39
            }
40
41
            if ($is_fillable) {
42
                if ($is_ML) {
43
                    if (is_null($this->$key)) {
44
                        $old_value = [];
45
                    } else {
46
                        $old_value = $this->$key;
47
                    }
48
                    $this->$key = ml($old_value, $request->input($key));
49
                } elseif ($is_MD) {
50
                    if ($request->input($key) == '' || $request->input($key) == null) {
51
                        $this->$key = null;
52
                    } else {
53
                        $this->$key = new UTCDateTime(new DateTime($request->input($key)));
0 ignored issues
show
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

53
                        $this->$key = new UTCDateTime(/** @scrutinizer ignore-type */ new DateTime($request->input($key)));
Loading history...
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...
54
                    }
55
                } else {
56
                    $this->$key = $request->input($key);
57
                }
58
            }
59
        }
60
61
        $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

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