Skip to content

Commit 54fe52d

Browse files
committed
Add types
1 parent a4278e6 commit 54fe52d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+613
-242
lines changed

src/CommonITILObject.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ protected function setPredefinedFields(ITILTemplate $tt, array &$options, array
779779
$tpl_key = static::getTemplateFormFieldName();
780780

781781
if ($this->isNewItem()) {
782-
if (isset($tt->predefined) && count($tt->predefined)) {
782+
if (count($tt->predefined)) {
783783
foreach ($tt->predefined as $predeffield => $predefvalue) {
784784
if (isset($options[$predeffield]) && isset($default_values[$predeffield])) {
785785
// Is always default value : not set
@@ -1115,6 +1115,13 @@ public function canMassiveAction($action, $field, $value)
11151115
return true;
11161116
}
11171117

1118+
/**
1119+
* Can ITIL object be reopened?
1120+
*
1121+
* @return bool
1122+
*/
1123+
abstract public function canReopen();
1124+
11181125

11191126
/**
11201127
* Do the current ItilObject need to be reopened by a requester answer

src/IPAddress.php

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ public static function getTypeName($nb = 0)
136136
}
137137

138138
/**
139-
* @param $input
140-
**/
139+
* @param array $input
140+
*
141+
* @return array|false
142+
*/
141143
public function prepareInput($input)
142144
{
143145

@@ -229,6 +231,12 @@ public function post_getFromDB()
229231
$this->setAddressFromArray($this->fields, "version", "name", "binary");
230232
}
231233

234+
/**
235+
* @param CommonGLPI $item
236+
* @param int $withtemplate
237+
*
238+
* @return void
239+
*/
232240
public static function showForItem(CommonGLPI $item, $withtemplate = 0)
233241
{
234242
global $DB;
@@ -335,8 +343,10 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
335343
}
336344

337345
/**
338-
* @param $item CommonDBTM object
339-
**/
346+
* @param CommonDBTM $item
347+
*
348+
* @return int|void
349+
*/
340350
public static function countForItem(CommonDBTM $item)
341351
{
342352
global $DB;
@@ -378,7 +388,9 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
378388

379389
/**
380390
* Disable the address
381-
**/
391+
*
392+
* @return void
393+
*/
382394
public function disableAddress()
383395
{
384396
$this->version = '';
@@ -481,32 +493,49 @@ public function setAddressFromArray(array $array, $versionField, $textualField,
481493

482494
/**
483495
* Check address validity
484-
**/
496+
*
497+
* @return bool
498+
*/
485499
public function is_valid()
486500
{
487501
return (($this->version != '') && ($this->textual != '') && ($this->binary != ''));
488502
}
489503

504+
/**
505+
* @return false|int|string
506+
*/
490507
public function getVersion()
491508
{
492509
return $this->version !== '' ? $this->version : false;
493510
}
494511

512+
/**
513+
* @return bool
514+
*/
495515
public function is_ipv4()
496516
{
497517
return ($this->getVersion() == 4);
498518
}
499519

520+
/**
521+
* @return bool
522+
*/
500523
public function is_ipv6()
501524
{
502525
return ($this->getVersion() == 6);
503526
}
504527

528+
/**
529+
* @return false|string
530+
*/
505531
public function getTextual()
506532
{
507533
return $this->textual !== '' ? $this->textual : false;
508534
}
509535

536+
/**
537+
* @return false|int[]|string
538+
*/
510539
public function getBinary()
511540
{
512541
return $this->binary !== '' ? $this->binary : false;
@@ -1052,12 +1081,14 @@ public function equals($ipaddress)
10521081
}
10531082

10541083
/**
1055-
* @param $itemtype
1056-
* @param $base HTMLTableBase object
1057-
* @param $super HTMLTableSuperHeader object (default NULL)
1058-
* @param $father HTMLTableHeader object (default NULL)
1084+
* @param class-string<CommonDBTM> $itemtype
1085+
* @param HTMLTableBase $base
1086+
* @param ?HTMLTableSuperHeader $super
1087+
* @param ?HTMLTableHeader $father
10591088
* @param $options array
1060-
**/
1089+
*
1090+
* @return void
1091+
*/
10611092
public static function getHTMLTableHeader(
10621093
$itemtype,
10631094
HTMLTableBase $base,
@@ -1261,11 +1292,13 @@ private static function getCriteriaLinkedToNetwork(IPNetwork $network): array
12611292
}
12621293

12631294
/**
1264-
* @param HTMLTableRow $row
1265-
* @param CommonDBTM $item
1266-
* @param HTMLTableCell $father
1295+
* @param ?HTMLTableRow $row
1296+
* @param ?CommonDBTM $item
1297+
* @param ?HTMLTableCell $father
12671298
* @param array $options
1268-
**/
1299+
*
1300+
* @return void
1301+
*/
12691302
public static function getHTMLTableCellsForItem(
12701303
?HTMLTableRow $row = null,
12711304
?CommonDBTM $item = null,

src/IPNetmask.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ class IPNetmask extends IPAddress
4141

4242

4343
/**
44-
* @param $ipnetmask (default '')
45-
* @param $version (default 0)
44+
* @param string|array|IPNetmask $ipnetmask
45+
* @param int $version
4646
**/
4747
public function __construct($ipnetmask = '', $version = 0)
4848
{
4949

5050
// First, be sure that the parent is correctly initialised
5151
parent::__construct();
5252

53-
// If $ipnetmask if empty, then, empty netmask !
53+
// If $ipnetmask is empty, then, empty netmask!
5454
if ($ipnetmask != '') {
5555
// If $ipnetmask if an IPNetmask, then just clone it
5656
if ($ipnetmask instanceof IPNetmask) {
@@ -80,14 +80,13 @@ public static function getTypeName($nb = 0)
8080
* Create a binary Netmask from dot notation (for instance : 255.255.255.0) or
8181
* integer (for instance /24). Rely on setAddressFromString()
8282
*
83-
* @param $netmask string netmask defined as textual
84-
* @param $version integer =4 or =6 : version of IP protocol
83+
* @param string $netmask netmask defined as textual
84+
* @param int|string $version =4 or =6 : version of IP protocol
8585
*
8686
* @return bool false if the netmask is not valid or if it does not correspond to version
87-
**/
87+
*/
8888
public function setNetmaskFromString($netmask, $version)
8989
{
90-
9190
if (is_numeric($netmask)) {
9291
if ($netmask < 0) {
9392
return false;

src/ITILCategory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,11 @@ public function prepareInputForUpdate($input)
406406
return $input;
407407
}
408408

409+
/**
410+
* @param array $input
411+
*
412+
* @return array
413+
*/
409414
public function prepareInputForClone($input)
410415
{
411416
// The code must be unique so we cannot clone it

src/ITILFollowup.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ITILFollowup extends CommonDBChild
4848
// From CommonDBTM
4949
public $auto_message_on_action = false;
5050
public static $rightname = 'followup';
51-
private $item = null;
51+
private ?CommonITILObject $item = null;
5252

5353
public static $log_history_add = Log::HISTORY_LOG_SIMPLE_MESSAGE;
5454
public static $log_history_update = Log::HISTORY_LOG_SIMPLE_MESSAGE;
@@ -71,6 +71,9 @@ class ITILFollowup extends CommonDBChild
7171
public static $items_id = 'items_id';
7272

7373

74+
/**
75+
* @return string
76+
*/
7477
public function getItilObjectItemType()
7578
{
7679
return str_replace('Followup', '', $this->getType());
@@ -193,6 +196,9 @@ public function canCreateItem(): bool
193196
$itilobject = $this->item;
194197
} else {
195198
$itilobject = getItemForItemtype($this->fields['itemtype']);
199+
if (!$itilobject instanceof CommonITILObject) {
200+
return false;
201+
}
196202
}
197203

198204
if (
@@ -241,7 +247,7 @@ public function canUpdateItem(): bool
241247
} else {
242248
$itilobject = getItemForItemtype($this->fields['itemtype']);
243249
}
244-
if (!$itilobject->can($this->getField('items_id'), READ)) {
250+
if (!$itilobject instanceof CommonITILObject || !$itilobject->can($this->getField('items_id'), READ)) {
245251
return false;
246252
}
247253

@@ -638,7 +644,9 @@ public function post_getFromDB()
638644
// Bandaid to avoid loading parent item if not needed
639645
// TODO: replace by proper lazy loading
640646
if (!$this->isParentAlreadyLoaded()) {
641-
if ($this->item = getItemForItemtype($this->fields['itemtype'])) {
647+
$item = getItemForItemtype($this->fields['itemtype']);
648+
if ($item instanceof CommonITILObject) {
649+
$this->item = $item;
642650
$this->item->getFromDB($this->fields['items_id']);
643651
}
644652
}
@@ -734,6 +742,10 @@ public function rawSearchOptions()
734742
}
735743

736744

745+
/**
746+
* @param class-string<CommonDBTM> $itemtype
747+
* @return array
748+
*/
737749
public static function rawSearchOptionsToAdd($itemtype = null)
738750
{
739751
global $DB;
@@ -937,6 +949,9 @@ public function showForm($ID, array $options = [])
937949
return true;
938950
}
939951

952+
/**
953+
* @return void
954+
*/
940955
public static function showMassiveActionAddFollowupForm()
941956
{
942957
echo "<table class='tab_cadre_fixe'>";

src/ITILSolution.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ITILSolution extends CommonDBChild
4343
{
4444
// From CommonDBTM
4545
public $dohistory = true;
46-
private $item = null;
46+
private ?CommonITILObject $item = null;
4747

4848
public static $itemtype = 'itemtype'; // Class name or field name (start with itemtype) for link to Parent
4949
public static $items_id = 'items_id'; // Field name
@@ -133,7 +133,9 @@ public function post_getFromDB()
133133
|| $this->item->getType() !== $this->fields['itemtype'] // Another item is loaded
134134
|| $this->item->getID() !== $this->fields['items_id'] // Another item is loaded
135135
) {
136-
if ($this->item = getItemForItemtype($this->fields['itemtype'])) {
136+
$item = getItemForItemtype($this->fields['itemtype']);
137+
if ($item instanceof CommonITILObject) {
138+
$this->item = $item;
137139
$this->item->getFromDB($this->fields['items_id']);
138140
}
139141
}
@@ -292,14 +294,13 @@ public function prepareInputForAdd($input)
292294
public function post_addItem()
293295
{
294296

295-
//adding a solution mean the ITIL object is now solved
296-
//and maybe closed (according to entitiy configuration)
297-
if ($this->item == null) {
298-
$this->item = getItemForItemtype($this->fields['itemtype']);
299-
$this->item->getFromDB($this->fields['items_id']);
297+
$item = getItemForItemtype($this->fields['itemtype']);
298+
if (!$item instanceof CommonITILObject) {
299+
return;
300300
}
301301

302-
$item = $this->item;
302+
$item->getFromDB($this->fields['items_id']);
303+
$this->item = $item;
303304

304305
// Handle rich-text images and uploaded documents
305306
$this->input["_job"] = $this->item;

0 commit comments

Comments
 (0)