Passed
Push — master ( e83663...5c40cf )
by Anthony
02:41
created

Messagerie::getMessageNonLu()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
1
<?php
2
	namespace modules\messagerie\app\controller;
3
4
	use core\App;
5
	use core\functions\ChaineCaractere;
6
7
	class Messagerie {
8
		public static $url_message;
9
10
		private $id_message;
11
		private $objet;
12
		private $message;
13
		private $date_message;
14
		private $url;
15
16
		private $id_expediteur;
17
		private $pseudo_expediteur;
18
19
		private $pseudo_receveur;
20
		private $id_receveur;
21
22
		private $values = [];
23
		
24
		
25
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
26
		/**
27
		 * @param null $type_boite
28
		 * initialisation de la récupération des messages des différents boites
29
		 */
30
		public function __construct($type_boite = null) {
31
			if ($type_boite !== null) {
32
				if ($type_boite == "boite réception") {
33
					$this->getBoiteReception();
34
				}
35
				else if ($type_boite == "messages envoyés") {
36
					$this->getMessagesEnvoyes();
37
				}
38
				else if ($type_boite == "messages supprimés") {
39
					$this->getMessageSupprimes();
40
				}
41
			}
42
		}
43
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
44
		
45
		
46
		
47
		//-------------------------- GETTER ----------------------------------------------------------------------------//
48
		public function getIdMessage() {
49
			return $this->id_message;
50
		}
51
		public function getObjet() {
52
			return $this->objet;
53
		}
54
		public function getMessage() {
55
			return $this->message;
56
		}
57
		public function getDateMessage(){
58
		    return $this->date_message;
59
		}
60
		public function getUrl(){
61
		    return $this->url;
62
		}
63
		public function getIdExpediteur() {
64
			return $this->id_expediteur;
65
		}
66
		public function getPseudoExpediteur() {
67
			return $this->pseudo_expediteur;
68
		}
69
		public function getIdReceveur() {
70
			return $this->id_receveur;
71
		}
72
		public function getPseudoReceveur() {
73
			return $this->pseudo_receveur;
74
		}
75
		public function getValues(){
76
		    return ["messagerie" => $this->values];
77
		}
78
79
		/**
80
		 * fonction qui permet de récupérer tous les messages dans la boite de récéption
81
		 */
82 View Code Duplication
		private function getBoiteReception() {
0 ignored issues
show
Duplication introduced by
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...
Coding Style introduced by
getBoiteReception uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
83
			$dbc = App::getDb();
84
85
			$query = $dbc->select()
86
				->from("_messagerie_boite_reception")
87
				->from("_messagerie_message")
88
				->from("identite")
89
				->where("_messagerie_boite_reception.ID_identite", "=", $_SESSION['idlogin'.CLEF_SITE], "AND")
90
				->where("_messagerie_boite_reception.supprimer", " IS ", "NULL", "AND", true)
91
				->where("_messagerie_boite_reception.ID_message", "=", "_messagerie_message.ID_message", "AND", true)
92
				->where("_messagerie_message.ID_expediteur", "=", "identite.ID_identite", "", true)
93
				->get();
94
95
			if ((is_array($query)) && (count($query) > 0)) {
96
				foreach ($query as $obj) {
97
					$arr = [
98
						"id_message" => $obj->ID_message,
99
						"objet" => $obj->objet,
100
						"date_message" => $obj->date,
101
						"id_expediteur" => $obj->ID_expediteur,
102
						"pseudo_expediteur" => $obj->pseudo,
103
						"url" => $obj->url
104
					];
105
					
106
					$values[] = $arr;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
107
				}
108
				
109
				$this->setValues($values);
0 ignored issues
show
Bug introduced by
The variable $values does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
110
			}
111
		}
112
113
		/**
114
		 * fonction qui permet de récupérer tous les messages dans la boite des messages envoyes
115
		 */
116
		private function getMessagesEnvoyes() {
0 ignored issues
show
Coding Style introduced by
getMessagesEnvoyes uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
117
			$dbc = App::getDb();
118
119
			$query = $dbc->select()
120
				->from("_messagerie_boite_reception")
121
				->from("_messagerie_message")
122
				->from("identite")
123
				->where("_messagerie_message.ID_expediteur", "=", $_SESSION['idlogin'.CLEF_SITE], "AND")
124
				->where("_messagerie_boite_reception.ID_message", "=", "_messagerie_message.ID_message", "AND", true)
125
				->where("_messagerie_boite_reception.ID_identite", "=", "identite.ID_identite", "", true)
126
				->get();
127
128
			if ((is_array($query)) && (count($query) > 0)) {
129
				foreach ($query as $obj) {
130
					$arr = [
131
						"id_message" => $obj->ID_message,
132
						"objet" => $obj->objet,
133
						"date_message" => $obj->date,
134
						"id_expediteur" => $obj->ID_expediteur,
135
						"pseudo_receveur" => $obj->pseudo,
136
						"url" => $obj->url
137
					];
138
139
					$values[] = $arr;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
140
				}
141
				
142
				$this->setValues($values);
0 ignored issues
show
Bug introduced by
The variable $values does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
143
			}
144
		}
145
146
		/**
147
		 * fonction qui récupère tous les messages supprimés
148
		 */
149 View Code Duplication
		private function getMessageSupprimes() {
0 ignored issues
show
Duplication introduced by
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...
Coding Style introduced by
getMessageSupprimes uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
150
			$dbc = App::getDb();
151
152
			$query = $dbc->select()
153
				->from("_messagerie_boite_reception")
154
				->from("_messagerie_message")
155
				->from("identite")
156
				->where("_messagerie_boite_reception.ID_identite", "=", $_SESSION['idlogin'.CLEF_SITE], "AND")
157
				->where("_messagerie_boite_reception.supprimer", "=", 1, "AND")
158
				->where("_messagerie_boite_reception.ID_message", "=", "_messagerie_message.ID_message", "AND", true)
159
				->where("_messagerie_message.ID_expediteur", "=", "identite.ID_identite", "", true)
160
				->get();
161
162
			if ((is_array($query)) && (count($query) > 0)) {
163
				foreach ($query as $obj) {
164
					$arr = [
165
						"id_message" => $obj->ID_message,
166
						"objet" => $obj->objet,
167
						"date_message" => $obj->date,
168
						"id_expediteur" => $obj->ID_expediteur,
169
						"pseudo_expediteur" => $obj->pseudo,
170
						"url" => $obj->url
171
					];
172
173
					$values[] = $arr;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
174
				}
175
				
176
				$this->setValues($values);
0 ignored issues
show
Bug introduced by
The variable $values does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
177
			}
178
		}
179
180
		/*
181
		 * fonction qui permetlors de l'envoit d'un message d'être sur que le membre existe
182
		 */
183
		private function getIdIdentiteExist($pseudo) {
184
			$dbc = App::getDb();
185
186
			$pseudo = trim($pseudo);
187
188
			$query = $dbc->select("ID_identite")->from("identite")->where("pseudo", "=", $pseudo)->get();
189
190
			if ((count($query) == 1) && (is_array($query))) {
191
				foreach ($query as $obj) {
192
					return $obj->ID_identite;
193
				}
194
			}
195
196
			return false;
197
		}
198
		
199
		/**
200
		 * fonction qui sert à récupérer les messages non lus
201
		 */
202
		public function getMessageNonLu() {
0 ignored issues
show
Coding Style introduced by
getMessageNonLu uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
203
			$dbc = App::getDb();
204
			
205
			$query = $dbc->select("ID_message")
206
				->from("_messagerie_boite_reception")
207
				->where("ID_identite", "=", $_SESSION['idlogin'.CLEF_SITE], "AND")
208
				->where("lu", " IS NULL ", "", "OR", true)
209
				->where("lu", "=", 0, "", true)
210
				->get();
211
			
212
			$count = count($query);
213
			
214
			if ($count > 0) {
215
				$this->setValues(["messages_non_lu" => count($query)]);
216
			}
217
		}
218
219
		/**
220
		 * @param $url_message
221
		 * fonction qui récupère un message suivant une url
222
		 */
223
		public function getUnMessage($url_message) {
224
			$dbc = App::getDb();
225
226
			$query = $dbc->select()
227
				->from("_messagerie_message")
228
				->from("_messagerie_boite_reception")
229
				->from("identite")
230
				->where("_messagerie_message.url", "=", $url_message, "AND")
231
				->where("_messagerie_message.ID_expediteur", "=", "identite.ID_identite", "AND", true)
232
				->where("_messagerie_boite_reception.ID_message", "=", "_messagerie_message.ID_message", "", true)
233
				->get();
234
235
			if ((is_array($query)) && (count($query) > 0)) {
236
				foreach ($query as $obj) {
237
					$this->setValues([
238
						"id_message" => $obj->ID_message,
239
						"objet" => $obj->objet,
240
						"message" => $obj->message,
241
						"date_message" => $obj->date,
242
						"id_expediteur" => $obj->ID_expediteur,
243
						"pseudo_expediteur" => $obj->pseudo,
244
						"url" => $obj->url,
245
						"supprimer" => $obj->supprimer
246
					]);
247
					
248
					$this->setLireMessage($obj->ID_message);
249
				}
250
			}
251
			else {
252
				return false;
253
			}
254
		}
255
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
256
		
257
		
258
		
259
		//-------------------------- SETTER ----------------------------------------------------------------------------//
260
		/**
261
		 * @param $values
262
		 * can set values while keep older infos
263
		 */
264
		public function setValues($values) {
265
			$this->values = array_merge($this->values, $values);
266
		}
267
		
268
		/**
269
		 * @param $id_message
270
		 * fonction qui passe un message en lu un fois qu'il a été ouvert
271
		 */
272
		private function setLireMessage($id_message) {
0 ignored issues
show
Coding Style introduced by
setLireMessage uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
273
			$dbc = App::getDb();
274
			
275
			$dbc->update("lu", 1)
276
				->from("_messagerie_boite_reception")
277
				->where("ID_message", "=", $id_message, "AND")
278
				->where("ID_identite", "=", $_SESSION['idlogin'.CLEF_SITE])
279
				->set();
280
		}
281
		
282
		/**
283
		 * @param $id_message
284
		 * pour passer le message en supprimé, il sera alors consultable dans la table messages supprimés
285
		 */
286 View Code Duplication
		public function setArchiverMessage($id_message) {
0 ignored issues
show
Duplication introduced by
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...
287
			$dbc = App::getDb();
288
289
			$dbc->update("supprimer", 1)->from("_messagerie_boite_reception")
290
				->where("ID_message", "=", $id_message, "AND")
291
				->where("ID_identite", "=", 1)
292
				->set();
293
		}
294
295
		/**
296
		 * @param $id_message
297
		 */
298 View Code Duplication
		public function setSupprimerMessage($id_message) {
0 ignored issues
show
Duplication introduced by
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...
Coding Style introduced by
setSupprimerMessage uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
299
			$dbc = App::getDb();
300
301
			$dbc->delete()->from("_messagerie_boite_reception")
302
				->where("ID_message", "=", $id_message, "AND")
303
				->where("ID_identite", "=", $_SESSION['idlongin'])
304
				->del();
305
		}
306
307
		/**
308
		 * @param $objet
309
		 * @param $destinataire
310
		 * @param $message
311
		 * @return bool
312
		 *
313
		 * fonction qui sert à envoyer un message à un ou plusieurs destinataires
314
		 */
315
		public function setEnvoyerMessage($objet, $destinataire, $message) {
0 ignored issues
show
Coding Style introduced by
setEnvoyerMessage uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
316
			$dbc = App::getDb();
317
318
			//on test si un ou plusieurs destinataires ++ si ils existent
319
			if (ChaineCaractere::FindInString($destinataire, ",")) {
320
				$destinataires = explode(",", $destinataire);
321
				$c = count($destinataires);
322
323
				for ($i=0 ; $i<$c ; $i++) {
324
					if ($this->getIdIdentiteExist($destinataires[$i]) !== false) {
325
						$destinataires[] = $this->getIdIdentiteExist($destinataires[$i]);
326
						$expediteur = $_SESSION['idlogin'.CLEF_SITE];
327
					}
328
					else {
329
						return false;
330
					}
331
				}
332
			}
333
			else {
334
				if ($this->getIdIdentiteExist($destinataire) !== false) {
335
					$destinataires[] = $this->getIdIdentiteExist($destinataire);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$destinataires was never initialized. Although not strictly required by PHP, it is generally a good practice to add $destinataires = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
336
					$expediteur = $_SESSION['idlogin'.CLEF_SITE];
337
				}
338
				else if (is_numeric($destinataire)) {
339
					$destinataires[] = $destinataire;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$destinataires was never initialized. Although not strictly required by PHP, it is generally a good practice to add $destinataires = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
340
					$expediteur = 1;
341
				}
342
				else {
343
					return false;
344
				}
345
			}
346
347
			//cela veut dire qu'on a au moin 1 membre à qui envoyer le message
348
			if (count($destinataires) > 0) {
349
				$dbc->insert("message", $message)
350
					->insert("objet", $objet)
351
					->insert("url", ChaineCaractere::setUrl($objet))
352
					->insert("date", date("Y-m-d H:i:s"))
353
					->insert("ID_expediteur", $expediteur)
0 ignored issues
show
Bug introduced by
The variable $expediteur does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
354
					->into("_messagerie_message")
355
					->set();
356
357
				$id_message = $dbc->lastInsertId();
358
359
				foreach ($destinataires as $destinataire) {
360
					$dbc->insert("ID_identite", $destinataire)
361
						->insert("ID_message", $id_message)
362
						->into("_messagerie_boite_reception")
363
						->set();
364
				}
365
366
				return true;
367
			}
368
369
			return false;
370
		}
371
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
372
	}