-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathIntegerColumnTrait.php
79 lines (67 loc) · 1.63 KB
/
IntegerColumnTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Vimeo\MysqlEngine\Schema\Column;
trait IntegerColumnTrait
{
/**
* @var bool
*/
protected $auto_increment = false;
/**
* @var int
*/
protected $integer_display_width;
/**
* @var bool
*/
protected $unsigned = false;
public function __construct(bool $unsigned, int $integer_display_width)
{
$this->unsigned = $unsigned;
$this->integer_display_width = $integer_display_width;
}
public function getDisplayWidth() : int
{
return $this->integer_display_width;
}
/**
* @return static
*/
public function autoIncrement()
{
$this->auto_increment = true;
return $this;
}
public function isAutoIncrement() : bool
{
return $this->auto_increment;
}
public function isUnsigned() : bool
{
return $this->unsigned;
}
/**
* @return 'int'
*/
public function getPhpType() : string
{
return 'int';
}
public function getPhpCode() : string
{
$default = '';
if ($this instanceof Defaultable && $this->hasDefault()) {
$default = '->setDefault('
. ($this->getDefault() === null
? 'null'
: '\'' . $this->getDefault() . '\'')
. ')';
}
return '(new \\' . static::class . '('
. ($this->unsigned ? 'true' : 'false')
. ', ' . $this->integer_display_width
. '))'
. $default
. $this->getNullablePhp()
. ($this->isAutoIncrement() ? '->autoIncrement()' : '');
}
}