Skip to content

Commit

Permalink
Rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed May 2, 2024
1 parent 5402d4c commit 9f3972b
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/AbstractVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function setRealm(string $realm): self
*
* @return string
*/
public function getRealm(): string
public function realm(): string
{
return $this->realm;
}
Expand All @@ -100,7 +100,7 @@ public function setUsername(string $username): self
*
* @return string
*/
public function getUsername(): string
public function username(): string
{
return $this->username;
}
Expand All @@ -123,7 +123,7 @@ public function setPassword(string $password): self
*
* @return string
*/
public function getPassword(): string
public function password(): string
{
return $this->password;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function digest(string $realm = 'Secure realm'): self
*/
public function secure(?string $message = null): void
{
$this->getVault()->secure($message);
$this->vault()->secure($message);
}

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ public function setCredentials(string $username, string $password): self
*
* @return string
*/
public function getType(): string
public function type(): string
{
return $this->type;
}
Expand All @@ -155,7 +155,7 @@ public function getType(): string
*
* @return string
*/
public function getRealm(): string
public function realm(): string
{
return $this->realm;
}
Expand All @@ -165,7 +165,7 @@ public function getRealm(): string
*
* @return string
*/
public function getUsername(): string
public function username(): string
{
return $this->username;
}
Expand All @@ -175,7 +175,7 @@ public function getUsername(): string
*
* @return string
*/
public function getPassword(): string
public function password(): string
{
return $this->password;
}
Expand All @@ -186,7 +186,7 @@ public function getPassword(): string
* @throws NotSupportedException
* @return AbstractVault
*/
protected function getVault(): AbstractVault
protected function vault(): AbstractVault
{
$classname = sprintf('%s\Vault\%sVault', __NAMESPACE__, ucfirst(strtolower($this->type)));

Expand Down
2 changes: 1 addition & 1 deletion src/Directive.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function format(): string
*
* @return string
*/
public function getType(): string
public function type(): string
{
return $this->type;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Key
*
* @return string
*/
public function getRealm(): ?string
public function realm(): ?string
{
return $this->realm;
}
Expand All @@ -91,7 +91,7 @@ public function getRealm(): ?string
*
* @return string
*/
public function getUsername(): ?string
public function username(): ?string
{
return $this->username;
}
Expand All @@ -101,7 +101,7 @@ public function getUsername(): ?string
*
* @return string
*/
public function getPassword(): ?string
public function password(): ?string
{
return $this->password;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Vault/BasicVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class BasicVault extends AbstractVault
*/
public function unlocksWithKey(Key $key): bool
{
$username_match = $this->getUsername() == $key->getUsername();
$password_match = $this->getPassword() == $key->getPassword();
$username_match = $this->username() == $key->username();
$password_match = $this->password() == $key->password();

return $username_match && $password_match;
}
Expand All @@ -32,7 +32,7 @@ public function unlocksWithKey(Key $key): bool
public function getDirective(): Directive
{
return new Directive('basic', [
'realm' => $this->getRealm(),
'realm' => $this->realm(),
'charset' => 'UTF-8',
]);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Vault/DigestVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DigestVault extends AbstractVault
*/
public function unlocksWithKey(Key $key): bool
{
$username_match = $key->getUsername() == $this->getUsername();
$username_match = $key->username() == $this->username();
$hash_match = $key->getResponse() == $this->getKeyHash($key);

return $username_match && $hash_match;
Expand All @@ -33,7 +33,7 @@ public function unlocksWithKey(Key $key): bool
private function getKeyHash(Key $key): string
{
return md5(implode(':', [
md5(sprintf('%s:%s:%s', $key->getUsername(), $this->getRealm(), $this->getPassword())),
md5(sprintf('%s:%s:%s', $key->username(), $this->realm(), $this->password())),
$key->getNonce(),
$key->getNc(),
$key->getCnonce(),
Expand All @@ -60,10 +60,10 @@ private function getRequestMethod(): string
public function getDirective(): Directive
{
return new Directive('digest', [
'realm' => $this->getRealm(),
'realm' => $this->realm(),
'qop' => 'auth',
'nonce' => uniqid(),
'opaque' => md5($this->getRealm()),
'opaque' => md5($this->realm()),
]);
}
}
12 changes: 6 additions & 6 deletions tests/Unit/AbstractVaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@ public function unlocksWithKey(Key $key): bool
public function testConstructor(): void
{
$vault = $this->getTestVault('myRealm', 'myUsername', 'myPassword');
$this->assertEquals('myUsername', $vault->getUsername());
$this->assertEquals('myPassword', $vault->getPassword());
$this->assertEquals('myRealm', $vault->getRealm());
$this->assertEquals('myUsername', $vault->username());
$this->assertEquals('myPassword', $vault->password());
$this->assertEquals('myRealm', $vault->realm());
}

public function testSetGetUsername(): void
{
$vault = $this->getTestVault('myRealm', 'myUsername', 'myPassword');
$vault->setUsername('foo');
$this->assertEquals('foo', $vault->getUsername());
$this->assertEquals('foo', $vault->username());
}

public function testSetGetPassword(): void
{
$vault = $this->getTestVault('myRealm', 'myUsername', 'myPassword');
$vault->setPassword('foo');
$this->assertEquals('foo', $vault->getPassword());
$this->assertEquals('foo', $vault->password());
}

public function testSetGetRealm(): void
{
$vault = $this->getTestVault('myRealm', 'myUsername', 'myPassword');
$vault->setRealm('foo');
$this->assertEquals('foo', $vault->getRealm());
$this->assertEquals('foo', $vault->realm());
}
}
28 changes: 14 additions & 14 deletions tests/Unit/AuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,61 @@ public function testMake(): void
]);

$this->assertInstanceOf(Authenticator::class, $auth);
$this->assertEquals('digest', $auth->getType());
$this->assertEquals('testRealm', $auth->getRealm());
$this->assertEquals('testUser', $auth->getUsername());
$this->assertEquals('testPass', $auth->getPassword());
$this->assertEquals('digest', $auth->type());
$this->assertEquals('testRealm', $auth->realm());
$this->assertEquals('testUser', $auth->username());
$this->assertEquals('testPass', $auth->password());
}

public function testBasic(): void
{
$auth = Authenticator::basic('test');
$this->assertInstanceOf(Authenticator::class, $auth);
$this->assertEquals('basic', $auth->getType());
$this->assertEquals('test', $auth->getRealm());
$this->assertEquals('basic', $auth->type());
$this->assertEquals('test', $auth->realm());
}

public function testDigest(): void
{
$auth = Authenticator::digest('test');
$this->assertInstanceOf(Authenticator::class, $auth);
$this->assertEquals('digest', $auth->getType());
$this->assertEquals('test', $auth->getRealm());
$this->assertEquals('digest', $auth->type());
$this->assertEquals('test', $auth->realm());
}

public function testSetType(): void
{
$auth = Authenticator::basic()->setType('digest');
$this->assertInstanceOf(Authenticator::class, $auth);
$this->assertEquals('digest', $auth->getType());
$this->assertEquals('digest', $auth->type());
}

public function testSetRealm(): void
{
$auth = Authenticator::basic()->setRealm('foo');
$this->assertInstanceOf(Authenticator::class, $auth);
$this->assertEquals('foo', $auth->getRealm());
$this->assertEquals('foo', $auth->realm());
}

public function testSetUsername(): void
{
$auth = Authenticator::basic()->setUsername('foo');
$this->assertInstanceOf(Authenticator::class, $auth);
$this->assertEquals('foo', $auth->getUsername());
$this->assertEquals('foo', $auth->username());
}

public function testSetPassword(): void
{
$auth = Authenticator::basic()->setPassword('foo');
$this->assertInstanceOf(Authenticator::class, $auth);
$this->assertEquals('foo', $auth->getPassword());
$this->assertEquals('foo', $auth->password());
}

public function testSetCredentials(): void
{
$auth = Authenticator::basic()->setCredentials('foo', 'bar');
$this->assertInstanceOf(Authenticator::class, $auth);
$this->assertEquals('foo', $auth->getUsername());
$this->assertEquals('bar', $auth->getPassword());
$this->assertEquals('foo', $auth->username());
$this->assertEquals('bar', $auth->password());
}
}
12 changes: 6 additions & 6 deletions tests/Unit/KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ final class KeyTest extends TestCase
public function testSetGet(): void
{
$key = new Key();
$this->assertNull($key->getRealm());
$this->assertNull($key->getUsername());
$this->assertNull($key->getPassword());
$this->assertNull($key->realm());
$this->assertNull($key->username());
$this->assertNull($key->password());
$this->assertNull($key->getQop());
$this->assertNull($key->getNonce());
$this->assertNull($key->getOpaque());
Expand All @@ -34,9 +34,9 @@ public function testSetGet(): void
$key->setProperty('cnonce', 'testCnonce');
$key->setProperty('response', 'testResponse');

$this->assertEquals('testRealm', $key->getRealm());
$this->assertEquals('testUsername', $key->getUsername());
$this->assertEquals('testPassword', $key->getPassword());
$this->assertEquals('testRealm', $key->realm());
$this->assertEquals('testUsername', $key->username());
$this->assertEquals('testPassword', $key->password());
$this->assertEquals('testQop', $key->getQop());
$this->assertEquals('testNonce', $key->getNonce());
$this->assertEquals('testOpaque', $key->getOpaque());
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Token/HttpAuthentificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testGetKey(): void
{
$key = $this->getTestToken()->getKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test_username', $key->getUsername());
$this->assertEquals('test_password', $key->getPassword());
$this->assertEquals('test_username', $key->username());
$this->assertEquals('test_password', $key->password());
}

private function getTestToken(): HttpAuthentification
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Token/HttpAuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGetKey(): void
{
$key = $this->getTestToken()->getKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test', $key->getRealm());
$this->assertEquals('test', $key->realm());
$this->assertEquals('auth', $key->getQop());
$this->assertEquals('xxxxxxxxxxxxx', $key->getNonce());
$this->assertEquals('yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy', $key->getOpaque());
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Token/PhpAuthDigestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGetKey(): void
{
$key = $this->getTestToken()->getKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test', $key->getRealm());
$this->assertEquals('test', $key->realm());
$this->assertEquals('auth', $key->getQop());
$this->assertEquals('xxxxxxxxxxxxx', $key->getNonce());
$this->assertEquals('yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy', $key->getOpaque());
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Token/PhpAuthUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testGetKey(): void
{
$key = $this->getTestToken()->getKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test_username', $key->getUsername());
$this->assertEquals('test_password', $key->getPassword());
$this->assertEquals('test_username', $key->username());
$this->assertEquals('test_password', $key->password());
}

private function getTestToken(): PhpAuthUser
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Token/RedirectHttpAuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testGetKey(): void
{
$key = $this->getTestToken()->getKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test_username', $key->getUsername());
$this->assertEquals('test_password', $key->getPassword());
$this->assertEquals('test_username', $key->username());
$this->assertEquals('test_password', $key->password());
}

private function getTestToken(): RedirectHttpAuthorization
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Vault/BasicVaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testGetDirective(): void
$vault = new BasicVault('myRealm', 'myUsername', 'myPassword');
$directive = $vault->getDirective();
$this->assertInstanceOf(Directive::class, $directive);
$this->assertEquals('basic', $directive->getType());
$this->assertEquals('basic', $directive->type());
$this->assertEquals('myRealm', $directive->getParameter('realm'));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Vault/DigestVaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testGetDirective(): void
$vault = new Vault('myRealm', 'myUsername', 'myPassword');
$directive = $vault->getDirective();
$this->assertInstanceOf(Directive::class, $directive);
$this->assertEquals('digest', $directive->getType());
$this->assertEquals('digest', $directive->type());
$this->assertEquals('myRealm', $directive->getParameter('realm'));
$this->assertEquals('auth', $directive->getParameter('qop'));
$this->assertMatchesRegularExpression("/^[a-z0-9]{13}$/", $directive->getParameter('nonce'));
Expand Down

0 comments on commit 9f3972b

Please sign in to comment.