Skip to content

Commit 36264d3

Browse files
authored
Merge pull request #1 from TomHAnderson/hotfix/admin-events
Fixed AdminEvent logging cs
2 parents 335c529 + 0f42dd5 commit 36264d3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Repository/ApiKeyRepository.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Illuminate\Support\Str;
1717

1818
use function preg_match;
19+
use function request;
1920

2021
class ApiKeyRepository extends EntityRepository
2122
{
@@ -28,7 +29,7 @@ public function generate(string $name): ApiKey
2829
throw new DuplicateName('An API key already exists with the name: ' . $name);
2930
}
3031

31-
if (!$this->isValidName($name)) {
32+
if (! $this->isValidName($name)) {
3233
throw new InvalidName('Please provide a valid name: [a-z0-9-]');
3334
}
3435

@@ -45,7 +46,7 @@ public function generate(string $name): ApiKey
4546
->setStatusAt(new DateTime());
4647

4748
$this->getEntityManager()->persist($apiKey);
48-
$this->getEntityManager()->persist($this->logAdminEvent($apiKey,'generate'));
49+
$this->getEntityManager()->persist($this->logAdminEvent($apiKey, 'generate'));
4950

5051
return $apiKey;
5152
}
@@ -56,7 +57,7 @@ public function updateActive(ApiKey $apiKey, bool $status): ApiKey
5657
->setIsActive($status)
5758
->setStatusAt(new DateTime());
5859

59-
$eventName = ($status) ? 'activate': 'deactivate';
60+
$eventName = $status ? 'activate' : 'deactivate';
6061
$this->getEntityManager()->persist($this->logAdminEvent($apiKey, $eventName));
6162

6263
return $apiKey;
@@ -89,7 +90,7 @@ public function removeScope(ApiKey $apiKey, Scope $scope): ApiKey
8990
}
9091
}
9192

92-
if (!$found) {
93+
if (! $found) {
9394
throw new ApiKeyDoesNotHaveScope(
9495
'The requested Scope to remove does not exist on the ApiKey'
9596
);
@@ -105,16 +106,15 @@ public function removeScope(ApiKey $apiKey, Scope $scope): ApiKey
105106

106107
public function isValidName(string $name): bool
107108
{
108-
return (bool)preg_match('/^[a-z0-9-]{1,255}$/', $name);
109+
return (bool) preg_match('/^[a-z0-9-]{1,255}$/', $name);
109110
}
110111

111-
protected function logAdminEvent(ApiKey $apiKey, string $eventName)
112+
protected function logAdminEvent(ApiKey $apiKey, string $eventName): AdminEvent
112113
{
113114
return (new AdminEvent())
114115
->setIpAddress(request()->ip())
115116
->setApiKey($apiKey)
116117
->setEvent($eventName)
117-
->setCreatedAt(new DateTime())
118-
;
118+
->setCreatedAt(new DateTime());
119119
}
120120
}

0 commit comments

Comments
 (0)