absences_CetDepositRequestIterator::executeQuery()   F
last analyzed

Complexity

Conditions 18
Paths 8193

Size

Total Lines 81
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 43
CRAP Score 24.4627

Importance

Changes 0
Metric Value
cc 18
eloc 32
nc 8193
nop 0
dl 0
loc 81
rs 2.1162
c 0
b 0
f 0
ccs 43
cts 59
cp 0.7288
crap 24.4627

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
require_once dirname(__FILE__).'/request.class.php';
26
27
28
29
/**
30
 * CET deposit request
31
 * 
32
 * @property	int 	$id_user
33
 * @property 	int		$id_agent_right_cet
34
 * @property 	int		$id_agent_right_source
35
 * @property 	float	$quantity
36
 * @property 	int		$idfai
37
 * @property 	string	$comment
38
 * @property 	string	$createdOn
39
 * @property 	string	$modifiedOn
40
 * @property 	string	$status
41
 * @property 	int		$id_approver
42
 * @property	int		$archived
43
 * 
44
 */
45
class absences_CetDepositRequest extends absences_Request
46
{
47
	/**
48
	 * 
49
	 * @var absences_AgentRight
50
	 */
51
	private $agentRightSource;
52
	
53
	/**
54
	 *
55
	 * @var absences_AgentRight
56
	 */
57
	private $agentRightCet;
58
	
59
	
60
	/**
61
	 * @param int $id
62
	 * @return absences_CetDepositRequest
63
	 */
64
	public static function getById($id)
65
	{
66
		$request = new absences_CetDepositRequest();
67
		$request->id = $id;
68
	
69
		return $request;
70
	}
71
72
	
73
	
74
	/**
75
	 *
76
	 * @return array
77
	 */
78 5 View Code Duplication
	public function getRow()
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...
79
	{
80 5
		if (null === $this->row)
81 5
		{
82
			global $babDB;
83
			$query = 'SELECT * FROM absences_cet_deposit_request WHERE ';
84
	
85
			if (isset($this->id))
86
			{
87
				$query .= 'id='.$babDB->quote($this->id);
88
			}
89
	
90
			$res = $babDB->db_query($query);
91
			$this->setRow($babDB->db_fetch_assoc($res));
92
		}
93
	
94 5
		return $this->row;
95
	}
96
	
97
	
98
	
99
	
100
	
101
	/**
102
	 * @return absences_AgentRight
103
	 */
104
	public function getAgentRightSource()
105
	{
106
		if (!isset($this->agentRightSource))
107
		{
108
			require_once dirname(__FILE__).'/agent_right.class.php';
109
			$this->agentRightSource = absences_AgentRight::getById($this->id_agent_right_source);
110
		}
111
		
112
		return $this->agentRightSource;
113
	}
114
	
115
	
116
	
117
	/**
118
	 * @return absences_AgentRight
119
	 */
120
	public function getAgentRightCet()
121
	{
122
		if (!isset($this->agentRightCet))
123
		{
124
			require_once dirname(__FILE__).'/agent_right.class.php';
125
			$this->agentRightCet = absences_AgentRight::getById($this->id_agent_right_cet);
126
		}
127
	
128
		return $this->agentRightCet;
129
	}
130
	
131
	
132
	/**
133
	 * (non-PHPdoc)
134
	 * @see absences_Request::getRequestType()
135
	 * 
136
	 * @return string
137
	 */
138
	public function getRequestType()
139
	{
140
		return absences_translate('Time saving account deposit');
141
	}
142
	
143
	
144 5
	public function save()
145
	{
146 5
		global $babDB;
147
		
148 5
		if (!isset($this->createdOn)) {
149
		    $this->createdOn = date('Y-m-d H:i:s');
150
		}
151
		
152 5
		if (!isset($this->modifiedOn)) {
153 5
		    $this->modifiedOn = date('Y-m-d H:i:s');
154 5
		}
155
		
156
		
157 5
		if (isset($this->id) && !empty($this->id))
158 5
		{
159
		    $query = '
160
				UPDATE absences_cet_deposit_request	 
161
					SET 
162 2
						id_agent_right_source='.$babDB->quote($this->id_agent_right_source).',
163 2
						quantity='.$babDB->quote($this->quantity).',
164 2
						modifiedOn='.$babDB->quote($this->modifiedOn).',
165 2
						idfai='.$babDB->quote($this->idfai).',
166 2
						status='.$babDB->quote($this->status).',
167 2
						quantity='.$babDB->quote($this->quantity).',
168 2
						comment='.$babDB->quote($this->comment).',
169 2
						comment2='.$babDB->quote($this->comment2).',
170 2
						id_approver='.$babDB->quote($this->id_approver).' 
171 2
			';
172
		    
173 2
		    if (isset($this->todelete)) {
174
		        $query .= ', todelete='.$babDB->quote($this->todelete);
175
		    }
176
		    
177
		    $query .= ' WHERE 
178 2
					id='.$babDB->quote($this->id).' ';
179
		    
180 2
			$babDB->db_query($query);
181 2
		} else {
182
		
183
		
184 5
			$babDB->db_query('INSERT INTO 
185
				absences_cet_deposit_request 
186
					(
187
						id_user, 
188
						id_agent_right_cet, 
189
						id_agent_right_source, 
190
						quantity,
191
						comment,
192
						createdOn,
193
						modifiedOn,
194
						idfai,
195
						status
196
					) 
197
				VALUES 
198
					(
199 5
						'.$babDB->quote($this->id_user).',
200 5
						'.$babDB->quote($this->id_agent_right_cet).',
201 5
						'.$babDB->quote($this->id_agent_right_source).',
202 5
						'.$babDB->quote($this->quantity).',
203 5
						'.$babDB->quote($this->comment).',
204 5
						'.$babDB->quote($this->createdOn).',
205 5
						'.$babDB->quote($this->modifiedOn).',
206 5
						'.$babDB->quote($this->idfai).',
207 5
						'.$babDB->quote($this->status).'
208
					)
209 5
			');
210
			
211 5
			$this->id = $babDB->db_insert_id();
212
		
213
		}
214 5
	}
215
	
216
	
217
	
218
	
219
	/**
220
	 * (non-PHPdoc)
221
	 * @see absences_Request::getApprobationId()
222
	 * 
223
	 * @return int
224
	 */
225
	public function getApprobationId()
226
	{
227
		if ($agent = $this->getAgent())
228
		{
229
			return $agent->getCetApprobationId();
230
		}
231
	
232
		return null;
233
	}
234
	
235
	/**
236
	 * Process specific code when the request is rejected
237
	 *
238
	 */
239
	protected function onReject()
240
	{
241
	
242
	}
243
	
244
	/**
245
	 * Process specific code when the request is confirmed
246
	 *
247
	 */
248
	public function onConfirm()
249
	{
250
		// the quantity in source right is removed dynamically
251
		
252
		$source = $this->getAgentRightSource()->getRight();
253
		$cet = $this->getAgentRightCet()->getRight();
254
		
255
		
256
		
257
		// add quantity to the CET
258
		
259
		$agentCet = $this->getAgentRightCet();
260
		
261
		if (!$agentCet->getRow())
262
		{
263
			bab_debug('No agentRight found, agent deleted?');
264
			return;
265
		}
266
		
267
		
268
		$agentCet->quantity += $this->quantity;
269
		$agentCet->save();
270
		
271
		$qte_text = absences_quantity($this->quantity, $source->quantity_unit);
272
		
273
		// ajout d'un message dans l'historique de chaque droit et dans l'historique de l'utilisateur
274
		
275
		$source->addMovement(sprintf(absences_translate('%s has saved %s to his time saving account'), $this->getAgent()->getName(), $qte_text));
276
		$cet->addMovement(sprintf(absences_translate('The time saving account of %s has received %s'), $this->getAgent()->getName(), $qte_text));
277
		$this->addMovement(sprintf(absences_translate('%s of right "%s" saved to "%s"'), $qte_text, $source->description, $cet->description));
278
	}
279
	
280
	
281
	public function getTitle()
282
	{
283
	    if (isset($this->todelete) && $this->todelete) {
284
	        return absences_translate('time saving account deposit request to delete');
285
	    }
286
	    
287
		return absences_translate('time saving account deposit request');
288
	}
289
	
290
	
291
	public function getNotifyFields()
292
	{
293
		$source = $this->getAgentRightSource()->getRight();
294
		
295
		if (!$source->getRow())
296
		{
297
			return array();
298
		}
299
		
300
		return array(
301
				absences_translate('From right')	=> $source->description,
302
				absences_translate('Quantity') 		=> absences_quantity($this->quantity, $source->quantity_unit)
303
		);
304
	}
305
	
306
	
307
	/**
308
	 * (non-PHPdoc)
309
	 * @see absences_Request::getYear()
310
	 * 
311
	 * @return int
312
	 */
313
	public function getYear()
314
	{
315
		$year = (int) substr($this->createdOn, 0, 4);
316
	
317
		if (0 === $year)
318
		{
319
			return null;
320
		}
321
	
322
		return $year;
323
	}
324
	
325
	
326 View Code Duplication
	public function getArchiveYear()
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...
327
	{
328
		require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
329
		$year = (int) substr($this->createdOn, 0, 4);
330
		
331
		if (0 === $year)
332
		{
333
			return null;
334
		}
335
		
336
		$day = absences_getVacationOption('archivage_day');
337
		$month = absences_getVacationOption('archivage_month');
338
		
339
		$currentYear = new BAB_DateTime($year, $month, $day);
340
		if($this->createdOn < $currentYear->getIsoDate()){
341
			$year = $year-1;
342
		}
343
		
344
		return $year;
345
	}
346
	
347
	
348
	
349 View Code Duplication
	public function archive()
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...
350
	{
351
		global $babDB;
352
	
353
		$babDB->db_query("
354
			UPDATE absences_cet_deposit_request 
355
			SET 
356
				archived=".$babDB->quote(1)."
357
			WHERE 
358
				id=".$babDB->quote($this->id)."
359
		");
360
	}
361
	
362
	
363
	
364 View Code Duplication
	public function setNotified()
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...
365
	{
366
		global $babDB;
367
	
368
		$babDB->db_query("
369
			UPDATE absences_cet_deposit_request
370
			SET 
371
				appr_notified=".$babDB->quote(1)."
372
			WHERE 
373
				id=".$babDB->quote($this->id)."
374
		");
375
	}
376
	
377
	
378
	public function getManagerEditUrl()
379
	{
380
		$addon = bab_getAddonInfosInstance('absences');
381
		return $addon->getUrl().'vacadmcet&idx=edit&id='.$this->id;
382
	}
383
	
384
	public function getManagerDeleteUrl()
385
	{
386
		$addon = bab_getAddonInfosInstance('absences');
387
		return $addon->getUrl().'vacadmcet&idx=delete&id='.$this->id;
388
	}
389
	
390
	
391
	
392
	/**
393
	 * @return string
394
	 */
395 View Code Duplication
	public function getEditUrl($rfrom, $ide = null)
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...
396
	{
397
		$url = absences_addon()->getUrl()."vacuser&idx=cet&id=".$this->id;
398
	
399
		if (isset($rfrom))
400
		{
401
			$url .= '&rfrom='.$rfrom;
402
		}
403
	
404
		if (isset($ide))
405
		{
406
			$url .= '&ide='.$ide;
407
		}
408
	
409
		return $url;
410
	}
411
	
412
	
413
	public function getManagerFrame()
414
	{
415
		$W = bab_Widgets();
416
417
		return $W->Link($W->Icon(absences_translate('Deposit on the time saving account'), Func_Icons::MIMETYPES_UNKNOWN), absences_addon()->getUrl()."vacadmcet&idx=edit&id=".$this->id );
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $W->Link($W->Icon...edit&id=' . $this->id); (Widget_Link) is incompatible with the return type declared by the abstract method absences_Request::getManagerFrame of type Widget_Frame.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
418
	}
419
	
420
	
421
	
422
	/**
423
	 * Get request card frame to display in requests list
424
	 * @param bool 			$display_username	Affiche le nom du demandeur dans la card frame ou non, utile pour les listes contenant plusieurs demandeurs possibles
425
	 * @param int			$rfrom				si les demandes de la liste sont modifiee par un gestionnaire ou gestionnaire delegue
426
 	 * @param int			$ide				id entite de l'organigramme >0 si gestionnaire delegue seulement
427
	 * @return Widget_Frame
428
	 */
429
	public function getCardFrame($display_username, $rfrom, $ide)
430
	{
431
		bab_functionality::includeOriginal('Icons');
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class bab_functionality as the method includeOriginal() does only exist in the following sub-classes of bab_functionality: Func_Archive, Func_Archive_Zip, Func_Archive_Zip_ZipArchive, Func_Archive_Zip_Zlib, Func_CalendarBackend, Func_CalendarBackend_Ovi, Func_ContextActions, Func_ContextActions_Article, Func_ContextActions_ArticleTopic, Func_Home, Func_Home_Ovidentia, Func_Icons, Func_Icons_Default, Func_Ovml, Func_Ovml_Container, Func_Ovml_Container_Addon, Func_Ovml_Container_Article, Func_Ovml_Container_ArticleCategories, Func_Ovml_Container_ArticleCategory, Func_Ovml_Container_ArticleCategoryNext, Func_Ovml_Container_ArticleCategoryPrevious, Func_Ovml_Container_ArticleFiles, Func_Ovml_Container_ArticleNext, Func_Ovml_Container_ArticlePrevious, Func_Ovml_Container_ArticleTopic, Func_Ovml_Container_ArticleTopicNext, Func_Ovml_Container_ArticleTopicPrevious, Func_Ovml_Container_ArticleTopics, Func_Ovml_Container_Articles, Func_Ovml_Container_ArticlesHomePages, Func_Ovml_Container_CalendarCategories, Func_Ovml_Container_CalendarEventDomains, Func_Ovml_Container_CalendarEvents, Func_Ovml_Container_CalendarGroupEvents, Func_Ovml_Container_CalendarResourceEvents, Func_Ovml_Container_CalendarUserEvents, Func_Ovml_Container_Calendars, Func_Ovml_Container_DbDirectories, Func_Ovml_Container_DbDirectory, Func_Ovml_Container_DbDirectoryAcl, Func_Ovml_Container_DbDirectoryEntry, Func_Ovml_Container_DbDirectoryEntryFields, Func_Ovml_Container_DbDirectoryFields, Func_Ovml_Container_DbDirectoryMemberFields, Func_Ovml_Container_DbDirectoryMembers, Func_Ovml_Container_Delegation, Func_Ovml_Container_DelegationAdministrators, Func_Ovml_Container_DelegationItems, Func_Ovml_Container_DelegationManaged, Func_Ovml_Container_Delegations, Func_Ovml_Container_DelegationsCategories, Func_Ovml_Container_DelegationsCategory, Func_Ovml_Container_DelegationsManaged, Func_Ovml_Container_Faq, Func_Ovml_Container_FaqNext, Func_Ovml_Container_FaqPrevious, Func_Ovml_Container_FaqQuestion, Func_Ovml_Container_FaqQuestionNext, Func_Ovml_Container_FaqQuestionPrevious, Func_Ovml_Container_FaqQuestions, Func_Ovml_Container_FaqSubCategories, Func_Ovml_Container_FaqSubCategory, Func_Ovml_Container_Faqs, Func_Ovml_Container_File, Func_Ovml_Container_FileFields, Func_Ovml_Container_FileNext, Func_Ovml_Container_FilePrevious, Func_Ovml_Container_Files, Func_Ovml_Container_Folder, Func_Ovml_Container_FolderNext, Func_Ovml_Container_FolderPrevious, Func_Ovml_Container_Folders, Func_Ovml_Container_Forum, Func_Ovml_Container_ForumNext, Func_Ovml_Container_ForumPrevious, Func_Ovml_Container_Forums, Func_Ovml_Container_IfEqual, Func_Ovml_Container_IfGreaterThan, Func_Ovml_Container_IfGreaterThanOrEqual, Func_Ovml_Container_IfIsSet, Func_Ovml_Container_IfLessThan, Func_Ovml_Container_IfLessThanOrEqual, Func_Ovml_Container_IfNotEqual, Func_Ovml_Container_IfNotIsSet, Func_Ovml_Container_IfUserMemberOfGroups, Func_Ovml_Container_Multipages, Func_Ovml_Container_ObjectsInfo, Func_Ovml_Container_OrgPathToEntity, Func_Ovml_Container_OrgUserEntities, Func_Ovml_Container_OvmlArray, Func_Ovml_Container_OvmlArrayFields, Func_Ovml_Container_OvmlSoap, Func_Ovml_Container_ParentsArticleCategory, Func_Ovml_Container_Post, Func_Ovml_Container_PostFiles, Func_Ovml_Container_RecentArticles, Func_Ovml_Container_RecentComments, Func_Ovml_Container_RecentFaqQuestions, Func_Ovml_Container_RecentFiles, Func_Ovml_Container_RecentPosts, Func_Ovml_Container_RecentThreads, Func_Ovml_Container_SitemapCustomNode, Func_Ovml_Container_SitemapEntries, Func_Ovml_Container_SitemapEntry, Func_Ovml_Container_SitemapPath, Func_Ovml_Container_Soap, Func_Ovml_Container_SubFolders, Func_Ovml_Container_Tags, Func_Ovml_Container_Thread, Func_Ovml_Container_TmProjects, Func_Ovml_Container_TmSpaces, Func_Ovml_Container_TmTaskFields, Func_Ovml_Container_TmTasks, Func_Ovml_Container_WaitingArticles, Func_Ovml_Container_WaitingComments, Func_Ovml_Container_WaitingFiles, Func_Ovml_Container_WaitingPosts, Func_Ovml_Function, Func_Ovml_Function_AOAddition, Func_Ovml_Function_AODivision, Func_Ovml_Function_AOModulus, Func_Ovml_Function_AOMultiplication, Func_Ovml_Function_AOSubtraction, Func_Ovml_Function_AddStyleSheet, Func_Ovml_Function_Addon, Func_Ovml_Function_Ajax, Func_Ovml_Function_ArticleTree, Func_Ovml_Function_CurrentNode, Func_Ovml_Function_FileTree, Func_Ovml_Function_Get, Func_Ovml_Function_GetCookie, Func_Ovml_Function_GetCsrfProtectToken, Func_Ovml_Function_GetCurrentAdmGroup, Func_Ovml_Function_GetLanguage, Func_Ovml_Function_GetPageTitle, Func_Ovml_Function_GetPath, Func_Ovml_Function_GetSelectedSkinPath, Func_Ovml_Function_GetSessionVar, Func_Ovml_Function_GetVar, Func_Ovml_Function_Header, Func_Ovml_Function_IfNotIsSet, Func_Ovml_Function_Include, Func_Ovml_Function_NextArticle, Func_Ovml_Function_Post, Func_Ovml_Function_PreviousArticle, Func_Ovml_Function_PreviousOrNextArticle, Func_Ovml_Function_PutArray, Func_Ovml_Function_PutSoapArray, Func_Ovml_Function_PutVar, Func_Ovml_Function_Recurse, Func_Ovml_Function_Request, Func_Ovml_Function_SetCookie, Func_Ovml_Function_SetSessionVar, Func_Ovml_Function_SitemapCustomNodeId, Func_Ovml_Function_SitemapMenu, Func_Ovml_Function_SitemapPosition, Func_Ovml_Function_SitemapUrl, Func_Ovml_Function_Translate, Func_Ovml_Function_UrlContent, Func_Ovml_Function_WebStat, Func_PortalAuthentication, Func_PortalAuthentication_AuthOvidentia, Func_PwdComplexity, Func_PwdComplexity_DefaultPortal, Func_SearchUi, Func_SitemapDynamicNode, Func_SitemapDynamicNode_Topic, Func_UserEditor, Func_WorkingHours, Func_WorkingHours_Ovidentia, Ovml_Container_Sitemap, bab_ArithmeticOperator, bab_Ovml_Container_Operator, bab_rgp. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
432
		$W = bab_Widgets();
433
		
434
		
435
		$layout = $W->HBoxLayout()->setHorizontalSpacing(2,'em')->addClass('widget-full-width');
436
		$frame = $W->Frame(null, $layout);
437
		$frame->addClass(Func_Icons::ICON_LEFT_16);
438
		
439
		if (!$this->getRow())
440
		{
441
			return $frame;
442
		}
443
	
444
		$layout->addItem($col1 = $W->VBoxLayout()->setVerticalSpacing(.5,'em'));
445
		$layout->addItem($col2 = $W->VBoxLayout()->setVerticalSpacing(.5,'em'));
446
		$layout->addItem($col3 = $W->VBoxLayout()->setVerticalSpacing(.5,'em'));
447
		
448
		$col1->addItem($W->Link($W->Icon(absences_translate('Deposit on the time saving account'), Func_Icons::MIMETYPES_UNKNOWN), absences_addon()->getUrl()."vacuser&idx=view_cet_deposit&id=".$this->id ));
449
		$col1->setCanvasOptions($col1->Options()->width(25,'em'));
0 ignored issues
show
Bug introduced by
It seems like $col1->Options()->width(25, 'em') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
450
		$col2->setCanvasOptions($col1->Options()->width(25,'em'));
0 ignored issues
show
Bug introduced by
It seems like $col1->Options()->width(25, 'em') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
451
		$layout->addItem($col3 = $W->VBoxLayout()->setVerticalSpacing(.5,'em'));
452
		$col2->setSizePolicy(Widget_SizePolicy::MAXIMUM);
453
		
454
		$col1->addItem($this->getStatusIcon());
455
		
456
		
457
		
458
		if ($display_username)
459
		{
460
			$col2->addItem($this->labelledValue(absences_translate('Owner'), $this->getUserName()));
461
		}
462
		
463
		$source = $this->getAgentRightSource()->getRight();
464
		
465
		if ($source && $source->getRow())
466
		{
467
			$col2->addItem($this->labelledValue(absences_translate('From right'), $source->description));
468
			$col2->addItem($this->labelledValue(absences_translate('Quantity'), absences_quantity($this->quantity, $source->quantity_unit)));
469
		} else {
470
			$col2->addItem($this->labelledValue(absences_translate('Quantity'), $this->quantity));
471
		}
472
		
473
		
474 View Code Duplication
		if ($this->canModify())
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...
475
		{
476
			$col3->addItem($W->Link($W->Icon(absences_translate('Modify'), Func_Icons::ACTIONS_DOCUMENT_EDIT), $this->getEditUrl($rfrom, $ide)));
477
		}
478
		
479
		if ($this->canDelete())
480
		{
481
			$urldelete = absences_addon()->getUrl()."vacuser&idx=delete&id_cetdeposit=".$this->id;
482
			$col3->addItem($W->Link($W->Icon(absences_translate('Delete'), Func_Icons::ACTIONS_EDIT_DELETE), $urldelete));
483
		}
484
485
		$frame->setTitle(sprintf(absences_translate('Created the %s'), bab_shortDate(bab_mktime($this->createdOn()))));
486
	
487
		return $frame;
488
	}
489
	
490
	
491
	
492
	/**
493
	 * Delete request
494
	 */
495
	public function delete()
496
	{
497
498
		parent::delete();
499
		
500
		global $babDB;
501
		$babDB->db_query("delete from absences_cet_deposit_request where id=".$babDB->quote($this->id));
502
		
503
		$this->addMovement(
504
		    absences_translate('The time saving account deposit request has been deleted')
505
		);
506
	}
507
	
508
	
509
	/**
510
	 * Notify request owner about the approval or reject of the request
511
	 */
512
	public function notifyOwner()
513
	{
514
		require_once dirname(__FILE__).'/request.notify.php';
515
	
516
		switch($this->status)
517
		{
518
			case 'N':
519
				$subject = absences_translate("Your time saving account deposit request has been refused");
520
				break;
521
	
522
			case 'Y':
523
				$subject = absences_translate("Your time saving account deposit request has been accepted");
524
				break;
525
				
526
			default:
527
				return;
528
		}
529
		
530
		absences_notifyRequestAuthor(array($this), $subject, $subject, $this->id_user);
531
	}
532
}
533
534
535
536
537
538
539
540
/**
541
 * Vacation requests
542
 *
543
 */
544
class absences_CetDepositRequestIterator extends absences_Iterator
545
{
546
547
	/**
548
	 *
549
	 * @var array
550
	 */
551
	public $users;
552
	
553
	
554
	/**
555
	 * Filter by organization
556
	 * @var int
557
	 */
558
	public $organization;
559
	
560
	
561
	/**
562
	 * Filtrer les demandes necessitant ou pas un email aux approbateurs
563
	 * @var int
564
	 */
565
	public $appr_notified;
566
	
567
	
568
	/**
569
	 * Filtrer les demandes avec unes instance d'approbation
570
	 * @var bool
571
	 */
572
	public $idfai_set;
573
	
574
	/**
575
	 * 
576
	 * @var string
577
	 */
578
	public $status;
579
	
580
	/**
581
	 * Search all request created before this datetime
582
	 * @var string
583
	 */
584
	public $createdOn;
585
	
586
	
587
	/**
588
	 * Search all request modified before this date
589
	 * @var string
590
	 */
591
	public $modifiedOn;
592
	
593
	
594
	/**
595
	 * Filtrer les demandes par annee
596
	 * @var int
597
	 */
598
	public $year;
599
	
600
	
601
	/**
602
	 * Filtrer les demandes par statut d'archivage
603
	 * @var int
604
	 */
605
	public $archived = 0;
606
	
607
	
608
	/**
609
	 * @var int
610
	 */
611
	public $id_agent_right_source;
612
613
614 4
	public function getObject($data)
615
	{
616
617 4
		$entry = new absences_CetDepositRequest;
618 4
		$entry->setRow($data);
619 4
		return $entry;
620
621
	}
622
623
624
625 21
	public function executeQuery()
626
	{
627 21
		if(is_null($this->_oResult))
628 21
		{
629 21
			global $babDB;
630
			$req = 'SELECT r.*
631
			FROM 
632
				absences_cet_deposit_request r 
633
			         LEFT JOIN absences_personnel p ON p.id_user=r.id_user 
634 21
			';
635
636
637 21
			$where = array();
638
639 21
			if (isset($this->users))
640 21
			{
641 21
				$where[] = 'r.id_user IN('.$babDB->quote($this->users).')';
642 21
			}
643
			
644 21
			if (isset($this->organization))
645 21
			{
646
			    $where[] = 'p.id_organization='.$babDB->quote($this->organization);
647
			}
648
			
649 21
			if (isset($this->appr_notified))
650 21
			{
651
				$where[] = 'r.appr_notified='.$babDB->quote($this->appr_notified);
652
			}
653
			
654 21
			if (isset($this->idfai_set) && $this->idfai_set)
655 21
			{
656
				$where[] = 'r.idfai>'.$babDB->quote(0);
657
			}
658
659 21
			if (isset($this->status))
660 21
			{
661 7
				$where[] = 'r.status='.$babDB->quote($this->status);
662 7
			}
663
			
664 21
			if (isset($this->createdOn))
665 21
			{
666 15
				$where[] = 'r.createdOn<='.$babDB->quote($this->createdOn);
667 15
			}
668
			
669 21
			if (isset($this->modifiedOn))
670 21
			{
671
				$where[] = 'r.modifiedOn<='.$babDB->quote($this->modifiedOn);
672
			}
673
			
674 21
			if (isset($this->year))
675 21
			{
676
				$where[] = 'YEAR(r.createdOn)='.$babDB->quote($this->year);
677
			}
678
			
679 21
			if (isset($this->startTo) && $this->startTo != '0000-00-00')
680 21
			{
681
				$where[] = 'r.createdOn <='.$babDB->quote($this->startTo);
0 ignored issues
show
Bug introduced by
The property startTo 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...
682
			}
683
			
684 21
			if (isset($this->startFrom) && $this->startFrom != '0000-00-00')
685 21
			{
686
				$where[] = 'r.createdOn >='.$babDB->quote($this->startFrom);
0 ignored issues
show
Bug introduced by
The property startFrom 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...
687
			}
688
			
689 21
			if (isset($this->archived))
690 21
			{
691
				$where[] = 'r.archived='.$babDB->quote($this->archived);
692
			}
693
			
694 21
			if (isset($this->id_agent_right_source)) {
695 21
			    $where[] = 'r.id_agent_right_source='.$babDB->quote($this->id_agent_right_source);
696 21
			}
697
			
698
			if ($where)
0 ignored issues
show
Bug Best Practice introduced by
The expression $where of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
699 21
			{
700 21
				$req .= ' WHERE '.implode(' AND ', $where);
701 21
			}
702
			
703 21
			$this->setMySqlResult($this->getDataBaseAdapter()->db_query($req));
704 21
		}
705 21
	}
706
}
707