Skip to content

Commit 673bf76

Browse files
authored
Add hard return-type on User::getCredential() (#316)
1 parent 765018a commit 673bf76

31 files changed

+74
-110
lines changed

Credential/Anonymous.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,4 @@ public function __invoke(ChangeCredential $event): bool
1515
{
1616
throw new \BadMethodCallException('An anonymous credential cannot be changed.');
1717
}
18-
19-
public static function getUsernameField(): string
20-
{
21-
throw new \BadMethodCallException('An anonymous credential has no username field.');
22-
}
23-
24-
public function getUsername(): string
25-
{
26-
throw new \BadMethodCallException('An anonymous credential has no username.');
27-
}
2818
}

Credential/Credential.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,4 @@
1212
interface Credential
1313
{
1414
public function __invoke(ChangeCredential $event): bool;
15-
16-
public static function getUsernameField(): string;
17-
18-
public function getUsername(): string;
1915
}

Credential/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @author Roland Franssen <[email protected]>
1111
*/
12-
final class Email implements Credential
12+
final class Email implements UsernameCredential
1313
{
1414
use EmailAsUsername;
1515

Credential/EmailPassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @author Roland Franssen <[email protected]>
1111
*/
12-
final class EmailPassword implements PasswordProtectedCredential
12+
final class EmailPassword implements UsernameCredential, PasswordProtectedCredential
1313
{
1414
use EmailAsUsername;
1515
use PasswordProtection;

Credential/Nickname.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @author Roland Franssen <[email protected]>
1111
*/
12-
final class Nickname implements Credential
12+
final class Nickname implements UsernameCredential
1313
{
1414
use NicknameAsUsername;
1515

Credential/NicknamePassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @author Roland Franssen <[email protected]>
1111
*/
12-
final class NicknamePassword implements PasswordProtectedCredential
12+
final class NicknamePassword implements UsernameCredential, PasswordProtectedCredential
1313
{
1414
use NicknameAsUsername;
1515
use PasswordProtection;

Credential/PasswordProtectedCredential.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use MsgPhp\User\Password\PasswordAlgorithm;
88

99
/**
10-
* Represents a password protected credential. The password is usually a *hashed* value (thus secret).
10+
* Represents a user credential that is password protected. The password is usually a *hashed* value (thus secret).
1111
*
1212
* @author Roland Franssen <[email protected]>
1313
*/
1414
interface PasswordProtectedCredential extends Credential
1515
{
16+
public static function getPasswordField(): string;
17+
1618
public function getPassword(): string;
1719

1820
public function getPasswordAlgorithm(): ?PasswordAlgorithm;

Credential/PasswordProtection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ trait PasswordProtection
1616
*/
1717
private $password;
1818

19+
public static function getPasswordField(): string
20+
{
21+
return 'password';
22+
}
23+
1924
public function getPassword(): string
2025
{
2126
return $this->password;

Credential/Token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @author Roland Franssen <[email protected]>
1111
*/
12-
final class Token implements Credential
12+
final class Token implements UsernameCredential
1313
{
1414
/**
1515
* @var string

Credential/UsernameCredential.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MsgPhp\User\Credential;
6+
7+
/**
8+
* Represents a user credential that is bound to a known username.
9+
*
10+
* @author Roland Franssen <[email protected]>
11+
*/
12+
interface UsernameCredential extends Credential
13+
{
14+
public static function getUsernameField(): string;
15+
16+
public function getUsername(): string;
17+
}

0 commit comments

Comments
 (0)