absences_notifyRequestApproversCls   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 14.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 11
loc 75
rs 10
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getRequest() 0 4 1
B getnextrequest() 0 25 3
A getnextfield() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/************************************************************************
3
 * OVIDENTIA http://www.ovidentia.org                                   *
4
 ************************************************************************
5
 * Copyright (c) 2003 by CANTICO ( http://www.cantico.fr )              *
6
 *                                                                      *
7
 * This file is part of Ovidentia.                                      *
8
 *                                                                      *
9
 * Ovidentia is free software; you can redistribute it and/or modify    *
10
 * it under the terms of the GNU General Public License as published by *
11
 * the Free Software Foundation; either version 2, or (at your option)  *
12
 * any later version.													*
13
 *																		*
14
 * This program is distributed in the hope that it will be useful, but  *
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of			*
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.					*
17
 * See the  GNU General Public License for more details.				*
18
 *																		*
19
 * You should have received a copy of the GNU General Public License	*
20
 * along with this program; if not, write to the Free Software			*
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,*
22
 * USA.																	*
23
************************************************************************/
24
25
26
27
28
29
30
31
32
33
34
class absences_notifyRequestApproversCls
35
{
36
	public $message;
37
	public $commenttxt;
38
	public $comment;
39
	public $title_message;
40
41
	/**
42
	 * 
43
	 * @var array
44
	 */
45
	 private $requests;
46
	
47
	/**
48
	 * 
49
	 * @var array
50
	 */
51
	private $fields;
52
53
	public function __construct(Array $requests)
54
	{
55
		$this->requests = $requests;
56
57
		$this->fromuser = absences_translate("User");
0 ignored issues
show
Bug introduced by
The property fromuser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
58
		$this->commenttxt = absences_translate("Comment");
59
		$this->t_approbation_page = absences_translate("Approbations page");
0 ignored issues
show
Bug introduced by
The property t_approbation_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
60
		$this->approburl = $GLOBALS['babUrlScript'].'?tg=approb';
0 ignored issues
show
Bug introduced by
The property approburl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
61
	}
62
	
63
	
64
	public function getRequest()
65
	{
66
		return $this->requests;
67
	}
68
	
69
	
70
	public function getnextrequest()
71
	{		
72
		if (list(,$request) = each($this->requests))
73
		{
74
			/* @var $request absences_Request */
75
			
76
			if ($request->modifiedOn() !== $request->createdOn())
77
			{
78
				$this->title_message = bab_toHtml(sprintf(absences_translate("The %s has been modified"), $request->getTitle()));
79
			}
80
			else
81
			{
82
				$this->title_message = bab_toHtml(sprintf(absences_translate("A %s is waiting to be validated"), $request->getTitle()));
83
			}
84
			
85
			$this->username = bab_toHtml(bab_getUserName($request->id_user));
0 ignored issues
show
Bug introduced by
The property username does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
86
			$this->comment = bab_toHtml($request->comment, BAB_HTML_ENTITIES | BAB_HTML_BR);
0 ignored issues
show
Bug introduced by
The property comment does not seem to exist. Did you mean comment2?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
87
			$this->fields = $request->getNotifyFields();
88
			$this->alert = $request->approbAlert();
0 ignored issues
show
Bug introduced by
The property alert does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
89
			
90
			return true;
91
		}
92
		
93
		return false;
94
	}
95
	
96
	
97 View Code Duplication
	public function getnextfield()
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...
98
	{
99
		if ($arr = each($this->fields))
100
		{
101
			$this->label = bab_toHtml($arr[0]);
0 ignored issues
show
Bug introduced by
The property label does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
102
			$this->value = bab_toHtml($arr[1]);
0 ignored issues
show
Bug introduced by
The property value does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
103
			return true;
104
		}
105
		
106
		return false;
107
	}
108
}
109
110
111
112
/**
113
 * Notifier les approbateurs
114
 * 
115
 */
116
function absences_notifyRequestApprovers()
117
{
118
	$mail = bab_mail();
119
	if( $mail == false )
120
	{
121
		return;
122
	}
123
	
124
	
125
	$list = absences_getRequestsApprovers();
126
	
127
	foreach($list as $email)
128
	{
129
	    $mail->clearTo();
130
	    
131
		foreach($email['approvers'] as $id_user)
132
		{
133
			$mail->mailTo(bab_getUserEmail($id_user), bab_getUserName($id_user));
134
		}
135
		
136
		$mail->mailFrom($GLOBALS['babAdminEmail'], $GLOBALS['babAdminName']);
137
		$mail->mailSubject(absences_translate("Vacation request is waiting to be validated", "Vacations requests are waiting to be validated", count($email['requests'])));
138
		
139
		$content = new absences_notifyRequestApproversCls($email['requests']);
140
		
141
		$message = $mail->mailTemplate(bab_printTemplate($content, absences_addon()->getRelativePath()."mailinfo.html", "newrequests"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
142
		$mail->mailBody($message, "html");
143
		
144
		$message = bab_printTemplate($content,  absences_addon()->getRelativePath()."mailinfo.html", "newrequeststxt");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
145
		$mail->mailAltBody($message);
146
		
147
		if ($mail->send())
148
		{
149
			$requests = $content->getRequest();
150
			foreach($requests as $request)
151
			{
152
				$request->setNotified();
153
			}
154
		}
155
156
	}
157
}
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
class absences_notifyRequestAuthorCls
179
{
180
	public $message;
181
	public $from;
182
	public $site;
183
	public $bview;
184
	public $by;
185
	public $reason;
186
	public $reasontxt;
187
188
	private $res;
189
190
	function __construct(absences_Request $request, $message)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
191
	{
192
		$this->message = $message;
193
		
194
		$this->reasontxt = absences_translate("Additional information");
195
		$this->reason = bab_toHtml($request->comment2, BAB_HTML_BR | BAB_HTML_ENTITIES);
196
		if( $request->status == 'N')
197
		{
198
			$this->by = absences_translate("By");
199
			$this->username = bab_getUserName($request->id_approver);
0 ignored issues
show
Bug introduced by
The property username does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
200
			$this->bview = true;
201
		}
202
		else
203
		{
204
			$this->bview = false;
205
		}
206
		
207
		$this->res = $request->getNotifyFields();
208
	}
209
	
210
	
211 View Code Duplication
	public function getnext()
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...
212
	{
213
		if ($arr = each($this->res))
214
		{
215
			$this->label = bab_toHtml($arr[0]);
0 ignored issues
show
Bug introduced by
The property label does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
216
			$this->value = bab_toHtml($arr[1]);
0 ignored issues
show
Bug introduced by
The property value does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
217
			return true;
218
		}
219
		
220
		return false;
221
	}
222
}
223
224
225
226
/**
227
 * Notify author of a request about approval
228
 * @param	array | Iterator 	$requests 	<absences_Request>
229
 * @param	string				$subject	Email subject
230
 * @param   string				$message	message content introduction for each request
231
 * @param	int					$id_user	Recipient (author)
232
 */
233
function absences_notifyRequestAuthor($requests, $subject, $message, $id_user)
0 ignored issues
show
Unused Code introduced by
The parameter $message 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...
234
{
235
	global $BAB_SESS_USER, $BAB_SESS_EMAIL, $babAdminEmail;
236
237
	$mail = bab_mail();
238
	if( $mail == false )
239
		return;
240
241
	$mail->mailTo(bab_getUserEmail($id_user), bab_getUserName($id_user));
242
243
	$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER);
244
	$mail->mailSubject($subject);
245
	
246
	$message = '';
247
	$messagetxt = '';
248
249 View Code Duplication
	foreach($requests as $request)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
250
	{
251
		$tempa = new absences_notifyRequestAuthorCls($request, $message);
252
		$message .= bab_printTemplate($tempa, absences_addon()->getRelativePath()."mailinfo.html", "infovacation");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
253
		$messagetxt .= bab_printTemplate($tempa, absences_addon()->getRelativePath()."mailinfo.html", "infovacationtxt");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
254
	}
255
	$mail->mailBody($mail->mailTemplate($message), "html");
256
	$mail->mailAltBody($messagetxt);
257
258
	$mail->send();
259
}
260
261
262
263
264
265
266
267
268
class absences_notifyEntryOwnerEmailsCls
269
{
270
	public $message;
271
	public $from;
272
	public $site;
273
	public $bview;
274
	public $by;
275
	public $reason;
276
	public $reasontxt;
277
278
	private $res;
279
280
	function __construct(absences_Entry $entry, $subject)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
281
	{
282
		$this->message = $subject;
283
284
		$this->res = $entry->getNotifyFields();
285
	}
286
287
288 View Code Duplication
	public function getnext()
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...
289
	{
290
		if ($arr = each($this->res))
291
		{
292
			$this->label = bab_toHtml($arr[0]);
0 ignored issues
show
Bug introduced by
The property label does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
293
			$this->value = bab_toHtml($arr[1]);
0 ignored issues
show
Bug introduced by
The property value does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
294
			return true;
295
		}
296
297
		return false;
298
	}
299
}
300
301
302
303
304
305
/**
306
 * 
307
 * @param Array | absences_EntryIterator $entries <absences_Entry> 
308
 * @param Array $emails <string>
309
 */
310
function absences_notifyEntryOwnerEmails($entries, Array $emails)
311
{
312
	global $babBody, $babDB, $BAB_SESS_USER, $BAB_SESS_EMAIL, $babAdminEmail;
313
	
314
	$mail = bab_mail();
315
	if( $mail == false )
316
		return;
317
	
318
	$i = 0;
319
	foreach($emails as $email)
320
	{
321
		$email = trim($email);
322
		if (!empty($email))
323
		{
324
			$mail->mailTo($email);
325
			$i++;
326
		}
327
	}
328
	
329
	if ($i === 0)
330
	{
331
		return; // no recipient
332
	}
333
	
334
	
335
	$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER);
336
	if (1 === count($entries))
337
	{
338
		$entry = reset($entries);
339
		$subject = sprintf(absences_translate("An absence has been confirmed for %s"), $entry->getUserName());
340
	} else {
341
		$subject = absences_translate("absences request set has been confirmed");
342
	}
343
	$mail->mailSubject($subject);
344
	
345
	$message = '';
346
	$messagetxt = '';
347
	foreach($entries as $entry)
348
	{
349
		$subject = sprintf(absences_translate("An absence has been confirmed for %s"), $entry->getUserName());
350
		$tempa = new absences_notifyEntryOwnerEmailsCls($entry, $subject);
351
		$message .= bab_printTemplate($tempa, absences_addon()->getRelativePath()."mailinfo.html", "vacationemails");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
352
		$messagetxt .= bab_printTemplate($tempa, absences_addon()->getRelativePath()."mailinfo.html", "vacationemailstxt");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
353
	}
354
	
355
	$mail->mailBody($mail->mailTemplate($message), "html");
356
	$mail->mailAltBody($messagetxt);
357
	
358
	$mail->send();
359
}
360