Test Failed
Branch add-core-tests (a060d8)
by Rafael
05:48
created

Invitation::message()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 9
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 17
ccs 0
cts 13
cp 0
crap 6
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Notifications;
6
7
use Canvas\Contracts\Notifications\NotificationInterfase;
8
use Baka\Mail\Message;
9
use Phalcon\Di;
10
use Canvas\Models\Users;
11
12
class Invitation extends Notification implements NotificationInterfase
13
{
14
    //protected $useQueue = true;
15
16
    /**
17
     * Notification msg.
18
     *
19
     * @return string
20
     */
21
    public function message(): string
22
    {
23
        $app = Di::getDefault()->getApp();
24
25
        $userExists = Users::findFirst([
26
            'conditions' => 'email = ?0 and is_deleted = 0',
27
            'bind' => [$this->entity->email]
28
        ]);
29
30
        $invitationUrl = $app->url . '/users/invites/' . $this->entity->invite_hash;
31
32
        if (is_object($userExists)) {
33
            $invitationUrl = $app->url . '/users/link/' . $this->entity->invite_hash;
34
        }
35
36
        return "Hi {$this->entity->email} you have been invite to the app {$app->name} to create you account please <a href='{$invitationUrl}'>click here</a> <br /><br />
37
                Thanks {$this->fromUser->firstname} {$this->fromUser->lastname} ( {$this->fromUser->currentCompany->name} ) ";
38
    }
39
40
    /**
41
     * Email body.
42
     *
43
     * @return Message|null
44
     */
45
    public function toMail(): ?Message
46
    {
47
        return $this->mail->to($this->toUser->getEmail())
48
            ->subject('You have been invited!')
49
            ->content($this->message());
50
    }
51
}
52