Issues (51)

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.

DatabaseNotificationManager.php (1 issue)

Severity

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 IrishDan\NotificationBundle;
4
5
use IrishDan\NotificationBundle\Notification\DatabaseNotificationInterface;
6
use IrishDan\NotificationBundle\Notification\NotifiableInterface;
7
use Symfony\Bridge\Doctrine\ManagerRegistry;
8
use Symfony\Component\PropertyAccess\PropertyAccess;
9
use Symfony\Component\PropertyAccess\PropertyAccessor;
10
11
/**
12
 * Class DatabaseNotificationManager
13
 *
14
 * @package IrishDan\NotificationBundle
15
 */
16
class DatabaseNotificationManager
17
{
18
    /**
19
     * @var array
20
     */
21
    protected $databaseConfiguration;
22
    /**
23
     * @var ManagerRegistry
24
     */
25
    protected $managerRegistry;
26
    /**
27
     * @var PropertyAccessor
28
     */
29
    protected $propertyAccessor;
30
31
    /**
32
     * DatabaseNotificationManager constructor.
33
     *
34
     * @param ManagerRegistry $managerRegistry
35
     * @param array           $databaseConfiguration
36
     */
37
    public function __construct(ManagerRegistry $managerRegistry, array $databaseConfiguration = [])
38
    {
39
        $this->managerRegistry = $managerRegistry;
40
        $this->databaseConfiguration = $databaseConfiguration;
41
    }
42
43
    /**
44
     * @return bool|\Doctrine\Common\Persistence\ObjectManager|null|object
45
     */
46
    protected function getEntityManager()
47
    {
48
        $entity = $this->notificationEntityName();
49
        if ($entity) {
50
            return $this->managerRegistry->getManagerForClass($entity);
51
        }
52
53
        return false;
54
    }
55
56
    /**
57
     * @param array $data
58
     * @return bool
59
     */
60
    public function createDatabaseNotification(array $data)
61
    {
62
        if ($this->propertyAccessor === null) {
63
            $this->propertyAccessor = PropertyAccess::createPropertyAccessor();
64
        }
65
66
        $entityManager = $this->getEntityManager();
67
        if ($entityManager) {
68
            $entity = $this->notificationEntityName();
69
            $class = $entityManager->getRepository($entity)->getClassName();
70
            $databaseNotification = new $class();
71
72
            // Transfer values from message to databaseNotification.
73
            $properties = ['notifiable', 'uuid', 'type', 'body', 'title'];
74
            foreach ($properties as $property) {
75
                $value = $this->propertyAccessor->getValue($data, '[' . $property . ']');
76
                $this->propertyAccessor->setValue($databaseNotification, $property, $value);
77
            }
78
79
            // Save the notification to the database
80
            $entityManager->persist($databaseNotification);
81
            $entityManager->flush();
82
83
            return $databaseNotification;
84
        }
85
86
        return false;
87
    }
88
89
    /**
90
     * @param DatabaseNotificationInterface $notification
91
     * @param null                          $now
92
     * @param bool                          $flush
93
     */
94
    public function setReadAtDate(DatabaseNotificationInterface $notification, $now = null, $flush = true)
95
    {
96
        if (empty($now)) {
97
            $now = new \DateTime();
98
        }
99
100
        $notification->setReadAt($now);
101
102
        $entityManager = $this->getEntityManager();
103
        $entityManager->persist($notification);
104
        if ($flush) {
105
            $entityManager->flush();
106
        }
107
    }
108
109
    /**
110
     * @param NotifiableInterface $notifiable
111
     * @param null                $now
112
     */
113
    public function setUsersNotificationsAsRead(NotifiableInterface $notifiable, $now = null)
0 ignored issues
show
The parameter $now is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
114
    {
115
        $entity = $this->notificationEntityName();
116
        if (!empty($entity)) {
117
            $options = [
118
                'notifiable' => $notifiable,
119
                'readAt' => null,
120
            ];
121
122
            $entityManager = $this->getEntityManager();
123
            $usersNotifications = $entityManager->getRepository($entity)->findBy($options);
124
125
            if (!empty($usersNotifications)) {
126
                $this->setNotificationsReadat($usersNotifications);
127
            }
128
            $entityManager->flush();
129
        }
130
    }
131
132
    /**
133
     * @param array $notifications
134
     */
135
    public function setNotificationsReadAt(array $notifications)
136
    {
137
        $entityManager = $this->getEntityManager();
138
        foreach ($notifications as $notification) {
139
            $this->setReadAtDate($notification, null, false);
140
        }
141
142
        $entityManager->flush();
143
    }
144
145
    /**
146
     * @param DatabaseNotifiableInterface $user
147
     * @return array
148
     */
149
    public function getUsersUnreadNotifications(DatabaseNotifiableInterface $user)
150
    {
151
        $entityManager = $this->getEntityManager();
152
153
        if ($entityManager) {
154
            $entity = $this->notificationEntityName();
155
            $notifications = $entityManager->getRepository($entity)->getUnreadNotifications($user);
156
157
            return $notifications;
158
        }
159
160
        return [];
161
    }
162
163
    /**
164
     * @param NotifiableInterface $user
165
     * @param string              $status
166
     * @return int
167
     */
168
    public function getUsersNotificationCount(NotifiableInterface $user, $status = '')
169
    {
170
        $entityManager = $this->getEntityManager();
171
        if ($entityManager) {
172
            $entity = $this->notificationEntityName();
173
            $count = $entityManager->getRepository($entity)->getNotificationsCount($user, $status);
174
175
            return $count;
176
        }
177
178
        return 0;
179
    }
180
181
    /**
182
     * @param array $options
183
     * @throws \Exception
184
     */
185
    public function findAndSetAsRead(array $options)
186
    {
187
        $entityManager = $this->getEntityManager();
188
        $entity = $this->notificationEntityName();
189
        $notifications = $entityManager->getRepository($entity)->findBy($options);
190
191
        try {
192
            $this->setNotificationsReadAt($notifications);
193
        } catch (\Exception $e) {
194
            throw new \Exception(
195
                $e->getMessage()
196
            );
197
        }
198
    }
199
200
    /**
201
     * @return bool|mixed
202
     */
203
    protected function notificationEntityName()
204
    {
205
        $config = $this->databaseConfiguration;
206
        if (!empty($config['entity'])) {
207
            return $config['entity'];
208
        }
209
210
        return false;
211
    }
212
}
213