PlainMongoTrait::storeEditAllItems()   B
last analyzed

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
namespace OfflineAgency\MongoAutoSync\Traits;
4
5
use DateTime;
6
use Exception;
7
use Illuminate\Http\Request;
8
use MongoDB\BSON\UTCDateTime;
9
10
trait PlainMongoTrait
11
{
12
    /**
13
     * @param  Request  $request
14
     * @param  string  $event
15
     * @param  array  $options
16
     *
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)));
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