Skip to content

Commit ce16f7f

Browse files
committed
Refactoring
1 parent 1f2715f commit ce16f7f

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

src/UserVerification.php

+8-34
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function __construct(Mailer $mailer, Builder $schema)
4747
{
4848
$this->mailer = $mailer;
4949
$this->schema = $schema;
50+
51+
if (! $this->isCompliant()) {
52+
throw new ModelNotCompliantException();
53+
}
5054
}
5155

5256
/**
@@ -85,10 +89,6 @@ protected function generateToken()
8589
*/
8690
protected function saveToken(AuthenticatableContract $user, $token)
8791
{
88-
if (! $this->isCompliant($user)) {
89-
throw new ModelNotCompliantException();
90-
}
91-
9292
$user->verified = false;
9393

9494
$user->verification_token = $token;
@@ -114,10 +114,6 @@ public function send(
114114
$name = null
115115
)
116116
{
117-
if (! $this->isCompliant($user)) {
118-
throw new ModelNotCompliantException();
119-
}
120-
121117
$this->emailVerificationLink($user, $subject, $from, $name);
122118

123119
event(new VerificationEmailSent($user));
@@ -141,10 +137,6 @@ public function sendQueue(
141137
$name = null
142138
)
143139
{
144-
if (! $this->isCompliant($user)) {
145-
throw new ModelNotCompliantException();
146-
}
147-
148140
$this->emailQueueVerificationLink($user, $subject, $from, $name);
149141

150142
event(new VerificationEmailSent($user));
@@ -170,10 +162,6 @@ public function sendLater(
170162
$name = null
171163
)
172164
{
173-
if (! $this->isCompliant($user)) {
174-
throw new ModelNotCompliantException();
175-
}
176-
177165
$this->emailLaterVerificationLink($delay, $user, $subject, $from, $name);
178166

179167
event(new VerificationEmailSent($user));
@@ -259,7 +247,7 @@ public function process($email, $token, $userTable)
259247
unset($user->{"password"});
260248

261249
// Check if the given user is already verified.
262-
// If he is, we stop here.
250+
// If it is, we stop here.
263251
$this->isVerified($user);
264252

265253
$this->verifyToken($user->verification_token, $token);
@@ -361,26 +349,12 @@ protected function updateUser($user)
361349
* Determine if the given model table has the verified and verification_token
362350
* columns.
363351
*
364-
* @param \Illuminate\Contracts\Auth\Authenticatable $user
365352
* @return bool
366353
*/
367-
protected function isCompliant(AuthenticatableContract $user)
354+
protected function isCompliant()
368355
{
369-
return $this->hasColumn($user, 'verified')
370-
&& $this->hasColumn($user, 'verification_token')
371-
? true
372-
: false;
373-
}
356+
$user = config('auth.providers.users.model', App\User::class);
374357

375-
/**
376-
* Check if the given model talbe has the given column.
377-
*
378-
* @param \Illuminate\Contracts\Auth\Authenticatable $user
379-
* @param string $column
380-
* @return bool
381-
*/
382-
protected function hasColumn(AuthenticatableContract $user, $column)
383-
{
384-
return $this->schema->hasColumn($user->getTable(), $column);
358+
return $this->schema->hasColumns((new $user())->getTable(), ['verified', 'verification_token'])? true : false;
385359
}
386360
}

0 commit comments

Comments
 (0)