Invitation::toMail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Notifications;
6
7
use Canvas\Contracts\Notifications\NotificationInterface;
8
use Baka\Mail\Message;
0 ignored issues
show
Bug introduced by
The type Baka\Mail\Message was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Phalcon\Di;
10
use Canvas\Models\Users;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Canvas\Notifications\Users. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
12
class Invitation extends Notification implements NotificationInterface
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->getDefaultCompany()->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