Notify   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 38
ccs 0
cts 17
cp 0
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 2
A one() 0 13 5
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace Canvas\Notifications;
6
7
use Canvas\Contracts\Auth\UserInterface;
8
use Canvas\Contracts\Notifications\NotificationInterface;
9
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...
10
use Phalcon\Di;
11
12
class Notify
13
{
14
    /**
15
     * Send the nofitication to all the users.
16
     *
17
     * @param array | ResultsetInterface $users
0 ignored issues
show
Bug introduced by
The type Canvas\Notifications\ResultsetInterface 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...
18
     * @param NotificationInterface $notification
19
     *
20
     * @return void
21
     */
22
    public static function all($users, NotificationInterface $notification)
23
    {
24
        foreach ($users as $user) {
25
            self::one($user, $notification);
26
        }
27
    }
28
29
    /**
30
     * Process just one.
31
     *
32
     * @param Users $user
33
     * @param NotificationInterface $notification
34
     *
35
     * @return void
36
     */
37
    public static function one(UserInterface $user, NotificationInterface $notification): bool
38
    {
39
        $user = !$notification->getTo() ? $user : $notification->getTo();
0 ignored issues
show
Bug introduced by
The method getTo() does not exist on Canvas\Contracts\Notific...s\NotificationInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Canvas\Contracts\Notific...s\NotificationInterface. ( Ignorable by Annotation )

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

39
        $user = !$notification->/** @scrutinizer ignore-call */ getTo() ? $user : $notification->getTo();
Loading history...
40
41
        if (Di::getDefault()->has('userData') && !$notification->getFrom()) {
0 ignored issues
show
Bug introduced by
The method getFrom() does not exist on Canvas\Contracts\Notific...s\NotificationInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Canvas\Contracts\Notific...s\NotificationInterface. ( Ignorable by Annotation )

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

41
        if (Di::getDefault()->has('userData') && !$notification->/** @scrutinizer ignore-call */ getFrom()) {
Loading history...
42
            $from = Di::getDefault()->getUserData();
43
        } else {
44
            $from = !$notification->getFrom() ? $user : $notification->getFrom();
45
        }
46
        $notification->setTo($user);
47
        $notification->setFrom($from);
48
49
        return $notification->process();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $notification->process() returns the type boolean which is incompatible with the documented return type void.
Loading history...
50
    }
51
}
52