Skip to content

Commit

Permalink
Rector updated (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky authored May 12, 2023
1 parent ce15080 commit 3096d01
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ updates:
open-pull-requests-limit: 20
allow:
- dependency-type: all
labels: [ "Dependencies" ]
labels: [ "dependencies" ]

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
open-pull-requests-limit: 20
labels: [ "Dependencies" ]
labels: [ "dependencies" ]
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^10.1",
"qossmic/deptrac-shim": "^1.0",
"rector/rector": "^0.15",
"rector/rector": "^0.16",
"symplify/easy-coding-standard": "^11.0"
},
"autoload": {
Expand Down
40 changes: 0 additions & 40 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ parameters:
count: 1
path: src/OTP.php

-
message: "#^Method OTPHP\\\\TOTP\\:\\:expiresIn\\(\\) should return int\\<0, max\\> but returns int\\.$#"
count: 1
path: src/TOTP.php

-
message: "#^Parameter \\#1 \\$epoch of method OTPHP\\\\TOTP\\:\\:setEpoch\\(\\) expects int\\<0, max\\>, int given\\.$#"
count: 1
path: src/TOTP.php

-
message: "#^Parameter \\#1 \\$input of method OTPHP\\\\TOTP\\:\\:at\\(\\) expects int\\<0, max\\>, int given\\.$#"
count: 2
path: src/TOTP.php

-
message: "#^Parameter \\#2 \\$host of class OTPHP\\\\Url constructor expects non\\-empty\\-string, string given\\.$#"
count: 1
Expand All @@ -50,42 +35,17 @@ parameters:
count: 1
path: src/Url.php

-
message: "#^Parameter \\#1 \\$counter of method OTPHP\\\\HOTP\\:\\:setCounter\\(\\) expects int\\<0, max\\>, \\-500 given\\.$#"
count: 1
path: tests/HOTPTest.php

-
message: "#^Parameter \\#1 \\$digits of method OTPHP\\\\OTP\\:\\:setDigits\\(\\) expects int\\<1, max\\>, 0 given\\.$#"
count: 1
path: tests/HOTPTest.php

-
message: "#^Parameter \\#1 \\$dateTime of method OTPHP\\\\Test\\\\ClockMock\\:\\:setDateTime\\(\\) expects DateTimeImmutable\\|null, DateTimeImmutable\\|false given\\.$#"
count: 5
path: tests/TOTPTest.php

-
message: "#^Parameter \\#1 \\$epoch of method OTPHP\\\\TOTP\\:\\:setEpoch\\(\\) expects int\\<0, max\\>, \\-1 given\\.$#"
count: 1
path: tests/TOTPTest.php

-
message: "#^Parameter \\#1 \\$otp of method OTPHP\\\\TOTP\\:\\:verify\\(\\) expects non\\-empty\\-string, string given\\.$#"
count: 2
path: tests/TOTPTest.php

-
message: "#^Parameter \\#1 \\$period of method OTPHP\\\\TOTP\\:\\:setPeriod\\(\\) expects int\\<1, max\\>, \\-20 given\\.$#"
count: 1
path: tests/TOTPTest.php

-
message: "#^Parameter \\#3 \\$leeway of method OTPHP\\\\TOTP\\:\\:verify\\(\\) expects int\\<0, max\\>\\|null, int given\\.$#"
count: 2
path: tests/TOTPTest.php

-
message: "#^Parameter \\#3 \\$period of static method OTPHP\\\\Test\\\\TOTPTest\\:\\:createTOTP\\(\\) expects int\\<1, max\\>, int given\\.$#"
count: 1
path: tests/TOTPTest.php
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="vendor/autoload.php">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="OTP Test Suite">
<directory>./tests</directory>
Expand Down
4 changes: 0 additions & 4 deletions src/HOTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ protected function getParameterMap(): array
]];
}

/**
* @param positive-int $counter
*/
private function updateCounter(int $counter): void
{
$this->setCounter($counter);
Expand All @@ -115,7 +112,6 @@ private function getWindow(null|int $window): int

/**
* @param non-empty-string $otp
* @param 0|positive-int $counter
* @param null|0|positive-int $window
*/
private function verifyOtpWithWindow(string $otp, int $counter, null|int $window): bool
Expand Down
5 changes: 0 additions & 5 deletions src/HOTPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ interface HOTPInterface extends OTPInterface

/**
* The initial counter (a positive integer).
*
* @return 0|positive-int
*/
public function getCounter(): int;

Expand All @@ -34,8 +32,5 @@ public static function create(
int $digits = 6
): self;

/**
* @param 0|positive-int $counter
*/
public function setCounter(int $counter): void;
}
5 changes: 0 additions & 5 deletions src/OTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ final protected static function generateSecret(): string
/**
* The OTP at the specified input.
*
* @param 0|positive-int $input
*
* @return non-empty-string
*/
protected function generateOTP(int $input): string
Expand Down Expand Up @@ -134,9 +132,6 @@ private function getDecodedSecret(): string
return $decoded;
}

/**
* @param 0|positive-int $int
*/
private function intToByteString(int $int): string
{
$result = [];
Expand Down
5 changes: 0 additions & 5 deletions src/OTPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public static function generate(): self;
*/
public function setSecret(string $secret): void;

/**
* @param positive-int $digits
*/
public function setDigits(int $digits): void;

/**
Expand All @@ -38,8 +35,6 @@ public function setDigits(int $digits): void;
public function setDigest(string $digest): void;

/**
* @param 0|positive-int $input
*
* @return non-empty-string Return the OTP at the specified timestamp
*/
public function at(int $input): string;
Expand Down
37 changes: 15 additions & 22 deletions src/TOTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,21 @@ public function setEpoch(int $epoch): void
*/
protected function getParameterMap(): array
{
return array_merge(
parent::getParameterMap(),
[
'period' => static function ($value): int {
(int) $value > 0 || throw new InvalidArgumentException('Period must be at least 1.');

return (int) $value;
},
'epoch' => static function ($value): int {
(int) $value >= 0 || throw new InvalidArgumentException(
'Epoch must be greater than or equal to 0.'
);

return (int) $value;
},
]
);
return [
...parent::getParameterMap(),
'period' => static function ($value): int {
(int) $value > 0 || throw new InvalidArgumentException('Period must be at least 1.');

return (int) $value;
},
'epoch' => static function ($value): int {
(int) $value >= 0 || throw new InvalidArgumentException(
'Epoch must be greater than or equal to 0.'
);

return (int) $value;
},
];
}

/**
Expand All @@ -186,11 +184,6 @@ protected function filterOptions(array &$options): void
ksort($options);
}

/**
* @param 0|positive-int $timestamp
*
* @return 0|positive-int
*/
private function timecode(int $timestamp): int
{
$timecode = (int) floor(($timestamp - $this->getEpoch()) / $this->getPeriod());
Expand Down
14 changes: 0 additions & 14 deletions src/TOTPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ public static function create(
int $digits = self::DEFAULT_DIGITS
): self;

/**
* @param positive-int $period
*/
public function setPeriod(int $period): void;

/**
* @param 0|positive-int $epoch
*/
public function setEpoch(int $epoch): void;

/**
Expand All @@ -48,18 +42,10 @@ public function now(): string;

/**
* Get the period of time for OTP generation (a non-null positive integer, in second).
*
* @return positive-int
*/
public function getPeriod(): int;

/**
* @return 0|positive-int
*/
public function expiresIn(): int;

/**
* @return 0|positive-int
*/
public function getEpoch(): int;
}
2 changes: 0 additions & 2 deletions tests/HOTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ public function verifyValidInWindow(): void
}

/**
* @param positive-int $digits
* @param non-empty-string $digest
* @param 0|positive-int $counter
* @param non-empty-string $secret
* @param non-empty-string $label
* @param non-empty-string $issuer
Expand Down
3 changes: 0 additions & 3 deletions tests/TOTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,10 @@ public static function dataLeeway(): array
}

/**
* @param positive-int $digits
* @param non-empty-string $digest
* @param positive-int $period
* @param non-empty-string $secret
* @param non-empty-string $label
* @param non-empty-string $issuer
* @param 0|positive-int $epoch
*/
private static function createTOTP(
int $digits,
Expand Down

0 comments on commit 3096d01

Please sign in to comment.