Commit 7036407b authored by Jacob Priddy's avatar Jacob Priddy 👌

Reformat code

parent ff462548
......@@ -20,10 +20,10 @@ class Door
protected ?Carbon $updatedAt;
/**
* @param int $id
* @param string $location
* @param string $name
* @param string $token
* @param int $id
* @param string $location
* @param string $name
* @param string $token
* @param Carbon|null $createdAt
* @param Carbon|null $updatedAt
*/
......@@ -67,14 +67,6 @@ class Door
return $this->name;
}
/**
* @return string
*/
public function getToken(): string
{
return $this->token;
}
/**
* @return Carbon|null
*/
......@@ -99,4 +91,12 @@ class Door
return $this->getToken() === $token;
}
/**
* @return string
*/
public function getToken(): string
{
return $this->token;
}
}
......@@ -38,40 +38,40 @@ class SamlUser
/**
* @return string
*/
public function getFirstName(): string
public function getEmplid(): string
{
return $this->firstName;
return $this->emplid;
}
/**
* @return string
*/
public function getLastName(): string
public function getEmail(): string
{
return $this->lastName;
return $this->email;
}
/**
* @return string
*/
public function getEmplid(): string
public function getDisplayName(): string
{
return $this->emplid;
return $this->getFirstName() . ' ' . $this->getLastName();
}
/**
* @return string
*/
public function getEmail(): string
public function getFirstName(): string
{
return $this->email;
return $this->firstName;
}
/**
* @return string
*/
public function getDisplayName(): string
public function getLastName(): string
{
return $this->getFirstName() . ' ' . $this->getLastName();
return $this->lastName;
}
}
......@@ -91,6 +91,14 @@ class Token
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return int
*/
......@@ -139,14 +147,6 @@ class Token
return $this->updatedAt;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @param Carbon $date
* @return bool
......
......@@ -101,14 +101,6 @@ class User
$this->updatedAt = $updatedAt;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
......@@ -141,30 +133,6 @@ class User
return $this->emplid;
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @return string|null
*/
public function getPassword(): ?string
{
return $this->password;
}
/**
* @return string|null
*/
public function getDoorcode(): ?string
{
return $this->doorcode;
}
/**
* @return Carbon|null
*/
......@@ -189,14 +157,6 @@ class User
return $this->updatedAt;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @param string $id
* @return bool
......@@ -210,6 +170,22 @@ class User
return $this->getId() === (int)$id;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
public function matchCredentials(?string $email, ?string $password): bool
{
if (!$password || !$email) {
......@@ -219,6 +195,22 @@ class User
return $this->getEmail() === $email && $this->getPassword() === $password;
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @return string|null
*/
public function getPassword(): ?string
{
return $this->password;
}
/**
* @param string $doorcode
* @return bool
......@@ -232,6 +224,14 @@ class User
return $this->getDoorcode() === $doorcode;
}
/**
* @return string|null
*/
public function getDoorcode(): ?string
{
return $this->doorcode;
}
public function hasEmailOf(?string $email): bool
{
return $this->getEmail() === strtolower($email);
......
......@@ -70,24 +70,6 @@ class SimpleSamlPhpSamlRepository implements SamlRepository
return $this->makeUser();
}
/**
* @inheritDoc
*/
public function logout(): string
{
return $this->saml->getLogoutURL($this->logoutUrl);
}
public function isAuthenticated(): bool
{
return $this->saml->isAuthenticated();
}
public function isGuest(): bool
{
return !$this->isAuthenticated();
}
/**
* Verify required user attributes.
*/
......@@ -102,10 +84,10 @@ class SimpleSamlPhpSamlRepository implements SamlRepository
$validator = Validator::make(
$attributes,
[
'emplid.0' => 'required|string|size:7',
'emplid.0' => 'required|string|size:7',
'first_name.0' => 'required|string',
'last_name.0' => 'required|string',
'email.0' => 'required|email',
'last_name.0' => 'required|string',
'email.0' => 'required|email',
]
);
......@@ -124,4 +106,22 @@ class SimpleSamlPhpSamlRepository implements SamlRepository
$attributes['email'][0]
);
}
public function isGuest(): bool
{
return !$this->isAuthenticated();
}
public function isAuthenticated(): bool
{
return $this->saml->isAuthenticated();
}
/**
* @inheritDoc
*/
public function logout(): string
{
return $this->saml->getLogoutURL($this->logoutUrl);
}
}
......@@ -11,19 +11,6 @@ use Source\Exceptions\EntityNotFoundException;
class DatabaseTokensRepository implements TokensRepository
{
protected function dbTokenToToken(\App\Token $token): Token
{
return new Token(
$token->id,
$token->user_id,
$token->api_token,
$token->name,
$token->expires_at,
$token->created_at,
$token->updated_at
);
}
/**
* @inheritDoc
*/
......@@ -45,6 +32,19 @@ class DatabaseTokensRepository implements TokensRepository
return $this->dbTokenToToken($dbToken);
}
protected function dbTokenToToken(\App\Token $token): Token
{
return new Token(
$token->id,
$token->user_id,
$token->api_token,
$token->name,
$token->expires_at,
$token->created_at,
$token->updated_at
);
}
/**
* @inheritDoc
*/
......@@ -70,9 +70,9 @@ class DatabaseTokensRepository implements TokensRepository
public function invalidateToken(string $token): void
{
$found = \App\Token::where('api_token', $token)
->where('expires_at', '<', Carbon::now())
->where('expires_at', '!=', null)
->first();
->where('expires_at', '<', Carbon::now())
->where('expires_at', '!=', null)
->first();
if ($found) {
$found->expires_at = Carbon::now();
......
......@@ -8,13 +8,12 @@ use Source\Entities\Token;
class InMemoryTokensRepository implements TokensRepository
{
protected static int $id = 1;
/**
* @var Token[]
*/
protected array $tokens = [];
protected static int $id = 1;
/** @inheritDoc */
public function create(Token $token): Token
{
......
......@@ -9,7 +9,7 @@ use Source\Exceptions\EntityNotFoundException;
interface TokensRepository
{
/**
* @param Token $token
* @param Token $token
* @return Token
* @throws EntityNotFoundException
*/
......
......@@ -7,19 +7,6 @@ use Source\Entities\User;
class DatabaseUsersRepository implements UsersRepository
{
protected function fillBasicUserAttrs(User $user, \App\User $dbUser): \App\User
{
$dbUser->first_name = $user->getFirstName();
$dbUser->last_name = $user->getLastName();
$dbUser->display_name = $user->getDisplayName();
$dbUser->emplid = $user->getEmplid();
$dbUser->email = $user->getEmail();
$dbUser->password = bcrypt($user->getPassword());
$dbUser->doorcode = hash('sha256', $user->getDoorcode());
$dbUser->expires_at = $user->getExpiresAt();
return $dbUser;
}
/**
* @inheritDoc
*/
......@@ -97,6 +84,19 @@ class DatabaseUsersRepository implements UsersRepository
);
}
protected function fillBasicUserAttrs(User $user, \App\User $dbUser): \App\User
{
$dbUser->first_name = $user->getFirstName();
$dbUser->last_name = $user->getLastName();
$dbUser->display_name = $user->getDisplayName();
$dbUser->emplid = $user->getEmplid();
$dbUser->email = $user->getEmail();
$dbUser->password = bcrypt($user->getPassword());
$dbUser->doorcode = hash('sha256', $user->getDoorcode());
$dbUser->expires_at = $user->getExpiresAt();
return $dbUser;
}
/**
* @inheritDoc
*/
......@@ -208,7 +208,7 @@ class DatabaseUsersRepository implements UsersRepository
*/
public function findByEmail(string $email): ?User
{
$user = \App\User::where('email', strtolower($email))->first();
$user = \App\User::where('email', strtolower($email))->first();
return new User(
$user->id,
......
......@@ -7,29 +7,14 @@ use Source\Entities\User;
class InMemoryUsersRepository implements UsersRepository
{
/**
* @var User[]
*/
protected array $users = [];
/**
* @var int
*/
public static int $idCounter = 100;
/**
* @inheritDoc
* @var User[]
*/
public function get(string $userId): ?User
{
foreach ($this->users as $user) {
if ($user->hasUserIdOf($userId)) {
return $user;
}
}
return null;
}
protected array $users = [];
/**
* @inheritDoc
......@@ -57,6 +42,28 @@ class InMemoryUsersRepository implements UsersRepository
return $user;
}
/**
* @inheritDoc
*/
public function exists(string $userId): bool
{
return $this->get($userId) !== null;
}
/**
* @inheritDoc
*/
public function get(string $userId): ?User
{
foreach ($this->users as $user) {
if ($user->hasUserIdOf($userId)) {
return $user;
}
}
return null;
}
/**
* @inheritDoc
*/
......@@ -84,14 +91,6 @@ class InMemoryUsersRepository implements UsersRepository
return true;
}
/**
* @inheritDoc
*/
public function exists(string $userId): bool
{
return $this->get($userId) !== null;
}
/**
* @inheritDoc
*/
......
......@@ -23,20 +23,6 @@ abstract class BasePresenter
return $bool ? $true : $false;
}
/**
* @param Carbon|null $date
* @param string $format
* @return string|null
*/
public function formatDate(?Carbon $date, string $format = 'M j, Y'): ?string
{
if ($date === null) {
return null;
}
return $date->format($format);
}
/**
* @param Carbon|null $time
* @param string $format
......@@ -83,4 +69,18 @@ abstract class BasePresenter
'updated_at' => $this->formatDate($user->getUpdatedAt()),
];
}
/**
* @param Carbon|null $date
* @param string $format
* @return string|null
*/
public function formatDate(?Carbon $date, string $format = 'M j, Y'): ?string
{
if ($date === null) {
return null;
}
return $date->format($format);
}
}
......@@ -12,18 +12,18 @@ class ResponseModel
protected ?Door $door = null;
/**
* @param Door|null $door
* @return Door|null
*/
public function setDoor(?Door $door): void
public function getDoor(): ?Door
{
$this->door = $door;
return $this->door;
}
/**
* @return Door|null
* @param Door|null $door
*/
public function getDoor(): ?Door
public function setDoor(?Door $door): void
{
return $this->door;
$this->door = $door;
}
}
......@@ -12,18 +12,18 @@ class ResponseModel
protected ?User $user = null;
/**
* @param User|null $user
* @return User|null
*/
public function setUser(?User $user): void
public function getUser(): ?User
{
$this->user = $user;
return $this->user;
}
/**
* @return User|null
* @param User|null $user
*/
public function getUser(): ?User
public function setUser(?User $user): void
{
return $this->user;
$this->user = $user;
}
}
......@@ -17,42 +17,42 @@ class ResponseModel
protected ?User $user = null;
/**
* @param string $error
* @return bool
*/
public function setError(string $error): void
public function hasError(): bool
{
$this->error = $error;