Completed
Push — master ( a394db...779b37 )
by Paul
09:04
created

absences_WorkperiodRecoverRequestEditor::period()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 0
dl 9
loc 9
rs 9.6666
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
bab_Widgets()->includePhpClass('Widget_Form');
26
27
28
class absences_WorkperiodRecoverRequestEditor extends Widget_Form
29
{
30
	/**
31
	 * @var absences_WorkperiodRecoverRequest
32
	 */
33
	protected $workperiod;
34
	
35
	/**
36
	 *
37
	 * @var bool
38
	 */
39
	protected $withCardFrame;
40
	
41
	/**
42
	 * Display the quantity field
43
	 * @var bool
44
	 */
45
	protected $quantityField;
46
	
47
	/**
48
	 * 
49
	 * @param absences_WorkperiodRecoverRequest $wd
50
	 * @param bool $withCardFrame			Display the appliquant card frame (approval, manager)
51
	 * @param bool $quantityField			Display the quantity field (approval, manager)
52
	 */
53
	public function __construct(absences_WorkperiodRecoverRequest $wd = null, $withCardFrame = null, $quantityField = null)
54
	{
55
		$W = bab_Widgets();
56
		
57
		$this->workperiod = $wd;
58
		
59
		$this->withCardFrame = isset($withCardFrame) ? $withCardFrame : isset($wd);
60
		$this->quantityField = isset($quantityField) ? $quantityField : isset($wd);
61
	
62
		parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(2,'em'));
63
		
64
		bab_functionality::includefile('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 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...
65
		
66
	
67
		$this->setName('workperiod');
68
		$this->addClass('widget-bordered');
69
		$this->addClass('BabLoginMenuBackground');
70
		$this->addClass('widget-centered');
71
		$this->addClass(Func_Icons::ICON_LEFT_24);
72
		$this->colon();
73
	
74
		$this->setCanvasOptions($this->Options()->width(60,'em'));
0 ignored issues
show
Bug introduced by
It seems like $this->Options()->width(60, '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...
75
	
76
	
77
		
78
		
79
		$this->addFields();
80
		$this->addButtons();
81
		$this->setSelfPageHiddenFields();
82
		$this->loadValues();
83
		
84
	}
85
	
86
	
87
	protected function loadValues()
88
	{
89
		if (isset($_POST['workperiod']))
90
		{
91
			$this->setValues(array('workperiod' => $_POST['workperiod']));
92
			
93
			if (isset($_POST['workperiod']['id']))
94
			{
95
				$this->setHiddenValue('workperiod[id]', $_POST['workperiod']['id']);
96
			}
97
			return;
98
		}
99
		
100
		if (isset($this->workperiod))
101
		{
102
			$values = $this->workperiod->getRow();
103
			if (isset($values['date_begin'])) {
104
			     $values['datebegin'] = mb_substr($values['date_begin'], 0, 10);
105
			     $values['hourbegin'] = mb_substr($values['date_begin'], 11);
106
			}
107
			
108
			if (isset($values['date_end'])) {
109
			$values['dateend'] = mb_substr($values['date_end'], 0, 10);
110
			$values['hourend'] = mb_substr($values['date_end'], 11);
111
			}
112
			
113
			$this->setValues(array('workperiod' => $values));
114
			
115
			if (isset($values['id_user'])) {
116
			    $this->setHiddenValue('workperiod[id_user]', $values['id_user']);
117
			}
118
			
119
			if (isset($values['id'])) {
120
			     $this->setHiddenValue('workperiod[id]', $values['id']);
121
			}
122
			
123
		}
124
	}
125
	
126
	
127
	protected function addFields()
128
	{
129
		$W = bab_Widgets();
130
		
131
		if (isset($this->workperiod) && $this->withCardFrame)
132
		{
133
			require_once dirname(__FILE__).'/agent.class.php';
134
			require_once dirname(__FILE__).'/agent.ui.php';
135
			
136
			$agent = absences_Agent::getFromIdUser($this->workperiod->id_user);
137
			$cardFrame = new absences_AgentCardFrame($agent);
138
			$this->addItem($cardFrame);
139
		}
140
	
141
		$this->addItem($this->period());
142
		$this->addItem($this->id_type());
143
		
144
		if ($this->quantityField)
145
		{
146
			if ($this->workperiod->status === '')
147
			{
148
				// waiting request
149
				$this->addItem($this->quantity());
150
			} else {
151
				
152
				// confirmed or rejected
153
				$this->addItem(
154
					$W->Label(
155
						sprintf(
156
							absences_translate('Quantity used in the recovery creation : %s'), 
157
							absences_quantity($this->workperiod->quantity, $this->workperiod->quantity_unit)
158
						)
159
					)
160
				);
161
			}
162
		}
163
		
164
		$this->addItem($this->comment());
165
	}
166
	
167
	
168 View Code Duplication
	protected function id_type()
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...
169
	{
170
		$W = bab_Widgets();
171
		$select = $W->Select();
172
		
173
		require_once dirname(__FILE__).'/workperiod_type.class.php';
174
		
175
		$I = new absences_WorkperiodTypeIterator;
176
		foreach($I as $workperiodType)
177
		{
178
			$select->addOption($workperiodType->id, $workperiodType->name);
179
		}
180
		
181
		return $W->LabelledWidget(absences_translate('Working day type'), $select, __FUNCTION__);
182
	}
183
	
184
	
185
	/**
186
	 * quantity & quantity_unit
187
	 * @return Widget_FlowLayout
188
	 */
189 View Code Duplication
	protected function quantity()
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...
190
	{
191
		$W = bab_Widgets();
192
	
193
		$lineedit = $W->LineEdit()->setSize(2)->setMaxSize(5)->setMandatory(true, absences_translate('The quantity is mandatory'))->setName('quantity');
194
		$select = $W->Select()->setName('quantity_unit')
195
		->addOption('D', absences_translate('Day(s)'))
196
		->addOption('H', absences_translate('Hour(s)'));
197
	
198
		return $W->VBoxItems(
199
				$W->Label(absences_translate('Quantity'))->setAssociatedWidget($lineedit)->addClass('widget-strong'),
200
				$W->FlowItems($lineedit, $select)
201
		)->setVerticalSpacing(.2,'em');
202
	}
203
	
204
	
205
	
206 View Code Duplication
	protected function comment()
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...
207
	{
208
		$W = bab_Widgets();
209
		
210
		return $W->LabelledWidget(
211
			absences_translate('Reason for the request'), 
212
			$W->TextEdit()->setColumns(80)->setLines(5)->setMandatory(true, absences_translate('The reason is mandatory')),
213
			 __FUNCTION__
214
		);
215
	}
216
	
217
	
218
	/**
219
	 * 
220
	 * @return Widget_VBoxLayout
221
	 */
222 View Code Duplication
	protected function period()
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...
223
	{
224
		$W = bab_Widgets();
225
	
226
		return $W->VBoxItems(
227
				$W->Label(absences_translate('Worked period')),
228
				$W->FlowItems($this->date_begin(), $this->date_end())
229
		)->setVerticalSpacing(1,'em');
230
	}
231
	
232
	
233 View Code Duplication
	protected function date_begin()
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...
234
	{
235
		require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
236
		
237
		$delay = BAB_DateTime::now();
238
		$delay->add(absences_getVacationOption('delay_recovery'), BAB_DATETIME_DAY);
239
		
240
		$W = bab_Widgets();
241
		$date = $W->DatePicker()->setMaxDate($delay)->setMandatory(true)->setName('datebegin');
242
		$hours = $W->Select()->setName('hourbegin')->setOptions(absences_hoursList());
243
		
244
		$this->beginDate = $date;
0 ignored issues
show
Bug introduced by
The property beginDate 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...
245
		
246
		return $W->FlowItems(
247
			$W->Label(absences_translate('from date'))->setAssociatedWidget($date),
248
			$date,
249
			$hours
250
		)->setSpacing(.5,'em');
251
	}
252
	
253
	
254 View Code Duplication
	protected function date_end()
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...
255
	{
256
	    require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
257
	    
258
	    $delay = BAB_DateTime::now();
259
	    $delay->add(absences_getVacationOption('delay_recovery'), BAB_DATETIME_DAY);
260
	    
261
		$W = bab_Widgets();
262
		$date = $W->DatePicker()->setMinDate($this->beginDate)->setMaxDate($delay)->setMandatory(true)->setName('dateend');
263
		$hours = $W->Select()->setName('hourend')->setOptions(absences_hoursList());
264
		
265
		return $W->FlowItems(
266
			$W->Label(absences_translate('to date'))->setAssociatedWidget($date),
267
			$date,
268
			$hours
269
		)->setSpacing(.5,'em');
270
	}
271
272
	
273
	
274 View Code Duplication
	protected function addButtons()
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...
275
	{
276
		$W = bab_Widgets();
277
	
278
		$button = $W->FlowItems(
279
				$W->SubmitButton()->setName('cancel')->setLabel(absences_translate('Cancel')),
280
				$W->SubmitButton()->setName('save')->setLabel(absences_translate('Save'))->validate()
281
		)->setSpacing(1,'em');
282
	
283
		$this->addItem($button);
284
	}
285
	
286
}
287
288
289
290
291
292
293
class absences_WorkperiodRecoverApprobEditor extends absences_WorkperiodRecoverRequestEditor {
294
	
295
	
296
	public function __construct(absences_WorkperiodRecoverRequest $workperiod)
297
	{
298
		
299
		parent::__construct($workperiod);
300
		
301
		
302
	}
303
	
304
	/**
305
	 * Load values into editor
306
	 * 
307
	 */
308 View Code Duplication
	protected function loadValues()
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...
309
	{
310
		if (isset($_POST['workperiod']))
311
		{
312
			$this->setValues(array('workperiod' => $_POST['workperiod']));
313
		} else {
314
			if (isset($this->workperiod))
315
			{
316
				$this->setValues(array('workperiod' => $this->workperiod->getRow()));
317
			}
318
		}
319
		
320
		if (isset($this->workperiod))
321
		{
322
			$this->setHiddenValue('workperiod[id]', $this->workperiod->id);
323
			$this->setHiddenValue('id_workperiod', $this->workperiod->id);
324
		}
325
	}
326
	
327
	
328
	protected function addFields()
329
	{
330
		$W = bab_Widgets();
331
		
332
		require_once dirname(__FILE__).'/agent.ui.php';
333
		
334
		$agent = $this->workperiod->getAgent();
335
		$card = new absences_AgentCardFrame($agent);
336
		
337
		$this->addItem($card);
338
	
339
		$this->addItem($this->period());
340
		
341
		if ($type = $this->type())
342
		{
343
			$this->addItem($type);
344
		}
345
		
346
		$this->addItem($this->computed_quantity());
347
		$this->addItem($this->quantity());
348
		$this->addItem($this->validity_end());
349
		
350
		if ($comment = $this->comment())
351
		{
352
			$this->addItem($comment);
353
		}
354
		
355
		$this->addItem($this->comment2());
356
		
357
		if (!$this->workperiod->todelete) {
358
		    $this->addItem($W->Icon(
359
		      absences_translate('The acceptation will open a recovery vacation right for the applicant with the specified quantity'), Func_Icons::STATUS_DIALOG_INFORMATION)
360
		    );
361
		}
362
	}
363
	
364
	
365
	
366
	protected function validity_end()
367
	{
368
		$W = bab_Widgets();
369
		
370
		return $W->LabelledWidget(
371
				absences_translate('Recovery right validity end date'),
372
				$W->DatePicker(),
373
				__FUNCTION__
374
		);
375
	}
376
	
377
	
378 View Code Duplication
	protected function computed_quantity()
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...
379
	{
380
		$W = bab_Widgets();
381
	
382
		$type = $this->workperiod->getType();
383
		
384
		return $W->VBoxItems(
385
				$W->Label(absences_translate('Computed quantity on period'))->colon()->addClass('widget-strong'),
386
				$W->Label(absences_quantity($this->workperiod->getComputedDuration(), $type->quantity_unit))
0 ignored issues
show
Documentation introduced by
The property quantity_unit does not exist on object<absences_WorkperiodType>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
387
		);
388
	}
389
	
390
	
391
	/**
392
	 *
393
	 * 
394
	 */
395
	protected function period()
396
	{
397
		$W = bab_Widgets();
398
		
399
		return $W->VBoxItems(
400
				$W->Label(absences_translate('Working period'))->colon()->addClass('widget-strong'),
401
				$W->Label(absences_DateTimePeriod($this->workperiod->date_begin, $this->workperiod->date_end, 'bab_longDate'))
402
		);
403
	}
404
	
405
	/**
406
	 * 
407
	 */
408
	protected function type()
409
	{
410
		$W = bab_Widgets();
411
		
412
		$type = $this->workperiod->getType();
413
		
414
		if (!isset($type))
415
		{
416
			return null;
417
		}
418
		
419
		return $W->VBoxItems(
420
				$W->Label(absences_translate('Working day type'))->colon()->addClass('widget-strong'),
421
				$W->Label($type->name)
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<absences_WorkperiodType>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
422
		);
423
		
424
	}
425
	
426
	/**
427
	 * 
428
	 */
429
	protected function comment()
430
	{
431
		$W = bab_Widgets();
432
		
433
		if (empty($this->workperiod->comment))
434
		{
435
			return null;
436
		}
437
	
438
		return $W->VBoxItems(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $W->VBoxItems($W-...TML_ALL ^ BAB_HTML_P)); (Widget_VBoxLayout) is incompatible with the return type of the parent method absences_WorkperiodRecoverRequestEditor::comment of type Widget_LabelledWidget.

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...
439
			$W->Label(absences_translate('Reason for the request'))->colon()->addClass('widget-strong'),
440
			$W->RichText($this->workperiod->comment)->setRenderingOptions(BAB_HTML_ALL ^ BAB_HTML_P)
441
		);
442
	}
443
	
444
	
445
	
446 View Code Duplication
	protected function duration()
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...
447
	{
448
		$W = bab_Widgets();
449
		
450
		return $W->VBoxItems(
451
				$W->Label(absences_translate('Computed duration'))->colon(),
452
				$W->Label(absences_quantity($this->workperiod->getComputedDuration(), $this->workperiod->getType()->quantity_unit))
0 ignored issues
show
Documentation introduced by
The property quantity_unit does not exist on object<absences_WorkperiodType>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
453
		);
454
	}
455
	
456
	
457 View Code Duplication
	protected function comment2()
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...
458
	{
459
		$W = bab_Widgets();
460
	
461
		return $W->LabelledWidget(
462
				absences_translate('Approver comment'),
463
				$W->TextEdit()->setColumns(80)->setLines(5),
464
				__FUNCTION__
465
		);
466
	}
467
	
468
	
469
	
470
	protected function addButtons()
471
	{
472
		$W = bab_Widgets();
473
		
474
		if ($this->workperiod->todelete) {
475
		    $label = absences_translate('Confirm deletion');
476
		} else {
477
		    $label = absences_translate('Confirm');
478
		}
479
	
480
		$button = $W->FlowItems(
481
				
482
				$W->SubmitButton()->setName('confirm')->setLabel($label),
483
				$W->SubmitButton()->setName('refuse')->setLabel(absences_translate('Refuse'))
484
		)->setSpacing(1,'em');
485
	
486
		$this->addItem($button);
487
	}
488
	
489
}