@@ -105,13 +105,12 @@ public function scopeOfKey(Builder $query, string $key): Builder
105105
106106 if ($ compatibilityMode ) {
107107 return $ query ->where (function (Builder $ query ) use ($ key ) {
108- if ($ this -> isMissingId ($ key )) {
108+ if (! str_contains ($ key, ' | ' )) {
109109 return $ query ->where ('key ' , $ key )
110110 ->orWhere ('key ' , hash ('sha256 ' , $ key ));
111111 }
112112
113- $ id = $ this ->extractId ($ key );
114- $ key = $ this ->extractKey ($ key );
113+ [$ id , $ key ] = explode ('| ' , $ key , 2 );
115114
116115 return $ query
117116 ->where (function (Builder $ query ) use ($ key , $ id ) {
@@ -125,26 +124,13 @@ public function scopeOfKey(Builder $query, string $key): Builder
125124 });
126125 }
127126
128- if ($ this -> isMissingId ($ key )) {
127+ if (! str_contains ($ key, ' | ' )) {
129128 return $ query ->where ('key ' , hash ('sha256 ' , $ key ));
130129 }
131130
132- return $ query ->where ('id ' , $ this ->extractId ($ key ))
133- ->where ('key ' , hash ('sha256 ' , $ this ->extractKey ($ key )));
134- }
135-
136- private function isMissingId (string $ key ): bool
137- {
138- return strpos ($ key , '| ' ) === false ;
139- }
131+ [$ id , $ key ] = explode ('| ' , $ key , 2 );
140132
141- private function extractId (string $ key ): string
142- {
143- return explode ('| ' , $ key , 2 )[0 ];
144- }
145-
146- private function extractKey (string $ key ): string
147- {
148- return explode ('| ' , $ key , 2 )[1 ];
133+ return $ query ->where ('id ' , $ id )
134+ ->where ('key ' , hash ('sha256 ' , $ key ));
149135 }
150136}
0 commit comments