PushNotification   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Notifications;
6
7
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...
8
9
class PushNotification
10
{
11
    /**
12
     * @var string
13
     */
14
    public $title;
15
16
    /**
17
     * @var string
18
     */
19
    public $message;
20
21
    /**
22
     * User Object
23
     * 
24
     * @var Users
25
     */
26
    public $to;
27
28
    /**
29
     * Additional params if needed
30
     *
31
     * @var array
32
     */
33
    public $params;
34
35
    /**
36
     * Init a push notification object
37
     *
38
     * @param Users $user
39
     * @param string $title
40
     * @param string $message
41
     * @param array $params
42
     * 
43
     * @return void
44
     */
45
    public function __construct(Users $user, string $title, string $message, ?array $params = null)
46
    {
47
        $this->to = $user;
48
        $this->title = $title;
49
        $this->message = $message;
50
        $this->params = $params;
51
    }
52
}
53