Test Setup Failed
Push — master ( 43367b...b13334 )
by Php Easy Api
04:33
created

Wizard::indexes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Migratio\GrammarStructure\Mysql\Wizard;
4
5
use Migratio\Contract\TablePropertiesContract;
6
use Migratio\Contract\WizardContract;
7
8
class Wizard extends WizardHelper implements WizardContract
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $alterBinds = array();
14
15
    /**
16
     * @var $randomInstance
0 ignored issues
show
Documentation Bug introduced by
The doc comment $randomInstance at position 0 could not be parsed: Unknown type name '$randomInstance' at position 0 in $randomInstance.
Loading history...
17
     */
18
    public static $randomInstance;
19
20
    /**
21
     * @var array $error
22
     */
23
    protected $error = array();
24
25
    /**
26
     * @var array
27
     */
28
    protected $alterType = [];
29
30
    /**
31
     * @var array
32
     */
33
    protected $auto_increment=array();
34
35
    /**
36
     * @var $collation
0 ignored issues
show
Documentation Bug introduced by
The doc comment $collation at position 0 could not be parsed: Unknown type name '$collation' at position 0 in $collation.
Loading history...
37
     */
38
    protected $collation;
39
40
    /**
41
     * @var $comment
0 ignored issues
show
Documentation Bug introduced by
The doc comment $comment at position 0 could not be parsed: Unknown type name '$comment' at position 0 in $comment.
Loading history...
42
     */
43
    protected $comment;
44
45
    /**
46
     * @var array $primaryKey
47
     */
48
    protected $primaryKey=array();
49
50
    /**
51
     * @var array $references
52
     */
53
    protected $references=array();
54
55
    /**
56
     * @var $schemaType
0 ignored issues
show
Documentation Bug introduced by
The doc comment $schemaType at position 0 could not be parsed: Unknown type name '$schemaType' at position 0 in $schemaType.
Loading history...
57
     */
58
    protected $schemaType;
59
60
    /**
61
     * @var $file
0 ignored issues
show
Documentation Bug introduced by
The doc comment $file at position 0 could not be parsed: Unknown type name '$file' at position 0 in $file.
Loading history...
62
     */
63
    protected $file;
64
65
    /**
66
     * @var $name array
0 ignored issues
show
Documentation Bug introduced by
The doc comment $name at position 0 could not be parsed: Unknown type name '$name' at position 0 in $name.
Loading history...
67
     */
68
    protected $name=array();
69
70
    /**
71
     * @var array $nullable
72
     */
73
    protected $nullable=array();
74
75
    /**
76
     * @var array $types
77
     */
78
    protected $types=array();
79
80
    /**
81
     * @var $engine
0 ignored issues
show
Documentation Bug introduced by
The doc comment $engine at position 0 could not be parsed: Unknown type name '$engine' at position 0 in $engine.
Loading history...
82
     */
83
    protected $engine;
84
85
    /**
86
     * @var $default array
0 ignored issues
show
Documentation Bug introduced by
The doc comment $default at position 0 could not be parsed: Unknown type name '$default' at position 0 in $default.
Loading history...
87
     */
88
    protected $default=array();
89
90
    /**
91
     * @var array $index
92
     */
93
    protected $index=array();
94
95
    /**
96
     * @var array
97
     */
98
    protected $key=array();
99
100
    /**
101
     * @var array $unique
102
     */
103
    protected $unique=array();
104
105
    /**
106
     * @var $table
0 ignored issues
show
Documentation Bug introduced by
The doc comment $table at position 0 could not be parsed: Unknown type name '$table' at position 0 in $table.
Loading history...
107
     */
108
    protected $table;
109
110
    /**
111
     * @return mixed|void
112
     */
113
    public function auto_increment()
114
    {
115
        if(count($this->auto_increment)==0){
116
117
            if($this->getLastName()===false){
118
                $this->name[]='id';
119
                $this->setTypes('int',14);
120
            }
121
            $this->auto_increment[$this->getLastName()]=true;
122
            $this->primaryKey();
123
        }
124
    }
125
126
    /**
127
     * @param $value
128
     * @return $this
129
     */
130
    public function comment($value)
131
    {
132
        $this->comment[$this->getLastName()]=$value;
133
134
        return $this;
135
    }
136
137
    /**
138
     * @param $name
139
     * @return Types
140
     */
141
    public function name($name)
142
    {
143
        if(in_array($name,$this->name)){
144
           $this->setError('You have written the '.$name.' name more than 1.');
145
        }
146
147
        $this->name[] = $name;
148
149
        return new Types($this);
150
151
    }
152
153
    /**
154
     * @param $value
155
     * @return $this|mixed
156
     */
157
    public function default($value)
158
    {
159
        $this->default[$this->getLastName()]=$value;
160
161
        return $this;
162
    }
163
164
    /**
165
     * @param $value
166
     * @param bool $table
167
     * @return $this
168
     */
169
    public function collation($value,$table=false)
170
    {
171
        if($table===false)
172
        {
173
            $this->collation[$this->getLastName()]=$value;
174
        }
175
        else{
176
            $this->collation['table']=$value;
177
        }
178
179
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Migratio\GrammarStructure\Mysql\Wizard\Wizard which is incompatible with the return type mandated by Migratio\Contract\WizardContract::collation() of Migratio\Contract\TablePropertiesContract.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
180
    }
181
182
    /**
183
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
184
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
185
     * @param bool $key
186
     * @return $this|WizardContract
187
     */
188
    public function index($name=null,$value=null,$key=false)
189
    {
190
        $name   = ($name===null) ? $this->getLastName() : $name;
0 ignored issues
show
introduced by
The condition $name === null is always true.
Loading history...
191
        $value  = ($value===null) ? $name : $value;
0 ignored issues
show
introduced by
The condition $value === null is always true.
Loading history...
192
193
        if($key===false){
194
            $this->index[$this->getLastName()]=['name'=>$name,'value'=>$value];
195
        }
196
197
        if($key===true){
198
            $this->index['indexes'][]=['name'=>$name,'value'=>$value];
199
        }
200
201
        return $this;
202
    }
203
204
    /**
205
     * @param $index_name
206
     * @param array $indexes
207
     * @return void
208
     */
209
    public function indexes($index_name,$indexes=array())
210
    {
211
        $this->index[$index_name] = $indexes;
212
    }
213
214
    /**
215
     * @param $key_name
216
     */
217
    public function key($key_name)
218
    {
219
        $this->key['Index'] = $key_name;
220
    }
221
222
    /**
223
     * @param bool $null
224
     * @return $this
225
     */
226
    public function nullable($null=true)
227
    {
228
        $this->nullable[$this->getLastName()]=$null;
229
230
        return $this;
231
    }
232
233
    /**
234
     * @return $this|WizardContract
235
     */
236
    public function primaryKey()
237
    {
238
        $this->primaryKey[$this->getLastName()]=true;
239
240
        return $this;
241
    }
242
243
    /**
244
     * @return TablePropertiesContract
245
     */
246
    public function table()
247
    {
248
        return new TableProperties($this);
249
    }
250
251
    /**
252
     * @param $name
253
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
254
     * @return $this|mixed
255
     */
256
    public function unique($name=null,$value=null)
257
    {
258
        $name   = ($name===null) ? $this->getLastName() : $name;
259
        $value  = ($value===null) ? $name : $value;
0 ignored issues
show
introduced by
The condition $value === null is always true.
Loading history...
260
261
        $this->unique[$this->getLastName()] = ['name'=>$name,'value'=>$value];
262
263
        return $this;
264
    }
265
266
    /**
267
     * @param $name
268
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
269
     * @return $this|mixed
270
     */
271
    public function uniques($unique_name,$uniques=array())
272
    {
273
        $this->unique[$unique_name] = $uniques;
274
    }
275
}
276
277