Skip to content

Commit c816928

Browse files
committed
Fixed Compiler
Changed not-nullable syntax to nullable
1 parent 229ce51 commit c816928

File tree

8 files changed

+58
-44
lines changed

8 files changed

+58
-44
lines changed

app/Compiler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ protected function compileClass(ClassModel $classModel, FileModel $fileModel): s
138138
}
139139

140140
$result .= "return \$value;\n}\n";
141+
} else {
142+
$result .= "protected function validate_{$fieldModel->name}(\$value) { return \$value; }\n";
141143
}
142144

143145
if ($fieldModel->editable) {

app/Model/ClassModel.pdata

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ namespace PHPDataGen\Model;
2424

2525
class ClassModel {
2626

27-
val name: string!;
27+
val name: string;
2828

29-
val extends: string;
30-
var implements: array!;
29+
val extends: string?;
30+
var implements: array;
3131

32-
var fields: array!;
32+
var fields: array;
3333
}

app/Model/FieldModel.pdata

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ use PHPDataGen\Type;
2626

2727
class FieldModel {
2828

29-
val name: string!;
29+
val name: string;
3030

31-
val editable: bool! = false;
32-
val direct: bool! = false;
31+
val editable: bool = false;
32+
val direct: bool = false;
3333

34-
val type: Type!;
35-
val validators: array!;
34+
val type: Type;
35+
val validators: array;
3636

37-
val filterDefault: bool! = true;
38-
val default: string;
37+
val filterDefault: bool = true;
38+
val default: string?;
3939
}

app/Model/FileModel.pdata

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace PHPDataGen\Model;
2424

2525
class FileModel {
2626

27-
val namespace: string;
27+
val namespace: string?;
2828

29-
val uses: array!;
30-
var classes: array!;
29+
val uses: array;
30+
var classes: array;
3131
}

app/Parsing/Conveyor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function readExtendedClassname(): string {
225225
* @return Type Type
226226
*/
227227
public function readType(): Type {
228-
return new Type($this->readExtendedClassname(), !$this->readOperator('!'));
228+
return new Type($this->readExtendedClassname(), $this->readOperator('?'));
229229
}
230230

231231
/**

app/Type.pdata

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ namespace PHPDataGen;
2424

2525
class Type {
2626

27-
direct val name: string!;
27+
direct val name: string;
2828

29-
val nullable: bool!;
30-
val mixed: bool!;
31-
val class: bool!;
29+
val nullable: bool;
30+
val mixed: bool;
31+
val class: bool;
3232
}

app/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Type extends Data_Type {
3636
/**
3737
* @param string $type Type name of class
3838
*/
39-
public function __construct(string $type, bool $nullable = true) {
39+
public function __construct(string $type, bool $nullable = false) {
4040
$fields = [
4141
'name' => $type,
4242

tests/Data_Test.php

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
class Data_Test {
33
use \PHPDataGen\DataClassTrait;
44
private $A = null;
5-
private $A1 = null;
5+
private $A1 = '';
66
private $A2 = null;
77
private $A3 = null;
8-
private $A4 = null;
9-
private $A5 = null;
8+
private $A4 = '';
9+
private $A5 = '';
1010
private $B = null;
11-
private $B1 = null;
11+
private $B1 = '';
1212
private $B2 = null;
1313
private $B3 = null;
14-
private $B4 = null;
15-
private $B5 = null;
14+
private $B4 = '';
15+
private $B5 = '';
1616
protected $C = null;
17-
protected $C1 = null;
17+
protected $C1 = '';
1818
protected $C2 = null;
1919
protected $C3 = null;
20-
protected $C4 = null;
21-
protected $C5 = null;
20+
protected $C4 = '';
21+
protected $C5 = '';
2222
protected $D = null;
23-
protected $D1 = null;
23+
protected $D1 = '';
2424
protected $D2 = null;
2525
protected $D3 = null;
26-
protected $D4 = null;
27-
protected $D5 = null;
26+
protected $D4 = '';
27+
protected $D5 = '';
2828
public function __construct(array $init = []) {
2929
$this->A2 = $this->validate_A2("Foo");
3030
$this->A3 = "Fee";
@@ -48,86 +48,98 @@ public function __construct(array $init = []) {
4848
}
4949
}
5050
public function get_A() { return $this->A; }
51+
protected function validate_A($value) { return $value; }
5152
public function get_A1() { return $this->A1; }
5253
protected function validate_A1($value) {
53-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field A1 has type string'); }
54+
if (!is_string($value)) { throw new \InvalidArgumentException('Field A1 has type string'); }
5455
return $value;
5556
}
5657
public function get_A2() { return $this->A2; }
58+
protected function validate_A2($value) { return $value; }
5759
public function get_A3() { return $this->A3; }
60+
protected function validate_A3($value) { return $value; }
5861
public function get_A4() { return $this->A4; }
5962
protected function validate_A4($value) {
60-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field A4 has type string'); }
63+
if (!is_string($value)) { throw new \InvalidArgumentException('Field A4 has type string'); }
6164
return $value;
6265
}
6366
public function get_A5() { return $this->A5; }
6467
protected function validate_A5($value) {
65-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field A5 has type string'); }
68+
if (!is_string($value)) { throw new \InvalidArgumentException('Field A5 has type string'); }
6669
return $value;
6770
}
6871
public function &get_B() { return $this->B; }
72+
protected function validate_B($value) { return $value; }
6973
public function set_B($value) { $this->B = $this->validate_B($value);}
7074
public function &get_B1() { return $this->B1; }
7175
protected function validate_B1($value) {
72-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field B1 has type string'); }
76+
if (!is_string($value)) { throw new \InvalidArgumentException('Field B1 has type string'); }
7377
return $value;
7478
}
7579
public function set_B1($value) { $this->B1 = $this->validate_B1($value);}
7680
public function &get_B2() { return $this->B2; }
81+
protected function validate_B2($value) { return $value; }
7782
public function set_B2($value) { $this->B2 = $this->validate_B2($value);}
7883
public function &get_B3() { return $this->B3; }
84+
protected function validate_B3($value) { return $value; }
7985
public function set_B3($value) { $this->B3 = $this->validate_B3($value);}
8086
public function &get_B4() { return $this->B4; }
8187
protected function validate_B4($value) {
82-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field B4 has type string'); }
88+
if (!is_string($value)) { throw new \InvalidArgumentException('Field B4 has type string'); }
8389
return $value;
8490
}
8591
public function set_B4($value) { $this->B4 = $this->validate_B4($value);}
8692
public function &get_B5() { return $this->B5; }
8793
protected function validate_B5($value) {
88-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field B5 has type string'); }
94+
if (!is_string($value)) { throw new \InvalidArgumentException('Field B5 has type string'); }
8995
return $value;
9096
}
9197
public function set_B5($value) { $this->B5 = $this->validate_B5($value);}
9298
public function get_C() { return $this->C; }
99+
protected function validate_C($value) { return $value; }
93100
public function get_C1() { return $this->C1; }
94101
protected function validate_C1($value) {
95-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field C1 has type string'); }
102+
if (!is_string($value)) { throw new \InvalidArgumentException('Field C1 has type string'); }
96103
return $value;
97104
}
98105
public function get_C2() { return $this->C2; }
106+
protected function validate_C2($value) { return $value; }
99107
public function get_C3() { return $this->C3; }
108+
protected function validate_C3($value) { return $value; }
100109
public function get_C4() { return $this->C4; }
101110
protected function validate_C4($value) {
102-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field C4 has type string'); }
111+
if (!is_string($value)) { throw new \InvalidArgumentException('Field C4 has type string'); }
103112
return $value;
104113
}
105114
public function get_C5() { return $this->C5; }
106115
protected function validate_C5($value) {
107-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field C5 has type string'); }
116+
if (!is_string($value)) { throw new \InvalidArgumentException('Field C5 has type string'); }
108117
return $value;
109118
}
110119
public function &get_D() { return $this->D; }
120+
protected function validate_D($value) { return $value; }
111121
public function set_D($value) { $this->D = $this->validate_D($value);}
112122
public function &get_D1() { return $this->D1; }
113123
protected function validate_D1($value) {
114-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field D1 has type string'); }
124+
if (!is_string($value)) { throw new \InvalidArgumentException('Field D1 has type string'); }
115125
return $value;
116126
}
117127
public function set_D1($value) { $this->D1 = $this->validate_D1($value);}
118128
public function &get_D2() { return $this->D2; }
129+
protected function validate_D2($value) { return $value; }
119130
public function set_D2($value) { $this->D2 = $this->validate_D2($value);}
120131
public function &get_D3() { return $this->D3; }
132+
protected function validate_D3($value) { return $value; }
121133
public function set_D3($value) { $this->D3 = $this->validate_D3($value);}
122134
public function &get_D4() { return $this->D4; }
123135
protected function validate_D4($value) {
124-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field D4 has type string'); }
136+
if (!is_string($value)) { throw new \InvalidArgumentException('Field D4 has type string'); }
125137
return $value;
126138
}
127139
public function set_D4($value) { $this->D4 = $this->validate_D4($value);}
128140
public function &get_D5() { return $this->D5; }
129141
protected function validate_D5($value) {
130-
if (!is_null($value) && !is_string($value)) { throw new \InvalidArgumentException('Field D5 has type string'); }
142+
if (!is_string($value)) { throw new \InvalidArgumentException('Field D5 has type string'); }
131143
return $value;
132144
}
133145
public function set_D5($value) { $this->D5 = $this->validate_D5($value);}

0 commit comments

Comments
 (0)