Skip to content

Commit 230e269

Browse files
author
s3b4stian
committed
refactor done
1 parent 9dec02f commit 230e269

8 files changed

Lines changed: 26 additions & 16 deletions

File tree

.php-cs-fixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'@PSR12' => true,
88
'no_whitespace_in_blank_line' => true,
99
'return_type_declaration' => true,
10-
'native_function_invocation' => ['include' => ['@all']],
10+
'native_function_invocation' => ['include' => ['@compiler_optimized']],
1111
'phpdoc_align' => true,
1212
'phpdoc_separation' => true,
1313
'phpdoc_line_span' => ['property' => 'single', 'const' => 'single']

src/Linna/Authentication/EnhancedAuthenticationMapper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function fetchLimit(int $offset, int $rowCount): array
164164
public function fetchAttemptsWithSameUser(string $userName, int $timeInSeconds): int
165165
{
166166
//handle time
167-
$time = \date(DATE_ATOM, \time() - $timeInSeconds);
167+
$time = date(DATE_ATOM, time() - $timeInSeconds);
168168

169169
//make query
170170
$stmt = $this->pdo->prepare('SELECT count(user_name) as attempts FROM public.login_attempt WHERE user_name = :user_name AND date_time > :time');
@@ -187,7 +187,7 @@ public function fetchAttemptsWithSameUser(string $userName, int $timeInSeconds):
187187
public function fetchAttemptsWithSameSession(string $sessionId, int $timeInSeconds): int
188188
{
189189
//handle time
190-
$time = \date(DATE_ATOM, \time() - $timeInSeconds);
190+
$time = date(DATE_ATOM, time() - $timeInSeconds);
191191

192192
//make query
193193
$stmt = $this->pdo->prepare('SELECT count(session_id) as attempts FROM public.login_attempt WHERE session_id = :session_id AND date_time > :time');
@@ -210,7 +210,7 @@ public function fetchAttemptsWithSameSession(string $sessionId, int $timeInSecon
210210
public function fetchAttemptsWithSameIp(string $ipAddress, int $timeInSeconds): int
211211
{
212212
//handle time
213-
$time = \date(DATE_ATOM, \time() - $timeInSeconds);
213+
$time = date(DATE_ATOM, time() - $timeInSeconds);
214214

215215
//make query
216216
$stmt = $this->pdo->prepare('SELECT count(ip) as attempts FROM public.login_attempt WHERE ip = :ip AND date_time > :time');
@@ -232,7 +232,7 @@ public function fetchAttemptsWithSameIp(string $ipAddress, int $timeInSeconds):
232232
public function deleteOldLoginAttempts(int $timeInSeconds): bool
233233
{
234234
//handle time
235-
$time = \date(DATE_ATOM, \time() - $timeInSeconds);
235+
$time = date(DATE_ATOM, time() - $timeInSeconds);
236236

237237
//make query
238238
$stmt = $this->pdo->prepare('DELETE FROM public.login_attempt WHERE date_time < :time');

src/Linna/Authorization/PermissionMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function fetchById(int|string $permissionId): DomainObjectInterface
117117
public function fetchByName(string $permissionName): DomainObjectInterface
118118
{
119119
//handle permission name
120-
$hashedPermissionName = \md5($permissionName);
120+
$hashedPermissionName = md5($permissionName);
121121

122122
//make query
123123
$stmt = $this->pdo->prepare(self::QUERY_BASE.' WHERE md5(name) = :name');
@@ -384,7 +384,7 @@ public function fetchUserPermissionHashTable(int $userId): array
384384
}
385385

386386
//return result
387-
return \array_flip($result);
387+
return array_flip($result);
388388
}
389389

390390
/**

src/Linna/Authorization/RoleMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function fetchById(int|string $roleId): DomainObjectInterface
111111
public function fetchByName(string $roleName): DomainObjectInterface
112112
{
113113
//handle user name
114-
$hashedRoleName = \md5($roleName);
114+
$hashedRoleName = md5($roleName);
115115

116116
//make query
117117
$stmt = $this->pdo->prepare(self::QUERY_BASE.' WHERE md5(name) = :name');

src/Linna/Authorization/UserExtendedMapper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function hydrator(array $array): array
101101
description: $value->description,
102102
email: $value->email,
103103
password: $value->password,
104-
active: $value->active,
104+
active: (int) $value->active,
105105
created: new DateTimeImmutable($value->created),
106106
lastUpdate: new DateTimeImmutable($value->last_update),
107107
roles: $roles,
@@ -133,7 +133,7 @@ protected function hydratorSingle(object $object): DomainObjectInterface
133133
description: $object->description,
134134
email: $object->email,
135135
password: $object->password,
136-
active: $object->active,
136+
active: (int) $object->active,
137137
created: new DateTimeImmutable($object->created),
138138
lastUpdate: new DateTimeImmutable($object->last_update),
139139
roles: $roles,
@@ -159,7 +159,7 @@ public function grantPermissionById(UserExtended &$user, string|int $permissionI
159159

160160
try {
161161
//make query
162-
$stmt = $this->pdo->prepare('INSERT INTO public.user_permission (user_id, permission_id) VALUES (:user_id, :permission_id) ON DUPLICATE KEY UPDATE user_id = :user_id, permission_id = :permission_id');
162+
$stmt = $this->pdo->prepare('INSERT INTO public.user_permission (user_id, permission_id) VALUES (:user_id, :permission_id) ON CONFLICT (user_id, permission_id) DO UPDATE SET user_id = :user_id, permission_id = :permission_id');
163163

164164
$stmt->bindParam(':user_id', $userId, PDO::PARAM_INT);
165165
$stmt->bindParam(':permission_id', $permissionId, PDO::PARAM_INT);
@@ -245,7 +245,7 @@ public function addRoleById(UserExtended &$user, int|string $roleId)
245245

246246
try {
247247
//make query
248-
$stmt = $this->pdo->prepare('INSERT INTO public.user_role (user_id, role_id) VALUES (:user_id, :role_id) ON DUPLICATE KEY UPDATE user_id = :user_id, role_id = :role_id');
248+
$stmt = $this->pdo->prepare('INSERT INTO public.user_role (user_id, role_id) VALUES (:user_id, :role_id) ON CONFLICT (user_id, role_id) DO UPDATE SET user_id = :user_id, role_id = :role_id');
249249

250250
$stmt->bindParam(':user_id', $userId, PDO::PARAM_INT);
251251
$stmt->bindParam(':role_id', $roleId, PDO::PARAM_INT);

src/Linna/Authorization/UserMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function fetchById(int|string $userId): DomainObjectInterface
136136
public function fetchByName(string $userName): DomainObjectInterface
137137
{
138138
//handle user name
139-
$hashedUserName = \md5($userName);
139+
$hashedUserName = md5($userName);
140140

141141
//make query
142142
$stmt = $this->pdo->prepare(self::QUERY_BASE.' WHERE md5(name) = :name');
@@ -411,7 +411,7 @@ protected function concreteInsert(DomainObjectInterface &$user): void
411411

412412
$stmt->execute();
413413

414-
\settype($user->active, "integer");
414+
settype($user->active, "integer");
415415

416416
$user->setId((int) $this->pdo->lastInsertId());
417417
} catch (RuntimeException $e) {
@@ -450,7 +450,7 @@ protected function concreteUpdate(DomainObjectInterface $user): void
450450

451451
$stmt->execute();
452452

453-
\settype($user->active, "integer");
453+
settype($user->active, "integer");
454454

455455
} catch (RuntimeException $e) {
456456
echo 'Update not compled, ', $e->getMessage(), "\n";

tests/Linna/Authorization/PermissionExtendedMapperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public static function setUpBeforeClass(): void
6363
*/
6464
public static function tearDownAfterClass(): void
6565
{
66-
self::$pdo->exec('ALTER TABLE permission AUTO_INCREMENT = 0');
66+
//self::$pdo->exec('ALTER TABLE permission AUTO_INCREMENT = 0');
6767
}
6868
}

tests/Linna/Authorization/UserExtendedMapperTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,14 @@ public static function setUpBeforeClass(): void
5656
self::$roleMapper = $roleMapper;
5757
self::$userExtendedMapper = $userExtendedMapper;
5858
}
59+
60+
/**
61+
* Tear Down.
62+
*
63+
* @return void
64+
*/
65+
public static function tearDownAfterClass(): void
66+
{
67+
self::$pdo->exec('ALTER SEQUENCE public.user_user_id_seq RESTART WITH 8 INCREMENT BY 1;');
68+
}
5969
}

0 commit comments

Comments
 (0)