@@ -50,7 +50,7 @@ class Element extends JsonSerializable implements IElement
5050 * @param string $name API element name.
5151 * @throws InvalidArgumentException
5252 */
53- public function __construct ($ type , $ name )
53+ public function __construct (string $ type , string $ name )
5454 {
5555 parent ::__construct ();
5656 $ this ->setType ($ type );
@@ -88,13 +88,8 @@ public function getName(): string
8888 * @param string $type
8989 * @throws InvalidArgumentException
9090 */
91- protected function setType ($ type )
91+ protected function setType (string $ type )
9292 {
93- if (!is_string ($ type )) {
94- throw new InvalidArgumentException (
95- 'Expected API element type to be string! '
96- );
97- }
9893 if (!in_array ($ type , static ::$ allowedTypes , true )) {
9994 throw new InvalidArgumentException (sprintf (
10095 'Expected API element type to be in: %s! ' ,
@@ -109,14 +104,14 @@ protected function setType($type)
109104 * @param string $name
110105 * @throws InvalidArgumentException
111106 */
112- protected function setName ($ name )
107+ protected function setName (string $ name )
113108 {
114- if (! is_string ($ name ) || $ name === '' ) {
109+ if (trim ($ name ) === '' ) {
115110 throw new InvalidArgumentException (
116111 'Expected API element name to be string! '
117112 );
118113 }
119- $ this ->set (self ::JSON_NAME , $ name );
114+ $ this ->set (self ::JSON_NAME , trim ( $ name) );
120115 }
121116
122117 /**
@@ -169,25 +164,19 @@ public function cast($value)
169164 * @return Element
170165 * @throws InvalidArgumentException
171166 */
172- public static function fromArray ($ array ): Element
167+ public static function fromArray (array $ array ): Element
173168 {
174169 static ::fromArrayValidation ($ array );
175170 return new self ($ array [self ::JSON_TYPE ], $ array [self ::JSON_NAME ]);
176171 }
177172
178173 /**
179174 * Validate the array for fromArray().
180- * @param mixed $array
175+ * @param array $array
181176 * @throws InvalidArgumentException
182177 */
183- protected static function fromArrayValidation ($ array )
178+ protected static function fromArrayValidation (array $ array )
184179 {
185- if (!is_array ($ array )) {
186- throw new InvalidArgumentException (sprintf (
187- 'Expected array, but got \'%s \'! ' ,
188- gettype ($ array )
189- ));
190- }
191180 foreach (static ::$ allowedKeys as $ key ) {
192181 if (!array_key_exists ($ key , $ array )) {
193182 throw new InvalidArgumentException (sprintf (
@@ -205,7 +194,7 @@ protected static function fromArrayValidation($array)
205194 * @return Element
206195 * @throws InvalidArgumentException
207196 */
208- public static function jsonDecode ($ json ): IJsonSerializable
197+ public static function jsonDecode (string $ json ): IJsonSerializable
209198 {
210199 $ array = static ::jsonToArray ($ json );
211200 return static ::fromArray ($ array );
0 commit comments