Skip to content

Commit 0334d28

Browse files
committed
Adding type decorater utility.
1 parent 055d0b9 commit 0334d28

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/Utility/StringHelper.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,29 @@ public static function nonNullType($type) {
6464
return "$type!";
6565
}
6666

67+
/**
68+
* Decorates a type as non-null and/or as a list.
69+
*
70+
* @param string $type
71+
* The type to declare as non-null.
72+
* @param bool $list
73+
* Whether to mark the type as a list.
74+
* @param bool $required
75+
* Whether to mark the type as required.
76+
*
77+
* @return string
78+
* The decorated type.
79+
*/
80+
public static function decorateType($type, $list = FALSE, $required = FALSE) {
81+
if (!empty($list)) {
82+
$type = static::listType($type);
83+
}
84+
85+
if (!empty($required)) {
86+
$type = static::nonNullType($type);
87+
}
88+
89+
return $type;
90+
}
91+
6792
}

0 commit comments

Comments
 (0)