1616use Illuminate \Support \Str ;
1717
1818use function preg_match ;
19+ use function request ;
1920
2021class 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