Skip to content

Commit 0bf4728

Browse files
committed
cs fix
1 parent a93f0c7 commit 0bf4728

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

.php-cs-fixer.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
->setRules([
1111
'@Symfony' => true,
1212
'@Symfony:risky' => true,
13-
'@PHP71Migration:risky' => true,
14-
'@PHPUnit75Migration:risky' => true,
13+
'@PHP80Migration:risky' => true,
14+
'@PHP81Migration' => true,
15+
'@PHPUnit100Migration:risky' => true,
1516
'declare_strict_types' => false,
1617
'native_function_invocation' => ['include' => ['@all']],
1718
'final_class' => true,

src/Factory.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ final class Factory
1616
/**
1717
* @throws InvalidShortidException
1818
*/
19-
public function generate(int $length = null, string $alphabet = null, bool $readable = null): Shortid
19+
public function generate(?int $length = null, ?string $alphabet = null, ?bool $readable = null): Shortid
2020
{
21-
$length = $length ?? $this->length;
22-
$readable = $readable ?? $this->readable;
21+
$length ??= $this->length;
22+
$readable ??= $this->readable;
2323
if (null === $alphabet && $readable) {
2424
$alphabet = \str_replace(\str_split(Generator::AMBIGUOUS_CHARS), '', $this->alphabet);
2525
$alphabet .= \str_repeat('_', \strlen(Generator::AMBIGUOUS_CHARS) / 2);
@@ -65,7 +65,7 @@ public static function getFactory(): RandomLibFactory
6565
return self::$factory;
6666
}
6767

68-
public function checkLength(int $length = null, bool $strict = false): void
68+
public function checkLength(?int $length = null, bool $strict = false): void
6969
{
7070
if (null === $length && !$strict) {
7171
return;

src/Shortid.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ final class Shortid implements \JsonSerializable, \Serializable, \Stringable
99
/**
1010
* @throws InvalidShortidException
1111
*/
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)
1313
{
1414
if (!self::isValid($id, $length, $alphabet)) {
1515
throw new InvalidShortidException(\sprintf('Invalid shortid %s (length %d alphabet %s', $id, $length, $alphabet));
@@ -24,7 +24,7 @@ public function __toString(): string
2424
/**
2525
* @throws InvalidShortidException
2626
*/
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
2828
{
2929
if (null === $length) {
3030
self::getFactory()->checkLength($length);
@@ -43,14 +43,14 @@ public static function getFactory(): Factory
4343
return self::$factory;
4444
}
4545

46-
public static function setFactory(Factory $factory = null): void
46+
public static function setFactory(?Factory $factory = null): void
4747
{
4848
self::$factory = $factory;
4949
}
5050

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
5252
{
53-
$length = $length ?? self::getFactory()->getLength();
53+
$length ??= self::getFactory()->getLength();
5454
$alphabet = \preg_quote($alphabet ?: self::getFactory()->getAlphabet(), '/');
5555
$matches = [];
5656
$ok = \preg_match('/^(['.$alphabet.']{'.$length.'})$/', $value, $matches);

tests/ShortidTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testGenerate(): void
2121
if (\method_exists($this, 'assertMatchesRegularExpression')) {
2222
self::assertMatchesRegularExpression('/^[a-z0-9\_\-]{7}$/i', $generated->__toString());
2323
} else {
24-
self::assertRegExp('/^[a-z0-9\_\-]{7}$/i', $generated->__toString());
24+
self::assertMatchesRegularExpression('/^[a-z0-9\_\-]{7}$/i', $generated->__toString());
2525
}
2626
}
2727

@@ -32,7 +32,7 @@ public function testGenerateWithReadable(): void
3232
if (\method_exists($this, 'assertMatchesRegularExpression')) {
3333
self::assertMatchesRegularExpression('/^[a-z0-9\_\-]{7}$/i', $generated->__toString());
3434
} else {
35-
self::assertRegExp('/^[a-z0-9\_\-]{7}$/i', $generated->__toString());
35+
self::assertMatchesRegularExpression('/^[a-z0-9\_\-]{7}$/i', $generated->__toString());
3636
}
3737
}
3838

@@ -43,7 +43,7 @@ public function testGenerateWithLength(): void
4343
if (\method_exists($this, 'assertMatchesRegularExpression')) {
4444
self::assertMatchesRegularExpression('/^[a-z0-9\_\-]{8}$/i', $generated->__toString());
4545
} else {
46-
self::assertRegExp('/^[a-z0-9\_\-]{8}$/i', $generated->__toString());
46+
self::assertMatchesRegularExpression('/^[a-z0-9\_\-]{8}$/i', $generated->__toString());
4747
}
4848
}
4949

0 commit comments

Comments
 (0)