File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ <a name =" 4.3.0 " ></a >
2+ # [ 4.3.0] ( https://github.com/glowyphp/strings ) (2022-05-08)
3+ * Added isNull() method.
4+ * Added isInteger() method.
5+ * Added isFloat() method.
6+ * Added isUuid() method.
7+ * Added toNull() method.
8+ * Method pipe() returns a new instance of the class.
9+
110<a name =" 4.2.0 " ></a >
211# [ 4.2.0] ( https://github.com/glowyphp/strings ) (2022-01-01)
312* Added isHexColor() method.
Original file line number Diff line number Diff line change @@ -2029,6 +2029,36 @@ public function isHTML(): bool
20292029 return $ this ->toString () !== strip_tags ($ this ->toString ());
20302030 }
20312031
2032+ /**
2033+ * Determine whether the string is integer.
2034+ *
2035+ * @return bool Returns TRUE on success or FALSE otherwise.
2036+ */
2037+ public function isInteger (): bool
2038+ {
2039+ return (bool ) filter_var ($ this ->toString (), FILTER_VALIDATE_INT );
2040+ }
2041+
2042+ /**
2043+ * Determine whether the string is float.
2044+ *
2045+ * @return bool Returns TRUE on success or FALSE otherwise.
2046+ */
2047+ public function isFloat (): bool
2048+ {
2049+ return ((bool ) filter_var ($ this ->toString (), FILTER_VALIDATE_FLOAT ) !== $ this ->isInteger ());
2050+ }
2051+
2052+ /**
2053+ * Determine whether the string is null.
2054+ *
2055+ * @return bool Returns TRUE on success or FALSE otherwise.
2056+ */
2057+ public function isNull (): bool
2058+ {
2059+ return $ this ->toString () === null || $ this ->toString () === 'null ' ;
2060+ }
2061+
20322062 /**
20332063 * Determine whether the string is Boolean.
20342064 *
@@ -2105,6 +2135,16 @@ public function toFloat(): float
21052135 return floatval ($ this ->string );
21062136 }
21072137
2138+ /**
2139+ * Return Strings object as null.
2140+ *
2141+ * @return float Return Strings object as null.
2142+ */
2143+ public function toNull (): float
2144+ {
2145+ return null ;
2146+ }
2147+
21082148 /**
21092149 * Returns a boolean representation of the given logical string value.
21102150 *
Original file line number Diff line number Diff line change 849849 $ this ->assertFalse (Strings::create ('fòôbàřs ' )->isIP ());
850850});
851851
852+ test ('test isInteger() method ' , function (): void {
853+ $ this ->assertTrue (Strings::create ('1 ' )->isInteger ());
854+ $ this ->assertFalse (Strings::create ('1.0 ' )->isInteger ());
855+ $ this ->assertFalse (Strings::create ('Foo ' )->isInteger ());
856+ });
857+
858+ test ('test isFloat() method ' , function (): void {
859+ $ this ->assertFalse (Strings::create ('1 ' )->isFloat ());
860+ $ this ->assertTrue (Strings::create ('0.1 ' )->isFloat ());
861+ $ this ->assertTrue (Strings::create ('1.0 ' )->isFloat ());
862+ $ this ->assertTrue (Strings::create ('0.1 ' )->isFloat ());
863+ $ this ->assertFalse (Strings::create ('Foo ' )->isFloat ());
864+ });
865+
866+ test ('test isNull() method ' , function (): void {
867+ $ this ->assertTrue (Strings::create ('null ' )->isNull ());
868+ });
869+
852870test ('test isMAC() method ' , function (): void {
853871 $ this ->assertTrue (Strings::create ('00:11:22:33:44:55 ' )->isMAC ());
854872 $ this ->assertFalse (Strings::create ('127.0.0.1 ' )->isMAC ());
You can’t perform that action at this time.
0 commit comments