GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DuplicateOptions   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 6
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 6
cbo 1
dl 0
loc 155
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 10 2
A instance() 0 4 1
A excludeColumns() 0 6 1
A uniqueColumns() 0 6 1
A excludeRelations() 0 6 1
A excludeRelationColumns() 0 6 1
A uniqueRelationColumns() 0 6 1
A disableDeepDuplication() 0 6 1
1
<?php
2
3
namespace Neurony\Duplicate\Options;
4
5
use Exception;
6
use Illuminate\Support\Arr;
7
8
class DuplicateOptions
9
{
10
    /**
11
     * The database columns that should be ignored when duplicating the record.
12
     *
13
     * @var array|string
14
     */
15
    private $excludedColumns;
16
17
    /**
18
     * The database columns that should be unique when duplicating the record.
19
     *
20
     * @var array|string
21
     */
22
    private $uniqueColumns;
23
24
    /**
25
     * The relations of the model that should be ignored when duplicating the record.
26
     *
27
     * @var array|string
28
     */
29
    private $excludedRelations;
30
31
    /**
32
     * The database columns for each model's relation that should be ignored when duplicating the record.
33
     *
34
     * @var array
35
     */
36
    private $excludedRelationColumns;
37
38
    /**
39
     * The database columns for each model's relation that should be unique when duplicating the record.
40
     *
41
     * @var array
42
     */
43
    private $uniqueRelationColumns;
44
45
    /**
46
     * Flag indicating if when duplicating a record, the script should also duplicate it's relations.
47
     *
48
     * @var bool
49
     */
50
    private $shouldDuplicateDeeply = true;
51
52
    /**
53
     * Get the value of a property of this class.
54
     *
55
     * @param $name
56
     * @return mixed
57
     * @throws Exception
58
     */
59
    public function __get($name)
60
    {
61
        if (property_exists(static::class, $name)) {
62
            return $this->{$name};
63
        }
64
65
        throw new Exception(
66
            'The property "'.$name.'" does not exist in class "'.static::class.'"'
67
        );
68
    }
69
70
    /**
71
     * Get a fresh instance of this class.
72
     *
73
     * @return DuplicateOptions
74
     */
75
    public static function instance(): self
76
    {
77
        return new static();
78
    }
79
80
    /**
81
     * Set the $excludedColumns to work with in the Neurony\Duplicate\Traits\HasDuplicates trait.
82
     *
83
     * @param array|string $columns
84
     * @return DuplicateOptions
85
     */
86
    public function excludeColumns(...$columns): self
87
    {
88
        $this->excludedColumns = Arr::flatten($columns);
0 ignored issues
show
Documentation introduced by
$columns is of type array<integer,array|string>, but the function expects a object<Illuminate\Support\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
90
        return $this;
91
    }
92
93
    /**
94
     * Set the $uniqueColumns to work with in the Neurony\Duplicate\Traits\HasDuplicates trait.
95
     *
96
     * @param array|string $columns
97
     * @return DuplicateOptions
98
     */
99
    public function uniqueColumns(...$columns): self
100
    {
101
        $this->uniqueColumns = Arr::flatten($columns);
0 ignored issues
show
Documentation introduced by
$columns is of type array<integer,array|string>, but the function expects a object<Illuminate\Support\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
102
103
        return $this;
104
    }
105
106
    /**
107
     * Set the $excludedRelations to work with in the Neurony\Duplicate\Traits\HasDuplicates trait.
108
     *
109
     * @param array|string $relations
110
     * @return DuplicateOptions
111
     */
112
    public function excludeRelations(...$relations): self
113
    {
114
        $this->excludedRelations = Arr::flatten($relations);
0 ignored issues
show
Documentation introduced by
$relations is of type array<integer,array|string>, but the function expects a object<Illuminate\Support\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
115
116
        return $this;
117
    }
118
119
    /**
120
     * Set the $excludedRelationColumns to work with in the Neurony\Duplicate\Traits\HasDuplicates trait.
121
     *
122
     * Param $columns:
123
     * --- associative array with keys containing each relation name and values (array) containing the excluded columns for each relation.
124
     *
125
     * @param array $columns
126
     * @return DuplicateOptions
127
     */
128
    public function excludeRelationColumns(array $columns = []): self
129
    {
130
        $this->excludedRelationColumns = $columns;
131
132
        return $this;
133
    }
134
135
    /**
136
     * Set the $uniqueRelationColumns to work with in the Neurony\Duplicate\Traits\HasDuplicates trait.
137
     *
138
     * Param $columns:
139
     * --- associative array with keys containing each relation name and values (array) containing the unique columns for each relation.
140
     *
141
     * @param array $columns
142
     * @return DuplicateOptions
143
     */
144
    public function uniqueRelationColumns(array $columns = []): self
145
    {
146
        $this->uniqueRelationColumns = $columns;
147
148
        return $this;
149
    }
150
151
    /**
152
     * Set the $shouldDuplicateDeeply to work with in the Neurony\Duplicate\Traits\HasDuplicates trait.
153
     *
154
     * @return DuplicateOptions
155
     */
156
    public function disableDeepDuplication(): self
157
    {
158
        $this->shouldDuplicateDeeply = false;
159
160
        return $this;
161
    }
162
}
163