@@ -45,11 +45,16 @@ public function alpha_space(?string $value = null): bool
4545
4646 /**
4747 * Alphanumeric with underscores and dashes
48+ *
49+ * @see https://regex101.com/r/XfVY3d/1
4850 */
4951 public function alpha_dash (?string $ str = null ): bool
5052 {
51- // @see https://regex101.com/r/XfVY3d/1
52- return (bool ) preg_match ('/\A[a-z0-9_-]+\z/i ' , $ str );
53+ if ($ str === null ) {
54+ return false ;
55+ }
56+
57+ return preg_match ('/\A[a-z0-9_-]+\z/i ' , $ str ) === 1 ;
5358 }
5459
5560 /**
@@ -59,14 +64,19 @@ public function alpha_dash(?string $str = null): bool
5964 * _ underscore, + plus, = equals, | vertical bar, : colon, . period
6065 * ~ ! # $ % & * - _ + = | : .
6166 *
62- * @param string $str
67+ * @param string|null $str
6368 *
6469 * @return bool
70+ *
71+ * @see https://regex101.com/r/6N8dDY/1
6572 */
6673 public function alpha_numeric_punct ($ str )
6774 {
68- // @see https://regex101.com/r/6N8dDY/1
69- return (bool ) preg_match ('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i ' , $ str );
75+ if ($ str === null ) {
76+ return false ;
77+ }
78+
79+ return preg_match ('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i ' , $ str ) === 1 ;
7080 }
7181
7282 /**
@@ -307,7 +317,7 @@ public function valid_url_strict(?string $str = null, ?string $validSchemes = nu
307317 return false ;
308318 }
309319
310- $ scheme = strtolower (parse_url ($ str , PHP_URL_SCHEME ));
320+ $ scheme = strtolower (parse_url ($ str , PHP_URL_SCHEME ) ?? '' ); // absent scheme gives null
311321 $ validSchemes = explode (
312322 ', ' ,
313323 strtolower ($ validSchemes ?? 'http,https ' )
0 commit comments