@@ -9,7 +9,7 @@ final class Shortid implements \JsonSerializable, \Serializable, \Stringable
9
9
/**
10
10
* @throws InvalidShortidException
11
11
*/
12
- public function __construct (private string $ id , int $ length = null , string $ alphabet = null )
12
+ public function __construct (private string $ id , ? int $ length = null , ? string $ alphabet = null )
13
13
{
14
14
if (!self ::isValid ($ id , $ length , $ alphabet )) {
15
15
throw new InvalidShortidException (\sprintf ('Invalid shortid %s (length %d alphabet %s ' , $ id , $ length , $ alphabet ));
@@ -24,7 +24,7 @@ public function __toString(): string
24
24
/**
25
25
* @throws InvalidShortidException
26
26
*/
27
- public static function generate (int $ length = null , string $ alphabet = null , bool $ readable = false ): self
27
+ public static function generate (? int $ length = null , ? string $ alphabet = null , bool $ readable = false ): self
28
28
{
29
29
if (null === $ length ) {
30
30
self ::getFactory ()->checkLength ($ length );
@@ -43,14 +43,14 @@ public static function getFactory(): Factory
43
43
return self ::$ factory ;
44
44
}
45
45
46
- public static function setFactory (Factory $ factory = null ): void
46
+ public static function setFactory (? Factory $ factory = null ): void
47
47
{
48
48
self ::$ factory = $ factory ;
49
49
}
50
50
51
- public static function isValid (string $ value , int $ length = null , string $ alphabet = null ): bool
51
+ public static function isValid (string $ value , ? int $ length = null , ? string $ alphabet = null ): bool
52
52
{
53
- $ length = $ length ?? self ::getFactory ()->getLength ();
53
+ $ length ??= self ::getFactory ()->getLength ();
54
54
$ alphabet = \preg_quote ($ alphabet ?: self ::getFactory ()->getAlphabet (), '/ ' );
55
55
$ matches = [];
56
56
$ ok = \preg_match ('/^([ ' .$ alphabet .']{ ' .$ length .'})$/ ' , $ value , $ matches );
0 commit comments