@@ -33,71 +33,61 @@ protected function parse(mixed $object): void
33
33
);
34
34
}
35
35
36
- if (property_exists ($ object , 'id ' )) {
37
- if (!is_string ($ object ->id )) {
38
- throw new ValidationException (
39
- 'property "id" has to be a string, " ' .
40
- gettype ($ object ->id ) . '" given. '
41
- );
36
+ foreach (get_object_vars ($ object ) as $ key => $ value ) {
37
+ if ($ key === 'id ' ) {
38
+ if (!is_string ($ object ->id )) {
39
+ throw new ValidationException (
40
+ 'property "id" has to be a string, " ' .
41
+ gettype ($ object ->id ) . '" given. '
42
+ );
43
+ }
44
+
45
+ $ this ->set ('id ' , strval ($ object ->id ));
46
+ } elseif ($ key === 'links ' ) {
47
+ $ this ->set ('links ' , $ this ->create ('ErrorLink ' , $ object ->links ));
48
+ } elseif ($ key === 'status ' ) {
49
+ if (!is_string ($ object ->status )) {
50
+ throw new ValidationException (
51
+ 'property "status" has to be a string, " ' .
52
+ gettype ($ object ->status ) . '" given. '
53
+ );
54
+ }
55
+
56
+ $ this ->set ('status ' , strval ($ object ->status ));
57
+ } elseif ($ key === 'code ' ) {
58
+ if (!is_string ($ object ->code )) {
59
+ throw new ValidationException (
60
+ 'property "code" has to be a string, " ' .
61
+ gettype ($ object ->code ) . '" given. '
62
+ );
63
+ }
64
+
65
+ $ this ->set ('code ' , strval ($ object ->code ));
66
+ } elseif ($ key === 'title ' ) {
67
+ if (!is_string ($ object ->title )) {
68
+ throw new ValidationException (
69
+ 'property "title" has to be a string, " ' .
70
+ gettype ($ object ->title ) . '" given. '
71
+ );
72
+ }
73
+
74
+ $ this ->set ('title ' , strval ($ object ->title ));
75
+ } elseif ($ key === 'detail ' ) {
76
+ if (!is_string ($ object ->detail )) {
77
+ throw new ValidationException (
78
+ 'property "detail" has to be a string, " ' .
79
+ gettype ($ object ->detail ) . '" given. '
80
+ );
81
+ }
82
+
83
+ $ this ->set ('detail ' , strval ($ object ->detail ));
84
+ } elseif ($ key === 'source ' ) {
85
+ $ this ->set ('source ' , $ this ->create ('ErrorSource ' , $ object ->source ));
86
+ } elseif ($ key === 'meta ' ) {
87
+ $ this ->set ('meta ' , $ this ->create ('Meta ' , $ object ->meta ));
88
+ } else {
89
+ $ this ->set ($ key , $ value );
42
90
}
43
-
44
- $ this ->set ('id ' , strval ($ object ->id ));
45
- }
46
-
47
- if (property_exists ($ object , 'links ' )) {
48
- $ this ->set ('links ' , $ this ->create ('ErrorLink ' , $ object ->links ));
49
- }
50
-
51
- if (property_exists ($ object , 'status ' )) {
52
- if (!is_string ($ object ->status )) {
53
- throw new ValidationException (
54
- 'property "status" has to be a string, " ' .
55
- gettype ($ object ->status ) . '" given. '
56
- );
57
- }
58
-
59
- $ this ->set ('status ' , strval ($ object ->status ));
60
- }
61
-
62
- if (property_exists ($ object , 'code ' )) {
63
- if (!is_string ($ object ->code )) {
64
- throw new ValidationException (
65
- 'property "code" has to be a string, " ' .
66
- gettype ($ object ->code ) . '" given. '
67
- );
68
- }
69
-
70
- $ this ->set ('code ' , strval ($ object ->code ));
71
- }
72
-
73
- if (property_exists ($ object , 'title ' )) {
74
- if (!is_string ($ object ->title )) {
75
- throw new ValidationException (
76
- 'property "title" has to be a string, " ' .
77
- gettype ($ object ->title ) . '" given. '
78
- );
79
- }
80
-
81
- $ this ->set ('title ' , strval ($ object ->title ));
82
- }
83
-
84
- if (property_exists ($ object , 'detail ' )) {
85
- if (!is_string ($ object ->detail )) {
86
- throw new ValidationException (
87
- 'property "detail" has to be a string, " ' .
88
- gettype ($ object ->detail ) . '" given. '
89
- );
90
- }
91
-
92
- $ this ->set ('detail ' , strval ($ object ->detail ));
93
- }
94
-
95
- if (property_exists ($ object , 'source ' )) {
96
- $ this ->set ('source ' , $ this ->create ('ErrorSource ' , $ object ->source ));
97
- }
98
-
99
- if (property_exists ($ object , 'meta ' )) {
100
- $ this ->set ('meta ' , $ this ->create ('Meta ' , $ object ->meta ));
101
91
}
102
92
}
103
93
0 commit comments