44
55use cebe \openapi \exceptions \ReadonlyPropertyException ;
66use cebe \openapi \exceptions \UnknownPropertyException ;
7+ use cebe \openapi \spec \Type ;
78
89/**
910 * Base class for all spec objects.
@@ -40,25 +41,25 @@ public function __construct(array $data)
4041 continue ;
4142 }
4243
43- if ($ type === ' string ' || $ type === ' any ' ) {
44+ if ($ type === Type:: STRING || $ type === Type:: ANY ) {
4445 $ this ->_properties [$ property ] = $ data [$ property ];
45- } elseif ($ type === ' boolean ' ) {
46- if (!is_bool ($ data [$ property ])) {
46+ } elseif ($ type === Type:: BOOLEAN ) {
47+ if (!\ is_bool ($ data [$ property ])) {
4748 $ this ->_errors [] = "property ' $ property' must be boolean, but " . gettype ($ data [$ property ]) . " given. " ;
4849 continue ;
4950 }
5051 $ this ->_properties [$ property ] = (bool ) $ data [$ property ];
51- } elseif (is_array ($ type )) {
52- if (!is_array ($ data [$ property ])) {
52+ } elseif (\ is_array ($ type )) {
53+ if (!\ is_array ($ data [$ property ])) {
5354 $ this ->_errors [] = "property ' $ property' must be array, but " . gettype ($ data [$ property ]) . " given. " ;
5455 continue ;
5556 }
56- switch (count ($ type )) {
57+ switch (\ count ($ type )) {
5758 case 1 :
5859 // array
5960 $ this ->_properties [$ property ] = [];
6061 foreach ($ data [$ property ] as $ item ) {
61- if ($ type [0 ] === ' string ' ) {
62+ if ($ type [0 ] === Type:: STRING ) {
6263 if (!is_string ($ item )) {
6364 $ this ->_errors [] = "property ' $ property' must be array of strings, but array has " . gettype ($ item ) . " element. " ;
6465 }
@@ -71,14 +72,14 @@ public function __construct(array $data)
7172 break ;
7273 case 2 :
7374 // map
74- if ($ type [0 ] !== ' string ' ) {
75+ if ($ type [0 ] !== Type:: STRING ) {
7576 throw new \Exception ('Invalid map key type: ' . $ type [0 ]);
7677 }
7778 $ this ->_properties [$ property ] = [];
7879 foreach ($ data [$ property ] as $ key => $ item ) {
7980 if ($ type [1 ] === 'string ' ) {
8081 if (!is_string ($ item )) {
81- $ this ->_errors [] = "property ' $ property' must be map<string, string>, but entry ' $ key' is of type " . gettype ($ item ) . " . " ;
82+ $ this ->_errors [] = "property ' $ property' must be map<string, string>, but entry ' $ key' is of type " . \ gettype ($ item ) . ' . ' ;
8283 }
8384 $ this ->_properties [$ property ][$ key ] = $ item ;
8485 } else {
@@ -105,13 +106,13 @@ public function __construct(array $data)
105106 */
106107 public function validate (): bool
107108 {
108- foreach ($ this ->_properties as $ k => $ v ) {
109+ foreach ($ this ->_properties as $ v ) {
109110 if ($ v instanceof self) {
110111 $ v ->validate ();
111112 }
112113 }
113114 $ this ->performValidation ();
114- return count ($ this ->getErrors ()) === 0 ;
115+ return \ count ($ this ->getErrors ()) === 0 ;
115116 }
116117
117118 /**
@@ -121,7 +122,7 @@ public function validate(): bool
121122 public function getErrors (): array
122123 {
123124 $ errors = [$ this ->_errors ];
124- foreach ($ this ->_properties as $ k => $ v ) {
125+ foreach ($ this ->_properties as $ v ) {
125126 if ($ v instanceof self) {
126127 $ errors [] = $ v ->getErrors ();
127128 }
@@ -173,12 +174,12 @@ public function __get($name)
173174 if (isset (static ::attributes ()[$ name ])) {
174175 return is_array (static ::attributes ()[$ name ]) ? [] : null ;
175176 }
176- throw new UnknownPropertyException ('Getting unknown property: ' . get_class ($ this ) . ':: ' . $ name );
177+ throw new UnknownPropertyException ('Getting unknown property: ' . \ get_class ($ this ) . ':: ' . $ name );
177178 }
178179
179180 public function __set ($ name , $ value )
180181 {
181- throw new ReadonlyPropertyException ('Setting read-only property: ' . get_class ($ this ) . ':: ' . $ name );
182+ throw new ReadonlyPropertyException ('Setting read-only property: ' . \ get_class ($ this ) . ':: ' . $ name );
182183 }
183184
184185 public function __isset ($ name )
@@ -192,6 +193,6 @@ public function __isset($name)
192193
193194 public function __unset ($ name )
194195 {
195- throw new ReadonlyPropertyException ('Unsetting read-only property: ' . get_class ($ this ) . ':: ' . $ name );
196+ throw new ReadonlyPropertyException ('Unsetting read-only property: ' . \ get_class ($ this ) . ':: ' . $ name );
196197 }
197198}
0 commit comments