Skip to content

Commit 55bb88d

Browse files
Removed unnecessary usage of ClassMapper->staticMethod
1 parent 3f1e204 commit 55bb88d

15 files changed

Lines changed: 68 additions & 67 deletions

File tree

app/sprinkles/account/src/Account/Registration.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function register()
9090
$this->validate();
9191

9292
// Set default group
93-
$defaultGroup = $this->ci->classMapper->staticMethod('group', 'where', 'slug', $this->defaultGroup)->first();
93+
$defaultGroup = $this->ci->classMapper->getClassMapping('group')::where('slug', $this->defaultGroup)->first();
9494

9595
if (!$defaultGroup) {
9696
$e = new HttpException("Account registration is not working because the default group '{$this->defaultGroup}' does not exist.");
@@ -125,7 +125,7 @@ public function register()
125125
]);
126126

127127
// Load default roles
128-
$defaultRoles = $this->ci->classMapper->staticMethod('role', 'whereIn', 'slug', $this->defaultRoles)->get();
128+
$defaultRoles = $this->ci->classMapper->getClassMapping('role')::whereIn('slug', $this->defaultRoles)->get();
129129
$defaultRoleIds = $defaultRoles->pluck('id')->all();
130130

131131
// Attach default roles
@@ -188,7 +188,7 @@ public function validate()
188188
*/
189189
public function usernameIsUnique($username)
190190
{
191-
return !($this->ci->classMapper->staticMethod('user', 'findUnique', $username, 'user_name'));
191+
return !($this->ci->classMapper->getClassMapping('user')::findUnique($username, 'user_name'));
192192
}
193193

194194
/**
@@ -200,7 +200,7 @@ public function usernameIsUnique($username)
200200
*/
201201
public function emailIsUnique($email)
202202
{
203-
return !($this->ci->classMapper->staticMethod('user', 'findUnique', $email, 'email'));
203+
return !($this->ci->classMapper->getClassMapping('user')::findUnique($email, 'email'));
204204
}
205205

206206
/**
@@ -219,7 +219,7 @@ protected function setDefaults()
219219
$this->verified = $this->ci->config['site.registration.require_email_verification'];
220220
$this->requireEmailVerification = $this->ci->config['site.registration.require_email_verification'];
221221
$this->defaultGroup = $this->ci->config['site.registration.user_defaults.group'];
222-
$this->defaultRoles = $this->ci->classMapper->staticMethod('role', 'getDefaultSlugs');
222+
$this->defaultRoles = $this->ci->classMapper->getClassMapping('role')::getDefaultSlugs();
223223
}
224224

225225
/**

app/sprinkles/account/src/Authenticate/Authenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function __construct(ClassMapper $classMapper, Session $session, Config $
142142
public function attempt($identityColumn, $identityValue, $password, $rememberMe = false)
143143
{
144144
// Try to load the user, using the specified conditions
145-
$user = $this->classMapper->staticMethod('user', 'where', $identityColumn, $identityValue)->first();
145+
$user = $this->classMapper->getClassMapping('user')::where($identityColumn, $identityValue)->first();
146146

147147
if (!$user) {
148148
throw new InvalidCredentialsException();
@@ -252,7 +252,7 @@ public function logout($complete = false)
252252

253253
// User logout actions
254254
if ($currentUserId) {
255-
$currentUser = $this->classMapper->staticMethod('user', 'find', $currentUserId);
255+
$currentUser = $this->classMapper->getClassMapping('user')::find($currentUserId);
256256
if ($currentUser) {
257257
$currentUser->onLogout();
258258
}
@@ -411,7 +411,7 @@ protected function validateUserAccount($userId)
411411
// Load user from db, cache the result
412412
$key = $this->config['cache.user.key'] . $userId;
413413
$user = $this->cache->remember($key, $this->config['cache.user.delay'], function () use ($userId) {
414-
return $this->classMapper->staticMethod('user', 'find', (int) $userId);
414+
return $this->classMapper->getClassMapping('user')::find((int) $userId);
415415
});
416416

417417
// If the user doesn't exist any more, throw an exception.

app/sprinkles/account/src/Controller/AccountController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function checkUsername(Request $request, Response $response, $args)
9898
// Log throttleable event
9999
$throttler->logEvent('check_username_request');
100100

101-
if ($classMapper->staticMethod('user', 'findUnique', $data['user_name'], 'user_name')) {
101+
if ($classMapper->getClassMapping('user')::findUnique($data['user_name'], 'user_name')) {
102102
$message = $translator->translate('USERNAME.NOT_AVAILABLE', $data);
103103

104104
return $response->write($message)->withStatus(200);
@@ -237,7 +237,7 @@ public function forgotPassword(Request $request, Response $response, $args)
237237
$throttler->logEvent('password_reset_request', $throttleData);
238238

239239
// Load the user, by email address
240-
$user = $classMapper->staticMethod('user', 'where', 'email', $data['email'])->first();
240+
$user = $classMapper->getClassMapping('user')::where('email', $data['email'])->first();
241241

242242
// Check that the email exists.
243243
// If there is no user with that email address, we should still pretend like we succeeded, to prevent account enumeration
@@ -845,7 +845,7 @@ public function register(Request $request, Response $response, $args)
845845
}
846846

847847
// Security measure: do not allow registering new users until the master account has been created.
848-
if (!$classMapper->staticMethod('user', 'find', $config['reserved_user_ids.master'])) {
848+
if (!$classMapper->getClassMapping('user')::find($config['reserved_user_ids.master'])) {
849849
$ms->addMessageTranslated('danger', 'ACCOUNT.MASTER_NOT_EXISTS');
850850

851851
return $response->withJson([], 403);
@@ -1002,7 +1002,7 @@ public function resendVerification(Request $request, Response $response, $args)
10021002
$throttler->logEvent('verification_request', $throttleData);
10031003

10041004
// Load the user, by email address
1005-
$user = $classMapper->staticMethod('user', 'where', 'email', $data['email'])->first();
1005+
$user = $classMapper->getClassMapping('user')::where('email', $data['email'])->first();
10061006

10071007
// Check that the user exists and is not already verified.
10081008
// If there is no user with that email address, or the user exists and is already verified,
@@ -1181,7 +1181,7 @@ public function settings(Request $request, Response $response, $args)
11811181
unset($data['passwordc']);
11821182

11831183
// If new email was submitted, check that the email address is not in use
1184-
if (isset($data['email']) && $data['email'] != $currentUser->email && $classMapper->staticMethod('user', 'findUnique', $data['email'], 'email')) {
1184+
if (isset($data['email']) && $data['email'] != $currentUser->email && $classMapper->getClassMapping('user')::findUnique($data['email'], 'email')) {
11851185
$ms->addMessageTranslated('danger', 'EMAIL.IN_USE', $data);
11861186
$error = true;
11871187
}

app/sprinkles/account/src/Database/Models/User.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ public function delete($hardDelete = false)
189189
$this->roles()->detach();
190190

191191
// Remove all user activities
192-
$classMapper->staticMethod('activity', 'where', 'user_id', $this->id)->delete();
192+
$classMapper->getClassMapping('activity')::where('user_id', $this->id)->delete();
193193

194194
// Remove all user tokens
195-
$classMapper->staticMethod('password_reset', 'where', 'user_id', $this->id)->delete();
196-
$classMapper->staticMethod('verification', 'where', 'user_id', $this->id)->delete();
195+
$classMapper->getClassMapping('password_reset')::where('user_id', $this->id)->delete();
196+
$classMapper->getClassMapping('verification')::where('user_id', $this->id)->delete();
197197

198198
// TODO: remove any persistences
199199

app/sprinkles/account/src/Log/UserActivityDatabaseHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function write(array $record)
2727
$log->save();
2828

2929
if (isset($record['extra']['user_id'])) {
30-
$user = $this->classMapper->staticMethod('user', 'find', $record['extra']['user_id']);
30+
$user = $this->classMapper->getClassMapping('user')::find($record['extra']['user_id']);
3131
$user->last_activity_id = $log->id;
3232
$user->save();
3333
}

app/sprinkles/account/src/Repository/TokenRepository.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public function cancel($token)
6262
$hash = hash($this->algorithm, $token);
6363

6464
// Find an incomplete reset request for the specified hash
65-
$model = $this->classMapper
66-
->staticMethod($this->modelIdentifier, 'where', 'hash', $hash)
65+
$model = $this->classMapper->getClassMapping($this->modelIdentifier)
66+
::where('hash', $hash)
6767
->where('completed', false)
6868
->first();
6969

@@ -89,8 +89,8 @@ public function complete($token, $userParams = [])
8989
$hash = hash($this->algorithm, $token);
9090

9191
// Find an unexpired, incomplete token for the specified hash
92-
$model = $this->classMapper
93-
->staticMethod($this->modelIdentifier, 'where', 'hash', $hash)
92+
$model = $this->classMapper->getClassMapping($this->modelIdentifier)
93+
::where('hash', $hash)
9494
->where('completed', false)
9595
->where('expires_at', '>', Carbon::now())
9696
->first();
@@ -100,7 +100,7 @@ public function complete($token, $userParams = [])
100100
}
101101

102102
// Fetch user for this token
103-
$user = $this->classMapper->staticMethod('user', 'find', $model->user_id);
103+
$user = $this->classMapper->getClassMapping('user')::find($model->user_id);
104104

105105
if (is_null($user)) {
106106
return false;
@@ -163,8 +163,8 @@ public function create(UserInterface $user, $timeout)
163163
*/
164164
public function exists(UserInterface $user, $token = null)
165165
{
166-
$model = $this->classMapper
167-
->staticMethod($this->modelIdentifier, 'where', 'user_id', $user->id)
166+
$model = $this->classMapper->getClassMapping($this->modelIdentifier)
167+
::where('user_id', $user->id)
168168
->where('completed', false)
169169
->where('expires_at', '>', Carbon::now());
170170

@@ -185,8 +185,8 @@ public function exists(UserInterface $user, $token = null)
185185
*/
186186
protected function removeExisting(UserInterface $user)
187187
{
188-
return $this->classMapper
189-
->staticMethod($this->modelIdentifier, 'where', 'user_id', $user->id)
188+
return $this->classMapper->getClassMapping($this->modelIdentifier)
189+
::where('user_id', $user->id)
190190
->delete();
191191
}
192192

@@ -197,8 +197,8 @@ protected function removeExisting(UserInterface $user)
197197
*/
198198
public function removeExpired()
199199
{
200-
return $this->classMapper
201-
->staticMethod($this->modelIdentifier, 'where', 'completed', false)
200+
return $this->classMapper->getClassMapping($this->modelIdentifier)
201+
::where('completed', false)
202202
->where('expires_at', '<', Carbon::now())
203203
->delete();
204204
}
@@ -214,8 +214,8 @@ protected function generateRandomToken($gen = null)
214214
{
215215
do {
216216
$gen = md5(uniqid(mt_rand(), false));
217-
} while ($this->classMapper
218-
->staticMethod($this->modelIdentifier, 'where', 'hash', hash($this->algorithm, $gen))
217+
} while ($this->classMapper->getClassMapping($this->modelIdentifier)
218+
::where('hash', hash($this->algorithm, $gen))
219219
->first());
220220

221221
return $gen;

app/sprinkles/account/src/Util/Util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function randomUniqueUsername(ClassMapper $classMapper, $maxLength
3535
for ($m = 0; $m < 10; $m++) {
3636
// Generate a random phrase with $n adjectives
3737
$suggestion = CoreUtil::randomPhrase($n, $maxLength, $maxTries, '.');
38-
if (!$classMapper->staticMethod('user', 'where', 'user_name', $suggestion)->first()) {
38+
if (!$classMapper->getClassMapping('user')::where('user_name', $suggestion)->first()) {
3939
return $suggestion;
4040
}
4141
}

app/sprinkles/admin/src/Controller/AdminController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function pageDashboard(Request $request, Response $response, $args)
4848
$classMapper = $this->ci->classMapper;
4949

5050
// Probably a better way to do this
51-
$users = $classMapper->staticMethod('user', 'orderBy', 'created_at', 'desc')
51+
$users = $classMapper->getClassMapping('user')::orderBy('created_at', 'desc')
5252
->take(8)
5353
->get();
5454

@@ -70,9 +70,9 @@ public function pageDashboard(Request $request, Response $response, $args)
7070

7171
return $this->ci->view->render($response, 'pages/dashboard.html.twig', [
7272
'counter' => [
73-
'users' => $classMapper->staticMethod('user', 'count'),
74-
'roles' => $classMapper->staticMethod('role', 'count'),
75-
'groups' => $classMapper->staticMethod('group', 'count')
73+
'users' => $classMapper->getClassMapping('user')::count(),
74+
'roles' => $classMapper->getClassMapping('role')::count(),
75+
'groups' => $classMapper->getClassMapping('group')::count()
7676
],
7777
'info' => [
7878
'version' => [

app/sprinkles/admin/src/Controller/GroupController.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ public function create(Request $request, Response $response, $args)
8484
$classMapper = $this->ci->classMapper;
8585

8686
// Check if name or slug already exists
87-
if ($classMapper->staticMethod('group', 'where', 'name', $data['name'])->first()) {
87+
if ($classMapper->getClassMapping('group')::where('name', $data['name'])->first()) {
8888
$ms->addMessageTranslated('danger', 'GROUP.NAME.IN_USE', $data);
8989
$error = true;
9090
}
9191

92-
if ($classMapper->staticMethod('group', 'where', 'slug', $data['slug'])->first()) {
92+
if ($classMapper->getClassMapping('group')::where('slug', $data['slug'])->first()) {
9393
$ms->addMessageTranslated('danger', 'GROUP.SLUG.IN_USE', $data);
9494
$error = true;
9595
}
@@ -178,7 +178,7 @@ public function delete(Request $request, Response $response, $args)
178178
$classMapper = $this->ci->classMapper;
179179

180180
// Check if there are any users in this group
181-
$countGroupUsers = $classMapper->staticMethod('user', 'where', 'group_id', $group->id)->count();
181+
$countGroupUsers = $classMapper->getClassMapping('user')::where('group_id', $group->id)->count();
182182
if ($countGroupUsers > 0) {
183183
$e = new BadRequestException();
184184
$e->addUserMessage('GROUP.NOT_EMPTY', $group->toArray());
@@ -239,7 +239,7 @@ public function getInfo(Request $request, Response $response, $args)
239239
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
240240
$classMapper = $this->ci->classMapper;
241241

242-
$group = $classMapper->staticMethod('group', 'where', 'slug', $slug)->first();
242+
$group = $classMapper->getClassMapping('group')::where('slug', $slug)->first();
243243

244244
// If the group doesn't exist, return 404
245245
if (!$group) {
@@ -331,7 +331,7 @@ public function getModalConfirmDelete(Request $request, Response $response, $arg
331331
$classMapper = $this->ci->classMapper;
332332

333333
// Check if there are any users in this group
334-
$countGroupUsers = $classMapper->staticMethod('user', 'where', 'group_id', $group->id)->count();
334+
$countGroupUsers = $classMapper->getClassMapping('user')::where('group_id', $group->id)->count();
335335
if ($countGroupUsers > 0) {
336336
$e = new BadRequestException();
337337
$e->addUserMessage('GROUP.NOT_EMPTY', $group->toArray());
@@ -714,7 +714,7 @@ public function updateInfo(Request $request, Response $response, $args)
714714
if (
715715
isset($data['name']) &&
716716
$data['name'] != $group->name &&
717-
$classMapper->staticMethod('group', 'where', 'name', $data['name'])->first()
717+
$classMapper->getClassMapping('group')::where('name', $data['name'])->first()
718718
) {
719719
$ms->addMessageTranslated('danger', 'GROUP.NAME.IN_USE', $data);
720720
$error = true;
@@ -723,7 +723,7 @@ public function updateInfo(Request $request, Response $response, $args)
723723
if (
724724
isset($data['slug']) &&
725725
$data['slug'] != $group->slug &&
726-
$classMapper->staticMethod('group', 'where', 'slug', $data['slug'])->first()
726+
$classMapper->getClassMapping('group')::where('slug', $data['slug'])->first()
727727
) {
728728
$ms->addMessageTranslated('danger', 'GROUP.SLUG.IN_USE', $data);
729729
$error = true;
@@ -791,7 +791,7 @@ protected function getGroupFromParams($params)
791791
$classMapper = $this->ci->classMapper;
792792

793793
// Get the group
794-
$group = $classMapper->staticMethod('group', 'where', 'slug', $data['slug'])
794+
$group = $classMapper->getClassMapping('group')::where('slug', $data['slug'])
795795
->first();
796796

797797
return $group;

app/sprinkles/admin/src/Controller/PermissionController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getInfo(Request $request, Response $response, $args)
5252
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
5353
$classMapper = $this->ci->classMapper;
5454

55-
$permission = $classMapper->staticMethod('permission', 'find', $permissionId);
55+
$permission = $classMapper->getClassMapping('permission')::find($permissionId);
5656

5757
// If the permission doesn't exist, return 404
5858
if (!$permission) {
@@ -178,7 +178,7 @@ public function pageInfo(Request $request, Response $response, $args)
178178
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
179179
$classMapper = $this->ci->classMapper;
180180

181-
$permission = $classMapper->staticMethod('permission', 'find', $permissionId);
181+
$permission = $classMapper->getClassMapping('permission')::find($permissionId);
182182

183183
// If the permission doesn't exist, return 404
184184
if (!$permission) {

0 commit comments

Comments
 (0)