Test Setup Failed
Push — master ( d6fde7...1e848b )
by Php Easy Api
04:20
created

Wizard::default()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
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 $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...
12
     */
13
    public static $randomInstance;
14
15
    /**
16
     * @var array $error
17
     */
18
    protected $error = array();
19
20
    /**
21
     * @var array
22
     */
23
    protected $alterType = [];
24
25
    /**
26
     * @var array
27
     */
28
    protected $auto_increment=array();
29
30
    /**
31
     * @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...
32
     */
33
    protected $collation;
34
35
    /**
36
     * @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...
37
     */
38
    protected $comment;
39
40
    /**
41
     * @var array $primaryKey
42
     */
43
    protected $primaryKey=array();
44
45
    /**
46
     * @var array $references
47
     */
48
    protected $references=array();
49
50
    /**
51
     * @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...
52
     */
53
    protected $schemaType;
54
55
    /**
56
     * @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...
57
     */
58
    protected $file;
59
60
    /**
61
     * @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...
62
     */
63
    protected $name=array();
64
65
    /**
66
     * @var array $nullable
67
     */
68
    protected $nullable=array();
69
70
    /**
71
     * @var array $types
72
     */
73
    protected $types=array();
74
75
    /**
76
     * @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...
77
     */
78
    protected $engine;
79
80
    /**
81
     * @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...
82
     */
83
    protected $default=array();
84
85
    /**
86
     * @var array $index
87
     */
88
    protected $index=array();
89
90
    /**
91
     * @var array $unique
92
     */
93
    protected $unique=array();
94
95
    /**
96
     * @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...
97
     */
98
    protected $table;
99
100
    /**
101
     * @return mixed|void
102
     */
103
    public function auto_increment()
104
    {
105
        if(count($this->auto_increment)==0){
106
107
            if($this->getLastName()===false){
108
                $this->name[]='id';
109
                $this->setTypes('int',14);
110
            }
111
            $this->auto_increment[$this->getLastName()]=true;
112
            $this->primaryKey();
113
        }
114
    }
115
116
    /**
117
     * @param $value
118
     * @return $this
119
     */
120
    public function comment($value)
121
    {
122
        $this->comment[$this->getLastName()]=$value;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @param $name
129
     * @return Types
130
     */
131
    public function name($name)
132
    {
133
        if(in_array($name,$this->name)){
134
           $this->setError('You have written the '.$name.' name more than 1.');
135
        }
136
137
        $this->name[]=$name;
138
139
        return new Types($this);
140
141
    }
142
143
    /**
144
     * @param $value
145
     * @return $this|mixed
146
     */
147
    public function default($value)
148
    {
149
        $this->default[$this->getLastName()]=$value;
150
151
        return $this;
152
    }
153
154
    /**
155
     * @param $value
156
     * @param bool $table
157
     * @return $this
158
     */
159
    public function collation($value,$table=false)
160
    {
161
        if($table===false)
162
        {
163
            $this->collation[$this->getLastName()]=$value;
164
        }
165
        else{
166
            $this->collation['table']=$value;
167
        }
168
169
        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...
170
    }
171
172
    /**
173
     * @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...
174
     * @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...
175
     * @param bool $key
176
     * @return $this|WizardContract
177
     */
178
    public function index($name=null,$value=null,$key=false)
179
    {
180
        $name   = ($name===null) ? $this->getLastName() : $name;
0 ignored issues
show
introduced by
The condition $name === null is always true.
Loading history...
181
        $value  = ($value===null) ? $name : $value;
0 ignored issues
show
introduced by
The condition $value === null is always true.
Loading history...
182
183
        if($key===false){
184
            $this->index[$this->getLastName()]=['name'=>$name,'value'=>$value];
185
        }
186
187
        if($key===true){
188
            $this->index['indexes'][]=['name'=>$name,'value'=>$value];
189
        }
190
191
        return $this;
192
    }
193
194
    /**
195
     * @param bool $null
196
     * @return $this
197
     */
198
    public function nullable($null=true)
199
    {
200
        $this->nullable[$this->getLastName()]=$null;
201
202
        return $this;
203
    }
204
205
    /**
206
     * @return $this|WizardContract
207
     */
208
    public function primaryKey()
209
    {
210
        $this->primaryKey[$this->getLastName()]=true;
211
212
        return $this;
213
    }
214
215
    /**
216
     * @return TablePropertiesContract
217
     */
218
    public function table()
219
    {
220
        return new TableProperties($this);
221
    }
222
223
    /**
224
     * @param $name
225
     * @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...
226
     * @return $this|mixed
227
     */
228
    public function unique($name=null,$value=null)
229
    {
230
        $name   = ($name===null) ? $this->getLastName() : $name;
231
        $value  = ($value===null) ? $name : $value;
0 ignored issues
show
introduced by
The condition $value === null is always true.
Loading history...
232
233
        $this->unique[$this->getLastName()]=['name'=>$name,'value'=>$value];
234
235
        return $this;
236
    }
237
}
238
239