Issues (21)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Notifynder/Traits/NotifableBasic.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Fenos\Notifynder\Traits;
4
5
use Fenos\Notifynder\Helpers\TypeChecker;
6
7
/**
8
 * Class NotifableBasic.
9
 */
10
trait NotifableBasic
11
{
12
    /**
13
     * Get the notifications Relationship without any eager loading.
14
     *
15
     * @return \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Relations\MorphMany
16
     */
17
    abstract public function getLazyNotificationRelation();
18
19
    /**
20
     * Get the notifications Relationship.
21
     *
22
     * @param array|bool $eagerLoad
23
     * @return \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Relations\MorphMany
24
     */
25
    public function getNotificationRelation($eagerLoad = null)
26
    {
27
        $with = [];
28
        if (is_null($eagerLoad)) {
29
            $eagerLoad = notifynder_config('eager_load', false);
30
        }
31
32
        if ($eagerLoad === true) {
33
            $with = ['category', 'from', 'to']; // all relations
34
        } elseif (is_array($eagerLoad)) {
35
            $with = $eagerLoad;
36
        }
37
38
        return $this->getLazyNotificationRelation()->with($with);
39
    }
40
41
    /**
42
     * Get a new NotifynderManager instance with the given category.
43
     *
44
     * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category
45
     * @return \Fenos\Notifynder\Managers\NotifynderManager
46
     */
47
    public function notifynder($category)
48
    {
49
        return app('notifynder')->category($category);
50
    }
51
52
    /**
53
     * Get a new NotifynderManager instance with the given category and $this as the sender.
54
     *
55
     * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category
56
     * @return \Fenos\Notifynder\Managers\NotifynderManager
57
     */
58
    public function sendNotificationFrom($category)
59
    {
60
        return $this->notifynder($category)->from($this);
0 ignored issues
show
Documentation Bug introduced by
The method from does not exist on object<Fenos\Notifynder\...gers\NotifynderManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
61
    }
62
63
    /**
64
     * Get a new NotifynderManager instance with the given category and $this as the receiver.
65
     *
66
     * @param string|int|\Fenos\Notifynder\Models\NotificationCategory $category
67
     * @return \Fenos\Notifynder\Managers\NotifynderManager
68
     */
69
    public function sendNotificationTo($category)
70
    {
71
        return $this->notifynder($category)->to($this);
0 ignored issues
show
Documentation Bug introduced by
The method to does not exist on object<Fenos\Notifynder\...gers\NotifynderManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
72
    }
73
74
    /**
75
     * Read a single Notification.
76
     *
77
     * @param int $notification
78
     * @return bool
79
     */
80
    public function readNotification($notification)
81
    {
82
        return $this->updateSingleReadStatus($notification, 1);
83
    }
84
85
    /**
86
     * Unread a single Notification.
87
     *
88
     * @param int $notification
89
     * @return bool
90
     */
91
    public function unreadNotification($notification)
92
    {
93
        return $this->updateSingleReadStatus($notification, 0);
94
    }
95
96
    /**
97
     * @param int $notification
98
     * @param int $value
99
     * @return bool
100
     */
101
    protected function updateSingleReadStatus($notification, $value)
102
    {
103
        if (! TypeChecker::isNotification($notification, false)) {
104
            $notification = $this->getLazyNotificationRelation()->findOrFail($notification);
105
        }
106
107
        if ($this->getLazyNotificationRelation()->where($notification->getKeyName(), $notification->getKey())->exists()) {
108
            return $value ? $notification->read() : $notification->unread();
109
        }
110
111
        return false;
112
    }
113
114
    /**
115
     * Read all Notifications.
116
     *
117
     * @return mixed
118
     */
119
    public function readAllNotifications()
120
    {
121
        return $this->getLazyNotificationRelation()->update(['read' => 1]);
122
    }
123
124
    /**
125
     * Unread all Notifications.
126
     *
127
     * @return mixed
128
     */
129
    public function unreadAllNotifications()
130
    {
131
        return $this->getLazyNotificationRelation()->update(['read' => 0]);
132
    }
133
134
    /**
135
     * Count unread notifications.
136
     *
137
     * @return int
138
     */
139
    public function countUnreadNotifications()
140
    {
141
        return $this->getLazyNotificationRelation()->byRead(0)->count();
142
    }
143
144
    /**
145
     * Get all Notifications ordered by creation and optional limit.
146
     *
147
     * @param null|int $limit
148
     * @param string $order
149
     * @return \Illuminate\Database\Eloquent\Collection
150
     */
151 View Code Duplication
    public function getNotifications($limit = null, $order = 'desc')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        $query = $this->getNotificationRelation()->orderBy('created_at', $order);
154
        if (! is_null($limit)) {
155
            $query->limit($limit);
156
        }
157
158
        return $query->get();
159
    }
160
161
    /**
162
     * Get all unread Notifications.
163
     *
164
     * @param null|int $limit
165
     * @param string $order
166
     * @return \Illuminate\Database\Eloquent\Collection
167
     */
168 View Code Duplication
    public function getNotificationsNotRead($limit = null, $order = 'desc')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
169
    {
170
        $query = $this->getNotificationRelation()->byRead(0)->orderBy('created_at', $order);
171
        if (! is_null($limit)) {
172
            $query->limit($limit);
173
        }
174
175
        return $query->get();
176
    }
177
}
178