Issues (118)

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.

Messaging/Manager/ThreadStatusManager.php (2 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
/*
4
 * This file is part of the MilioooMessageBundle package.
5
 *
6
 * (c) Michiel boeckaert <[email protected]>
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Miliooo\Messaging\Manager;
12
13
use Miliooo\Messaging\User\ParticipantInterface;
14
use Miliooo\Messaging\Model\ThreadInterface;
15
use Miliooo\Messaging\Repository\ThreadRepositoryInterface;
16
use Miliooo\Messaging\ValueObjects\ThreadStatus;
17
use Miliooo\Messaging\Repository\MessageRepositoryInterface;
18
use Miliooo\Messaging\Model\ThreadMetaInterface;
19
use Miliooo\Messaging\Model\MessageMetaInterface;
20
use Miliooo\Messaging\ValueObjects\ReadStatus;
21
22
/**
23
 * ThreadStatusManager.
24
 *
25
 * The thread status manager is responsible for updating the thread status and persisting the updated thread to
26
 * the storage engine.
27
 *
28
 * @author Michiel Boeckaert <[email protected]>
29
 */
30
class ThreadStatusManager implements ThreadStatusManagerInterface
31
{
32
    /**
33
     * A thread repository instance.
34
     *
35
     * @var ThreadRepositoryInterface
36
     */
37
    private $threadRepository;
38
39
    /**
40
     * A message repository instance.
41
     *
42
     * @var MessageRepositoryInterface
43
     */
44
    private $messageRepository;
45
46
    /**
47
     * A read status manager instance.
48
     *
49
     * @var ReadStatusManagerInterface
50
     */
51
    private $readStatusManager;
52
53
    /**
54
     * @param ThreadRepositoryInterface  $threadRepository  A thread repository
55
     * @param MessageRepositoryInterface $messageRepository A message repository
56
     * @param ReadStatusManagerInterface $readStatusManager A read status manager
57
     */
58
    public function __construct(
59
        ThreadRepositoryInterface $threadRepository,
60
        MessageRepositoryInterface $messageRepository,
61
        ReadStatusManagerInterface $readStatusManager
62
    ) {
63
        $this->threadRepository = $threadRepository;
64
        $this->messageRepository = $messageRepository;
65
        $this->readStatusManager = $readStatusManager;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function updateThreadStatusForParticipant(
72
        ThreadStatus $newThreadStatus,
73
        ThreadInterface $thread,
74
        ParticipantInterface $participant
75
    ) {
76
        $threadMeta = $thread->getThreadMetaForParticipant($participant);
77
78
        //get the integer value of the thread status.
79
        $newThreadStatusInt = $newThreadStatus->getThreadStatus();
80
        $oldThreadStatusInt = $threadMeta->getStatus();
81
82
83
        //if no thread meta can happen if the current user is not participant of the thread
84
        if (!$threadMeta || $oldThreadStatusInt === $newThreadStatusInt) {
85
            return false;
86
        }
87
88
        //updates the status
89
        $threadMeta->setStatus($newThreadStatusInt);
90
91
        //saves the thread
92
        $this->threadRepository->save($thread);
93
94
        //create a value object from the old status integer
95
        $oldThreadStatus = new ThreadStatus($oldThreadStatusInt);
96
        $this->maybeMarkMessagesAsRead($thread, $participant, $oldThreadStatus, $newThreadStatus);
97
98
        return true;
99
    }
100
101
    /**
102
     * When archiving an active thread we want to mark all unread messages as read.
103
     *
104
     * Since this is a thread status update we do this here. We do use the read status manager for this should also
105
     * dispatch a new read status event.
106
     *
107
     * @param ThreadInterface      $thread          The current thread
108
     * @param ParticipantInterface $participant     The participant who wants to update the thread status
109
     * @param ThreadStatus         $oldThreadStatus The integer value of the old thread status
110
     * @param ThreadStatus         $newThreadStatus The integer value of the new thread status
111
     *
112
     * @return boolean false if no messages where marked as read, true if there were messages marked as read
113
     */
114
    protected function maybeMarkMessagesAsRead(
115
        ThreadInterface $thread,
116
        ParticipantInterface $participant,
117
        ThreadStatus $oldThreadStatus,
118
        ThreadStatus $newThreadStatus
119
    ) {
120
        if (!$this->updateActiveThreadToArchivedThread($oldThreadStatus, $newThreadStatus)) {
121
            return false;
122
        }
123
124
        //get the messages...
125
        $messages = $this->messageRepository->getUnreadMessagesFromThreadForParticipant($participant, $thread);
126
        // return if not array (should never happen) or if empty messages()
127
        if (!is_array($messages) || empty($messages)) {
128
            return false;
129
        }
130
131
        $readStatus = new ReadStatus(MessageMetaInterface::READ_STATUS_READ);
132
        $this->readStatusManager->updateReadStatusForMessageCollection($readStatus, $participant, $messages);
133
134
        return true;
135
    }
136
137
    /**
138
     * Checks whether we are updating the thread status from an active to an archived thread
139
     *
140
     * @param ThreadStatus $oldThreadStatus
141
     * @param ThreadStatus $newThreadStatus
142
     *
143
     * @return boolean true if we are updating an active thread to an archived thread false otherwise
144
     */
145
    protected function updateActiveThreadToArchivedThread(ThreadStatus $oldThreadStatus, ThreadStatus $newThreadStatus)
0 ignored issues
show
function updateActiveThreadToArchivedThread() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
146
    {
147
        if ($oldThreadStatus->getThreadStatus() !== ThreadMetaInterface::STATUS_ACTIVE
0 ignored issues
show
This if statement, and the following return statement can be replaced with return !($oldThreadStatu...face::STATUS_ARCHIVED);.
Loading history...
148
            ||
149
            $newThreadStatus->getThreadStatus() !== ThreadMetaInterface::STATUS_ARCHIVED
150
        ) {
151
            return false;
152
        }
153
154
        return true;
155
    }
156
}
157