init.php ➔ absences_upgrade()   F
last analyzed

Complexity

Conditions 28
Paths > 20000

Size

Total Lines 336
Code Lines 132

Duplication

Lines 32
Ratio 9.52 %

Importance

Changes 0
Metric Value
cc 28
eloc 132
nc 589832
nop 2
dl 32
loc 336
rs 2
c 0
b 0
f 0

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
// Ovidentia is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2, or (at your option)
7
// any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
// See the GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17
// USA.
18
//-------------------------------------------------------------------------
19
/**
20
 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
21
 * @copyright Copyright (c) 2011 by CANTICO ({@link http://www.cantico.fr})
22
 */
23
24
include_once dirname(__FILE__).'/functions.php';
25
26
27
function absences_onDeleteAddon()
28
{
29
	include_once $GLOBALS['babInstallPath'].'utilit/eventincl.php';
30
	require_once $GLOBALS['babInstallPath'].'utilit/functionalityincl.php';
31
32
	bab_removeAddonEventListeners('absences');
33
	
34
	$functionalities = new bab_functionalities();
35
	$functionalities->unregister('PortletBackend/Absences');
36
	$functionalities->unregister('AbsencesAgent');
37
	
38
	return true;
39
}
40
41
42
43
function absences_upgrade($version_base, $version_ini)
44
{
45
	global $babDB;
46
	
47
	include_once $GLOBALS['babInstallPath'].'utilit/eventincl.php';
48
	include_once $GLOBALS['babInstallPath'].'utilit/devtools.php';
49
	
50
	$addon = bab_getAddonInfosInstance('absences');
51
	
52
53
    bab_removeAddonEventListeners('absences');
54
    
55
    $addon->addEventListener('bab_eventUserDeleted'                   , 'absences_onUserDeleted'                 , 'events.php');
56
    $addon->addEventListener('bab_eventBeforeSiteMapCreated'          , 'absences_onBeforeSiteMapCreated'        , 'events.php');
57
    $addon->addEventListener('bab_eventUserModified'                  , 'absences_onUserModified'                , 'events.php');
58
    $addon->addEventListener('bab_eventBeforeWaitingItemsDisplayed'   , 'absences_onBeforeWaitingItemsDisplayed' , 'events.php');
59
    $addon->addEventListener('bab_eventConfirmMultipleWaitingItems'   , 'absences_onConfirmMultipleWaitingItems' , 'events.php');
60
    $addon->addEventListener('bab_eventPeriodModified'                , 'absences_onModifyPeriod'                , 'events.php');
61
    $addon->addEventListener('bab_eventBeforePeriodsCreated'          , 'absences_onBeforePeriodsCreated'        , 'events.php');
62
    $addon->addEventListener('LibTimer_eventHourly'                   , 'absences_onHourly'                      , 'events.php');
63
    $addon->addEventListener('bab_eventAfterEventCategoryDeleted'     , 'absences_onAfterEventCategoryDeleted'   , 'events.php');
64
    $addon->addEventListener('bab_eventOrgChartEntityAfterDeleted'    , 'absences_onOrgChartEntityAfterDeleted'  , 'events.php');
65
    $addon->addEventListener('bab_eventDirectory'                     , 'absences_onDirectory'                   , 'events.php');
66
    
67
68
	
69
	$tables = new bab_synchronizeSql(dirname(__FILE__).'/sql/dump.sql');
70
	//var_dump($tables->getDifferences());
71
	
72
	if ($tables->isCreatedTable('absences_rights') && bab_isTable('bab_vac_managers'))
73
	{
74
		include_once dirname(__FILE__).'/olddata.php';
75
		
76
		absence_copy_table('bab_vac_managers'		, ABSENCES_MANAGERS_TBL);
77
		absence_copy_table('bab_vac_types'			, ABSENCES_TYPES_TBL);
78
		absence_copy_table('bab_vac_collections'	, ABSENCES_COLLECTIONS_TBL);
79
		absence_copy_table('bab_vac_coll_types'		, ABSENCES_COLL_TYPES_TBL);
0 ignored issues
show
Deprecated Code introduced by
The constant ABSENCES_COLL_TYPES_TBL has been deprecated with message: : liaison regime/type : on laisse les anciennes donnes dans la table mais elle ne doit plus etre utilise

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

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

Loading history...
80
		absence_copy_table('bab_vac_personnel'		, ABSENCES_PERSONNEL_TBL);
81
		absence_copy_table('bab_vac_rights'			, ABSENCES_RIGHTS_TBL);
82
		absence_copy_table('bab_vac_rights_rules'	, ABSENCES_RIGHTS_RULES_TBL);
83
		absence_copy_table('bab_vac_rights_inperiod', ABSENCES_RIGHTS_INPERIOD_TBL);
84
		absence_copy_table('bab_vac_users_rights'	, ABSENCES_USERS_RIGHTS_TBL);
85
		absence_copy_table('bab_vac_entries'		, ABSENCES_ENTRIES_TBL);
86
		absence_copy_table('bab_vac_entries_elem'	, ABSENCES_ENTRIES_ELEM_TBL);
87
		absence_copy_table('bab_vac_planning'		, ABSENCES_PLANNING_TBL);
88
		absence_copy_table('bab_vac_options'		, ABSENCES_OPTIONS_TBL);
89
		absence_copy_table('bab_vac_calendar'		, ABSENCES_CALENDAR_TBL);
90
		absence_copy_table('bab_vac_rgroup'			, ABSENCES_RGROUPS_TBL);
91
		absence_copy_table('bab_vac_comanager'		, ABSENCES_COMANAGER_TBL);
92
		
93
		bab_installWindow::message(absences_translate('Import vacations data to addon... done.'));
94
	}
95
	
96
	
97
	// verifier les cles de la table absences_users_rights
98
	
99
	if (bab_isKeyExists('absences_users_rights', 'id_user'))
100
	{
101
		$babDB->db_query('ALTER TABLE absences_users_rights DROP INDEX id_user');
102
	}
103
	
104
	if (bab_isKeyExists('absences_users_rights', 'id_right'))
105
	{
106
		$babDB->db_query('ALTER TABLE absences_users_rights DROP INDEX id_right');
107
	}
108
	
109
	if (!bab_isKeyExists('absences_users_rights', 'user_right'))
110
	{
111
		bab_installWindow::message(absences_translate('Error, the program was not able to create the unique key "user_right", duplicated entries in table absences_users_rights must be removed manually before continue'));
112
		return false;
113
	}
114
115
	
116
	// fix the kind field if not set
117
	
118
	$res = $babDB->db_query("SELECT id, kind, date_begin_fixed FROM absences_rights WHERE kind='0'");
119
	while ($arr = $babDB->db_fetch_assoc($res))
120
	{
121 View Code Duplication
		if ($arr['date_begin_fixed'] !== '0000-00-00 00:00:00')
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...
122
		{
123
			$babDB->db_query("UPDATE absences_rights SET kind='2' WHERE id=".$babDB->quote($arr['id']));
124
		} else {
125
			$babDB->db_query("UPDATE absences_rights SET kind='1' WHERE id=".$babDB->quote($arr['id']));
126
		}
127
	}
128
	
129
	
130
	// mises a jour des demandes pour les droits a date fixe
131
	
132
	$res = $babDB->db_query("SELECT e.id FROM 
133
			absences_entries e, 
134
			absences_entries_elem ee, 
135
			absences_rights r
136
			WHERE 
137
				ee.id_entry=e.id 
138
				AND r.id=ee.id_right 
139
				AND r.kind='2'
140
			GROUP BY e.id 
141
	");
142
	
143
	while ($arr = $babDB->db_fetch_assoc($res))
144
	{
145
		$babDB->db_query("UPDATE absences_entries SET creation_type='1' WHERE id=".$babDB->quote($arr['id'])); 
146
	}
147
	
148
	
149
	
150
	// correction des demandes n'ayant pas de date de creation
151
	
152
	$res = $babDB->db_query("SELECT `id`, `date` FROM absences_entries WHERE createdOn='0000-00-00 00:00:00'");
153 View Code Duplication
	while ($arr = $babDB->db_fetch_assoc($res))
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...
154
	{
155
		$babDB->db_query("UPDATE absences_entries SET createdOn=".$babDB->quote($arr['date'])." WHERE id=".$babDB->quote($arr['id']));
156
	}
157
	
158
	$typescount = 0;
159
	$res = $babDB->db_query('SELECT COUNT(*) FROM '.$babDB->backTick('absences_types'));
160
	if ($arr = $babDB->db_fetch_array($res))
161
	{
162
	    $typescount = (int) $arr[0];
163
	}
164
	
165
	
166
	// default types
167
	
168 View Code Duplication
	if (0 === $typescount)
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...
169
	{
170
		bab_execSqlFile(dirname(__FILE__).'/sql/types.sql', 'UTF-8');
171
		bab_installWindow::message(absences_translate('Import vacations types... done.'));
172
	}
173
	
174
	
175
	
176
	$collectionscount = 0;
177
	$res = $babDB->db_query('SELECT COUNT(*) FROM '.$babDB->backTick('absences_collections'));
178
	if ($arr = $babDB->db_fetch_array($res))
179
	{
180
	    $collectionscount = (int) $arr[0];
181
	}
182
	
183
	// default collections
184
	
185 View Code Duplication
	if (0 === $collectionscount)
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...
186
	{
187
	    bab_execSqlFile(dirname(__FILE__).'/sql/collections.sql', 'UTF-8');
188
	    bab_installWindow::message(absences_translate('Import collections... done.'));
189
	}
190
	
191
	
192
	
193
	// considerer toutes demandes anciennes deja notifiees, ne pas toucher aux demandes du jour pour si on notifie une fois par jour
194
	
195
	$babDB->db_query("UPDATE absences_entries SET appr_notified='1' WHERE appr_notified='0' AND status='' AND createdOn<DATE_SUB(NOW(),INTERVAL 1 DAY)");
196
	
197
	
198
	
199
	// essayer de creer les liaisons droit-regimes a partir des liaisons types-regimes qui n'exisents plus dans l'application
200
	// pour cela on a les liaisons utilisateur-droit, si tout les utilisateur d'un regime sont relie a un droit alors on peut crer la liaison regime-droit
201
	// on effectue le test que si l'ancienne liaison regime-type-droit est presente
202
	
203
	if ($tables->isCreatedTable('absences_coll_rights'))
204
	{
205
	
206
		$res = $babDB->db_query('
207
			SELECT 
208
				ct.id_coll, 
209
				r.id 
210
			FROM 
211
				absences_coll_types ct,
212
				absences_rights r
213
			WHERE 
214
				r.id_type=ct.id_type 
215
				
216
		');
217
	
218
		while ($link = $babDB->db_fetch_assoc($res))
219
		{
220
			// chercher les membres du regime qui ne sont pas associes au droit
221
			$res2 = $babDB->db_query('SELECT * FROM 
222
					absences_personnel p 
223
						LEFT JOIN absences_users_rights ur ON p.id_user=ur.id_user AND ur.id_right='.$babDB->quote($link['id']).' 
224
				WHERE 
225
					p.id_coll='.$babDB->quote($link['id_coll']).'
226
					AND ur.id IS NULL 
227
			');
228
			
229 View Code Duplication
			if ($babDB->db_num_rows($res2) == 0)
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...
230
			{
231
				$babDB->db_query('INSERT INTO absences_coll_rights (id_coll, id_right) VALUES ('.$babDB->quote($link['id_coll']).','.$babDB->quote($link['id']).')');
232
			}
233
		}
234
	}
235
	
236
	
237
	
238
	
239
	if ($tables->isCreatedTable('absences_public_planning_groups')) {
240
	    // dans les version precedente, le planing public etait active par checkbox
241
	    $res = $babDB->db_query('SELECT public_calendar FROM absences_options');
242
	    if ($arr = $babDB->db_fetch_assoc($res)) {
243
	        if ($arr['public_calendar']) {
244
	            require_once $GLOBALS['babInstallPath'].'admin/acl.php';
245
	            aclSetGroups_all('absences_public_planning_groups', 1);
246
	        }
247
	    }
248
	}
249
	
250
	
251
	// add missing UUID
252
	
253
	require_once $GLOBALS['babInstallPath'].'utilit/uuid.php';
254
	$res = $babDB->db_query("SELECT id FROM absences_rights WHERE uuid=''");
255 View Code Duplication
	while ($arr = $babDB->db_fetch_assoc($res))
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...
256
	{
257
		$babDB->db_query('UPDATE absences_rights SET uuid='.$babDB->quote(bab_uuid()).' WHERE id='.$babDB->quote($arr['id']));
258
	}
259
	
260
	$res = $babDB->db_query("SELECT id FROM absences_rights_inperiod WHERE uuid=''");
261 View Code Duplication
	while ($arr = $babDB->db_fetch_assoc($res))
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...
262
	{
263
		$babDB->db_query('UPDATE absences_rights_inperiod SET uuid='.$babDB->quote(bab_uuid()).' WHERE id='.$babDB->quote($arr['id']));
264
	}
265
	
266
	
267
	// reprise des gestionnaires en tant que groupe avec ACL, faire la reprise si la table absences_options contient des lignes
268
	
269
	$res = $babDB->db_query("SELECT * FROM absences_managers");
270
	if ($babDB->db_num_rows($res) > 0)
271
	{
272
		require_once $GLOBALS['babInstallPath'].'admin/acl.php';
273
		
274
		$users = aclGetAccessUsers('absences_managers_groups', 1);
275
		if (0 === count($users))
276
		{
277
			$groupname = absences_translate('Vacations managers');
278
			$i = 1;
279
			
280
			$rootgroups = bab_getGroups(BAB_REGISTERED_GROUP, false);
281
			$names = array_flip($rootgroups['name']);
282
			
283
			while(isset($names[$groupname])) {
284
				$groupname .= ' '.$i;
285
				$i++;
286
			}
287
	
288
			$id_group = bab_createGroup($groupname, absences_translate('Created automatically while upgrading to the new absences addon'), 0);
289
			
290
			while ($arr = $babDB->db_fetch_assoc($res))
291
			{
292
				bab_addUserToGroup($arr['id_user'], $id_group);
293
			}
294
			
295
			
296
			aclAdd('absences_managers_groups', $id_group, 1);
297
			
298
			$babDB->db_query('TRUNCATE absences_managers');
299
		}
300
	}
301
	
302
	
303
	// selection de l'organigramme par defaut
304
	require_once $GLOBALS['babInstallPath'].'utilit/ocapi.php';
305
	if ($idprimaryoc = bab_OCgetPrimaryOcId())
306
	{
307
		$babDB->db_query('UPDATE absences_options SET id_chart='.$babDB->quote($idprimaryoc)." WHERE id_chart='0'");
308
	}
309
	
310
	
311
	
312
	// reprise des dates lors de l'ajout des dates dans la table absences_entries_elem
313
	require_once dirname(__FILE__).'/upgrade/entry_elem.php';
314
	absences_upgradeEntryElemDates::onUpgrade();
315
	
316
	
317
	$addon = bab_getAddonInfosInstance('absences');
318
	bab_functionality::includefile('PortletBackend');
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 includefile() 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...
319
320
    if (class_exists('Func_PortletBackend')) {
321
       $addon->registerFunctionality('PortletBackend/Absences', 'portletbackend.class.php');
322
    }
323
    $addon->registerFunctionality('AbsencesAgent', 'utilit/agent.api.php');
324
    $addon->registerFunctionality('AbsencesRequest', 'utilit/request.api.php');
325
326
327
	
328
	
329
	
330
	// T8341 Reprise des droits de recuperation creer avec une date de fin= a la date de debut
331
	
332
	$babDB->db_query("UPDATE absences_rights_inperiod SET period_end=DATE_ADD(period_end,INTERVAL 1 YEAR) 
333
	    WHERE period_start = period_end AND id_right IN(
334
	       SELECT id FROM absences_rights WHERE kind='16')");
335
	$babDB->db_query("UPDATE absences_rights SET date_end=DATE_ADD(date_end,INTERVAL 1 YEAR) 
336
	    WHERE kind='16' AND date_begin=date_end");
337
	
338
	
339
	// reprise des declaration de jours travaille approuvees par auto-approbation sans droit cree
340
	// avant la version 2.67 id_right n'existait pas
341
	// Utiliser ce code seulement si il y a des droit a recuperation manquant, il peut etre dangereux si le format du nom du droit change
342
	// la method restoreMissingRight cree le droit manquant ou cree la liaison manquante
343
	
344
	/*
345
	$res = $babDB->db_query("SELECT * FROM absences_workperiod_recover_request WHERE id_right='0' AND status='Y' AND modifiedOn>'2015-05-30 00:00:00'");
346
	require_once dirname(__FILE__).'/utilit/workperiod_recover_request.class.php';
347
	while ($arr = $babDB->db_fetch_assoc($res)) {
348
	    $request = new absences_WorkperiodRecoverRequest();
349
	    $request->setRow($arr);
350
	    $request->restoreMissingRight();
351
	}
352
	*/
353
	
354
	
355
	
356
	
357
	$babDB->db_query("UPDATE absences_cet_deposit_request SET firstconfirm='1' WHERE status='Y'");
358
	$babDB->db_query("UPDATE absences_workperiod_recover_request SET firstconfirm='1' WHERE status='Y'");
359
	$babDB->db_query("UPDATE absences_entries SET firstconfirm='1' WHERE status='Y'");
360
	
361
	
362
	// T9250 Export des soldes a une date donnee
363
	
364
	$babDB->db_query("UPDATE absences_rights SET createdOn=date_entry WHERE createdOn='0000-00-00 00:00:00'");
365
	
366
	
367
	
368
	// verification de l'historique des status
369
	
370
	absences_fixRequestLastMovement('absences_entries', 'absences_Entry');
371
	absences_fixRequestLastMovement('absences_workperiod_recover_request', 'absences_WorkperiodRecoverRequest');
372
	absences_fixRequestLastMovement('absences_cet_deposit_request', 'absences_CetDepositRequest');
373
	
374
	absences_deleteAgentsWithNoUser();
375
	absence_rePrimary();
376
	
377
	return true;
378
}
379