16
16
use Illuminate \Support \Str ;
17
17
18
18
use function preg_match ;
19
+ use function request ;
19
20
20
21
class ApiKeyRepository extends EntityRepository
21
22
{
@@ -28,7 +29,7 @@ public function generate(string $name): ApiKey
28
29
throw new DuplicateName ('An API key already exists with the name: ' . $ name );
29
30
}
30
31
31
- if (!$ this ->isValidName ($ name )) {
32
+ if (! $ this ->isValidName ($ name )) {
32
33
throw new InvalidName ('Please provide a valid name: [a-z0-9-] ' );
33
34
}
34
35
@@ -45,7 +46,7 @@ public function generate(string $name): ApiKey
45
46
->setStatusAt (new DateTime ());
46
47
47
48
$ this ->getEntityManager ()->persist ($ apiKey );
48
- $ this ->getEntityManager ()->persist ($ this ->logAdminEvent ($ apiKey ,'generate ' ));
49
+ $ this ->getEntityManager ()->persist ($ this ->logAdminEvent ($ apiKey , 'generate ' ));
49
50
50
51
return $ apiKey ;
51
52
}
@@ -56,7 +57,7 @@ public function updateActive(ApiKey $apiKey, bool $status): ApiKey
56
57
->setIsActive ($ status )
57
58
->setStatusAt (new DateTime ());
58
59
59
- $ eventName = ( $ status) ? 'activate ' : 'deactivate ' ;
60
+ $ eventName = $ status ? 'activate ' : 'deactivate ' ;
60
61
$ this ->getEntityManager ()->persist ($ this ->logAdminEvent ($ apiKey , $ eventName ));
61
62
62
63
return $ apiKey ;
@@ -89,7 +90,7 @@ public function removeScope(ApiKey $apiKey, Scope $scope): ApiKey
89
90
}
90
91
}
91
92
92
- if (!$ found ) {
93
+ if (! $ found ) {
93
94
throw new ApiKeyDoesNotHaveScope (
94
95
'The requested Scope to remove does not exist on the ApiKey '
95
96
);
@@ -105,16 +106,15 @@ public function removeScope(ApiKey $apiKey, Scope $scope): ApiKey
105
106
106
107
public function isValidName (string $ name ): bool
107
108
{
108
- return (bool )preg_match ('/^[a-z0-9-]{1,255}$/ ' , $ name );
109
+ return (bool ) preg_match ('/^[a-z0-9-]{1,255}$/ ' , $ name );
109
110
}
110
111
111
- protected function logAdminEvent (ApiKey $ apiKey , string $ eventName )
112
+ protected function logAdminEvent (ApiKey $ apiKey , string $ eventName ): AdminEvent
112
113
{
113
114
return (new AdminEvent ())
114
115
->setIpAddress (request ()->ip ())
115
116
->setApiKey ($ apiKey )
116
117
->setEvent ($ eventName )
117
- ->setCreatedAt (new DateTime ())
118
- ;
118
+ ->setCreatedAt (new DateTime ());
119
119
}
120
120
}
0 commit comments