Failed Conditions
Pull Request — master (#10)
by Maximo
03:34
created

AuthController::onConstruct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
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
 * Class AuthController
14
 *
15
 * @package Gewaer\Api\Controllers
16
 *
17
 * @property Users $userData
18
 * @property Request $request
19
 * @property Config $config
20
 * @property \Phalcon\Mailer\Message $mail
21
 */
22
class AuthController extends \Baka\Auth\AuthController
23
{
24
    /**
25
     * Setup for this controller
26
     *
27
     * @return void
28
     */
29 1
    public function onConstruct()
30
    {
31 1
        $this->userLinkedSourcesModel = new UserLinkedSources();
32 1
        $this->userModel = new Users();
33
34 1
        if (!isset($this->config->jwt)) {
35
            throw new ServerErrorHttpException('You need to configure your app JWT');
36
        }
37 1
    }
38
39
    /**
40
    * Set the email config array we are going to be sending
41
    *
42
    * @param String $emailAction
43
    * @param Users  $user
44
    */
45
    protected function sendEmail(BakaUsers $user, string $type): void
46
    {
47
        $send = true;
48
49
        switch ($type) {
50
            case 'recover':
51
                $recoveryLink = $this->config->app->frontEndUrl . '/user/reset/' . $user->user_activation_forgot;
52
53
                $subject = _('Password Recovery');
54
                $body = sprintf(_('Click %shere%s to set a new password for your account.'), '<a href="' . $recoveryLink . '" target="_blank">', '</a>');
55
56
                // send email to recover password
57
            break;
58
            case 'reset':
59
                $activationUrl = $this->config->app->frontEndUrl . '/user/activate/' . $user->user_activation_key;
60
61
                $subject = _('Password Updated!');
62
                $body = sprintf(_('Your password was update please, use this link to activate your account: %sActivate account%s'), '<a href="' . $activationUrl . '">', '</a>');
63
                // send email that password was update
64
            break;
65
            default:
66
                $send = false;
67
            break;
68
        }
69
70
        if ($send) {
71
            $this->mail
72
                ->to($user->email)
73
                ->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...
74
                ->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...
75
                ->sendNow();
0 ignored issues
show
Bug introduced by
The method sendNow() does not exist on Phalcon\Mailer\Message. Did you maybe mean send()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
                ->/** @scrutinizer ignore-call */ sendNow();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
        }
77
    }
78
}
79