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

Invitation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 38
ccs 0
cts 19
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 17 2
A toMail() 0 5 1
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