absences_ManagerMenu::getFrame()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.4285
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) 2006 by CANTICO ({@link http://www.cantico.fr})
22
 */
23
24
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...
25
26
27
class absences_ManagerMenu
28
{
29
	protected function category($name)
30
	{
31
		$W = bab_Widgets();
32
33
		return $W->Section(
34
				$name,
35
				$W->VBoxItems()
36
				->setHorizontalSpacing(6, 'px')->setVerticalSpacing(1, 'em')
37
		)
38
		->setFoldable(false);
39
	}
40
41
	protected function category_settings()
42
	{
43
		$W = bab_Widgets();
44
		$cat = $this->category(absences_translate('Settings'));
45
46
		$cat->addItem(
47
			$W->Link(
48
				$W->Icon(absences_translate("Vacations types"), Func_Icons::ACTIONS_VIEW_LIST_TEXT),
49
				absences_addon()->getUrl()."vacadm&idx=lvt"
50
			)
51
		);
52
53
54
		$cat->addItem(
55
				$W->Link(
56
						$W->Icon(absences_translate("Collections"), Func_Icons::ACTIONS_VIEW_LIST_TEXT),
57
						absences_addon()->getUrl()."vacadm&idx=lcol"
58
				)
59
		);
60
61
62
		$cat->addItem(
63
				$W->Link(
64
						$W->Icon(absences_translate("Personnel members"), Func_Icons::ACTIONS_USER_GROUP_PROPERTIES),
65
						absences_addon()->getUrl()."vacadm&idx=lper"
66
				)
67
		);
68
69
70
		$cat->addItem(
71
				$W->Link(
72
						$W->Icon(absences_translate("Workdays types entitling recovery"), Func_Icons::APPS_PREFERENCES_DATE_TIME_FORMAT),
73
						absences_addon()->getUrl()."workperiod_type"
74
				)
75
		);
76
77
78 View Code Duplication
		if (absences_getVacationOption('sync_server'))
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...
79
		{
80
			$cat->addItem(
81
					$W->Link(
82
							$W->Icon(absences_translate("Configure the shared vacation rights"), Func_Icons::APPS_PREFERENCES_WEBSERVICES),
83
							absences_addon()->getUrl()."sync_server"
84
					)
85
			);
86
		}
87
88 View Code Duplication
		if (absences_getVacationOption('sync_url'))
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...
89
		{
90
			$cat->addItem(
91
					$W->Link(
92
							$W->Icon(absences_translate("Configure the synchronized rights"), Func_Icons::APPS_PREFERENCES_WEBSERVICES),
93
							absences_addon()->getUrl()."sync_client"
94
					)
95
			);
96
		}
97
98
99
		$WorkingHours = bab_functionality::get('WorkingHours');
100
		if ($WorkingHours instanceof Func_WorkingHours_Workschedules)
0 ignored issues
show
Bug introduced by
The class Func_WorkingHours_Workschedules does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
101
		{
102
			$cat->addItem(
103
					$W->Link(
104
							$W->Icon(absences_translate("Configure the works schedules"), Func_Icons::APPS_PREFERENCES_CALENDAR),
105
							$WorkingHours->getProfileListUrl()
106
					)
107
			);
108
		}
109
110
111
		
112
		$cat->addItem(
113
				$W->Link(
114
						$W->Icon(absences_translate("Plannings"), Func_Icons::APPS_CALENDAR),
115
						absences_addon()->getUrl()."planning&idx=list"
116
				)
117
		);
118
		
119
120
121
122
	    $cat->addItem(
123
	        $W->Link(
124
	            $W->Icon(absences_translate("Organizations"), Func_Icons::APPS_GROUPS),
125
	            absences_addon()->getUrl()."organizations"
126
	        )
127
	    );
128
129
130
		return $cat;
131
	}
132
133
134 View Code Duplication
	protected function category_rights()
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...
135
	{
136
		$W = bab_Widgets();
137
		$cat = $this->category(absences_translate('Vacation rights'));
138
139
		$cat->addItem(
140
				$W->Link(
141
						$W->Icon(absences_translate("Vacations rights"), Func_Icons::APPS_VACATIONS),
142
						absences_addon()->getUrl()."vacadma&idx=lrig"
143
				)
144
		);
145
146
		$cat->addItem(
147
				$W->Link(
148
						$W->Icon(absences_translate("Rights groups"), Func_Icons::ACTIONS_LIST_ADD),
149
						absences_addon()->getUrl()."vacadma&idx=rgroup"
150
				)
151
		);
152
153
		$cat->addItem(
154
				$W->Link(
155
						$W->Icon(absences_translate("Rights renewal by years"), Func_Icons::ACTIONS_VIEW_CALENDAR_TIMELINE),
156
						absences_addon()->getUrl()."vacadma&idx=copy"
157
				)
158
		);
159
160
161
		$cat->addItem(
162
				$W->Link(
163
						$W->Icon(absences_translate("Archive rights"), Func_Icons::ACTIONS_ARCHIVE_CREATE),
164
						absences_addon()->getUrl()."archive&idx=right"
165
				)
166
		);
167
168
169
		$cat->addItem(
170
				$W->Link(
171
						$W->Icon(absences_translate("Sort rights"), Func_Icons::ACTIONS_ARROW_DOWN_DOUBLE),
172
						absences_addon()->getUrl()."sort&idx=right"
173
				)
174
		);
175
176
		return $cat;
177
	}
178
179 View Code Duplication
	protected function category_requests()
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...
180
	{
181
		$W = bab_Widgets();
182
		$cat = $this->category(absences_translate('Users requests'));
183
184
		$cat->addItem(
185
				$W->Link(
186
						$W->Icon(absences_translate("Vacations requests"), Func_Icons::ACTIONS_VIEW_LIST_DETAILS),
187
						absences_addon()->getUrl()."vacadmb&idx=lreq"
188
				)
189
		);
190
191
		$cat->addItem(
192
				$W->Link(
193
						$W->Icon(absences_translate("Waiting requests"), Func_Icons::APPS_APPROBATIONS),
194
						absences_addon()->getUrl()."waiting"
195
				)
196
		);
197
198
		$cat->addItem(
199
				$W->Link(
200
						$W->Icon(absences_translate("Working days entitling recovery"), Func_Icons::ACTIONS_VIEW_CALENDAR_WORKWEEK),
201
						absences_addon()->getUrl()."vacadmwd"
202
				)
203
		);
204
205
		$cat->addItem(
206
				$W->Link(
207
						$W->Icon(absences_translate("Time saving accounts deposits"), Func_Icons::ACTIONS_VIEW_HISTORY),
208
						absences_addon()->getUrl()."vacadmcet"
209
				)
210
		);
211
212
		$cat->addItem(
213
				$W->Link(
214
						$W->Icon(absences_translate("Archive requests"), Func_Icons::ACTIONS_ARCHIVE_CREATE),
215
						absences_addon()->getUrl()."archive&idx=request"
216
				)
217
		);
218
219
220
221
		return $cat;
222
	}
223
	
224
	
225
	
226
	
227
	
228 View Code Duplication
	protected function category_export()
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...
229
	{
230
	    $W = bab_Widgets();
231
	    $cat = $this->category(absences_translate('Exports'));
232
	    
233
	    
234
	    $cat->addItem(
235
            $W->Link(
236
                $W->Icon(absences_translate("Rights export"), Func_Icons::MIMETYPES_OFFICE_SPREADSHEET),
237
                absences_addon()->getUrl()."vacadm&idx=rightsexport"
238
            )
239
        );
240
	    
241
	    $cat->addItem(
242
	            $W->Link(
243
	                    $W->Icon(absences_translate("Vacation requests exports"), Func_Icons::MIMETYPES_OFFICE_SPREADSHEET),
244
	                    absences_addon()->getUrl()."exportvac&idx=reqx"
245
	            )
246
	    );
247
	    
248
	    
249
	    $cat->addItem(
250
	            $W->Link(
251
	                    $W->Icon(absences_translate("Vacation requests Sage exports"), Func_Icons::MIMETYPES_OFFICE_SPREADSHEET),
252
	                    absences_addon()->getUrl()."exportvac&idx=sage"
253
	            )
254
	    );
255
	    
256
	    
257
	    $cat->addItem(
258
	            $W->Link(
259
	                    $W->Icon(absences_translate("Available balances export"), Func_Icons::MIMETYPES_OFFICE_SPREADSHEET),
260
	                    absences_addon()->getUrl()."vacadm&idx=abexport"
261
	            )
262
	    );
263
	    
264
	    
265
	    $cat->addItem(
266
	            $W->Link(
267
	                    $W->Icon(absences_translate("Download statistics"), Func_Icons::MIMETYPES_OFFICE_SPREADSHEET),
268
	                    absences_addon()->getUrl()."statistics&idx=filter"
269
	            )
270
	    );
271
	    
272
	    
273
	    return $cat;
274
	}
275
276
277
	public function getFrame()
278
	{
279
		$W = bab_Widgets();
280
281
		$frame = $W->Frame()
282
			->setLayout($W->FlowLayout()->setVerticalAlign('top')->setSpacing(5, 'em'))
283
			->addClass(Func_Icons::ICON_LEFT_24)
284
			->addClass('BabLoginMenuBackground')
285
			->addClass('widget-bordered');
286
287
		$frame->addItem($this->category_settings());
288
		$frame->addItem($this->category_rights());
289
		$frame->addItem($this->category_requests());
290
		$frame->addItem($this->category_export());
291
292
		return $frame;
293
	}
294
}