Test Failed
Pull Request — master (#9)
by Maximo
03:26
created

AuthController::sendEmail()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 6
nop 2
dl 0
loc 31
ccs 0
cts 21
cp 0
crap 20
rs 9.584
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Api\Controllers;
6
7
use Gewaer\Models\Users;
8
use Baka\Auth\Models\Users as BakaUsers;
9
use Gewaer\Models\UserLinkedSources;
10
use Gewaer\Exception\ServerErrorHttpException;
11
12
/**
13
 * Base controller
14
 *
15
 */
16
class AuthController extends \Baka\Auth\AuthController
17
{
18
    /**
19
     * Setup for this controller
20
     *
21
     * @return void
22
     */
23 1
    public function onConstruct()
24
    {
25 1
        $this->userLinkedSourcesModel = new UserLinkedSources();
26 1
        $this->userModel = new Users();
27
28 1
        if (!isset($this->config->jwt)) {
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist on Gewaer\Api\Controllers\AuthController. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
            throw new ServerErrorHttpException('You need to configure your app JWT');
30
        }
31 1
    }
32
33
    /**
34
    * Set the email config array we are going to be sending
35
    *
36
    * @param String $emailAction
37
    * @param Users  $user
38
    */
39
    protected function sendEmail(BakaUsers $user, string $type): void
40
    {
41
        $send = true;
42
43
        switch ($type) {
44
            case 'recover':
45
                $recoveryLink = $this->config->app->frontEndUrl . '/user/reset/' . $user->user_activation_forgot;
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist on Gewaer\Api\Controllers\AuthController. Since you implemented __get, consider adding a @property annotation.
Loading history...
46
47
                $subject = _('Password Recovery');
48
                $body = sprintf(_('Click %shere%s to set a new password for your account.'), '<a href="' . $recoveryLink . '" target="_blank">', '</a>');
49
50
                // send email to recover password
51
            break;
52
            case 'reset':
53
                $activationUrl = $this->config->app->frontEndUrl . '/user/activate/' . $user->user_activation_key;
54
55
                $subject = _('Password Updated!');
56
                $body = sprintf(_('Your password was update please, use this link to activate your account: %sActivate account%s'), '<a href="' . $activationUrl . '">', '</a>');
57
                // send email that password was update
58
            break;
59
            default:
60
                $send = false;
61
            break;
62
        }
63
64
        if ($send) {
65
            $this->mail
0 ignored issues
show
Bug Best Practice introduced by
The property mail does not exist on Gewaer\Api\Controllers\AuthController. Since you implemented __get, consider adding a @property annotation.
Loading history...
66
                ->to($user->email)
67
                ->subject($subject)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $subject does not seem to be defined for all execution paths leading up to this point.
Loading history...
68
                ->content($body)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $body does not seem to be defined for all execution paths leading up to this point.
Loading history...
69
                ->sendNow();
70
        }
71
    }
72
}
73