From 030d912820b3efe9c59b5ffb2e15af5c06483dcf Mon Sep 17 00:00:00 2001 From: Molkobain Date: Tue, 9 Jul 2019 19:10:16 +0200 Subject: [PATCH] Code cleanup - Format code accordingly to coding conventions - Add / update PHPDoc all over the place - Suppress most of the warnings that did not have a big impact on code's logic --- core/dbobjectsearch.class.php | 3 + core/dbsearch.class.php | 5 ++ sources/form/field/field.class.inc.php | 30 ++++----- .../form/field/fileuploadfield.class.inc.php | 47 +++++++++++++- .../field/multiplechoicesfield.class.inc.php | 62 ++++++++++++++++++- sources/form/field/selectfield.class.inc.php | 13 +++- sources/form/formmanager.class.inc.php | 6 +- 7 files changed, 145 insertions(+), 21 deletions(-) diff --git a/core/dbobjectsearch.class.php b/core/dbobjectsearch.class.php index 65aa14023..3e96a9359 100644 --- a/core/dbobjectsearch.class.php +++ b/core/dbobjectsearch.class.php @@ -954,6 +954,9 @@ class DBObjectSearch extends DBSearch } } + /** + * @inheritDoc + */ public function Intersect(DBSearch $oFilter) { if ($oFilter instanceof DBUnionSearch) diff --git a/core/dbsearch.class.php b/core/dbsearch.class.php index 9f22b796a..e6ab5692e 100644 --- a/core/dbsearch.class.php +++ b/core/dbsearch.class.php @@ -187,6 +187,11 @@ abstract class DBSearch */ abstract public function AddCondition_ReferencedBy(DBObjectSearch $oFilter, $sForeignExtKeyAttCode, $iOperatorCode = TREE_OPERATOR_EQUALS, &$aRealiasingMap = null); + /** + * @param \DBSearch $oFilter + * + * @return \DBSearch + */ abstract public function Intersect(DBSearch $oFilter); /** diff --git a/sources/form/field/field.class.inc.php b/sources/form/field/field.class.inc.php index 6cf6646f1..5eea0240c 100644 --- a/sources/form/field/field.class.inc.php +++ b/sources/form/field/field.class.inc.php @@ -214,7 +214,7 @@ abstract class Field * Usually Called by the form when adding the field * * @param string $sFormPath - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetFormPath($sFormPath) { @@ -225,7 +225,7 @@ abstract class Field /** * * @param string $sLabel - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetLabel($sLabel) { @@ -236,7 +236,7 @@ abstract class Field /** * * @param boolean $bHidden - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetHidden($bHidden) { @@ -247,7 +247,7 @@ abstract class Field /** * * @param boolean $bReadOnly - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetReadOnly($bReadOnly) { @@ -260,7 +260,7 @@ abstract class Field * Setting the value will automatically add/remove a MandatoryValidator to the Field * * @param boolean $bMandatory - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetMandatory($bMandatory) { @@ -291,7 +291,7 @@ abstract class Field * * @todo Implement * @param boolean $bMustChange - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetMustChange($bMustChange) { @@ -313,7 +313,7 @@ abstract class Field /** * * @param array $aValidators - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetValidators($aValidators) { @@ -325,7 +325,7 @@ abstract class Field * Note : Function is protected as bValid should not be set from outside * * @param boolean $bValid - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ protected function SetValid($bValid) { @@ -337,7 +337,7 @@ abstract class Field * Note : Function is protected as aErrorMessages should not be set from outside * * @param array $aErrorMessages - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ protected function SetErrorMessages($aErrorMessages) { @@ -348,7 +348,7 @@ abstract class Field /** * * @param mixed $currentValue - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetCurrentValue($currentValue) { @@ -359,7 +359,7 @@ abstract class Field /** * * @param Closure $onFinalizeCallback - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function SetOnFinalizeCallback(Closure $onFinalizeCallback) { @@ -370,7 +370,7 @@ abstract class Field /** * * @param \Combodo\iTop\Form\Validator\Validator $oValidator - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function AddValidator(Validator $oValidator) { @@ -381,7 +381,7 @@ abstract class Field /** * * @param \Combodo\iTop\Form\Validator\Validator $oValidator - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ public function RemoveValidator(Validator $oValidator) { @@ -399,7 +399,7 @@ abstract class Field * Note : Function is protected as aErrorMessages should not be add from outside * * @param string $sErrorMessage - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ protected function AddErrorMessage($sErrorMessage) { @@ -410,7 +410,7 @@ abstract class Field /** * Note : Function is protected as aErrorMessages should not be set from outside * - * @return \Combodo\iTop\Form\Field\Field + * @return $this */ protected function EmptyErrorMessages() { diff --git a/sources/form/field/fileuploadfield.class.inc.php b/sources/form/field/fileuploadfield.class.inc.php index f6f1ee7f5..6d1077007 100644 --- a/sources/form/field/fileuploadfield.class.inc.php +++ b/sources/form/field/fileuploadfield.class.inc.php @@ -19,6 +19,8 @@ namespace Combodo\iTop\Form\Field; +use Closure; + /** * Description of FileUploadField * @@ -26,15 +28,24 @@ namespace Combodo\iTop\Form\Field; */ class FileUploadField extends Field { + /** @var bool DEFAULT_ALLOW_DELETE */ const DEFAULT_ALLOW_DELETE = true; + /** @var string|null $sTransactionId */ protected $sTransactionId; + /** @var \DBObject|null $oObject */ protected $oObject; + /** @var string|null $sUploadEndpoint */ protected $sUploadEndpoint; + /** @var string|null $sDownloadEndpoint */ protected $sDownloadEndpoint; + /** @var bool $bAllowDelete */ protected $bAllowDelete; - public function __construct($sId, \Closure $onFinalizeCallback = null) + /** + * @inheritDoc + */ + public function __construct($sId, Closure $onFinalizeCallback = null) { $this->sTransactionId = null; $this->oObject = null; @@ -58,7 +69,7 @@ class FileUploadField extends Field /** * * @param string $sTransactionId - * @return \Combodo\iTop\Form\Field\FileUploadField + * @return $this */ public function SetTransactionId($sTransactionId) { @@ -66,44 +77,76 @@ class FileUploadField extends Field return $this; } + /** + * @return \DBObject|null + */ public function GetObject() { return $this->oObject; } + /** + * @param $oObject + * + * @return $this + */ public function SetObject($oObject) { $this->oObject = $oObject; return $this; } + /** + * @return string|null + */ public function GetUploadEndpoint() { return $this->sUploadEndpoint; } + /** + * @param $sUploadEndpoint + * + * @return $this + */ public function SetUploadEndpoint($sUploadEndpoint) { $this->sUploadEndpoint = $sUploadEndpoint; return $this; } + /** + * @return string|null + */ public function GetDownloadEndpoint() { return $this->sDownloadEndpoint; } + /** + * @param $sDownloadEndpoint + * + * @return $this + */ public function SetDownloadEndpoint($sDownloadEndpoint) { $this->sDownloadEndpoint = $sDownloadEndpoint; return $this; } + /** + * @return bool + */ public function GetAllowDelete() { return $this->bAllowDelete; } + /** + * @param $bAllowDelete + * + * @return $this + */ public function SetAllowDelete($bAllowDelete) { $this->bAllowDelete = (boolean) $bAllowDelete; diff --git a/sources/form/field/multiplechoicesfield.class.inc.php b/sources/form/field/multiplechoicesfield.class.inc.php index 7d866df1e..a8a113837 100644 --- a/sources/form/field/multiplechoicesfield.class.inc.php +++ b/sources/form/field/multiplechoicesfield.class.inc.php @@ -28,14 +28,21 @@ use Closure; * Values = Items that have been picked * * @author Guillaume Lajarige + * @since 2.3.0 */ abstract class MultipleChoicesField extends Field { + /** @var bool DEFAULT_MULTIPLE_VALUES_ENABLED */ const DEFAULT_MULTIPLE_VALUES_ENABLED = false; + /** @var bool $bMultipleValuesEnabled */ protected $bMultipleValuesEnabled; + /** @var array $aChoices */ protected $aChoices; + /** + * @inheritDoc + */ public function __construct($sId, Closure $onFinalizeCallback = null) { parent::__construct($sId, $onFinalizeCallback); @@ -44,6 +51,9 @@ abstract class MultipleChoicesField extends Field $this->currentValue = array(); } + /** + * @inheritDoc + */ public function GetCurrentValue() { $value = null; @@ -67,7 +77,7 @@ abstract class MultipleChoicesField extends Field * Sets the current value for the MultipleChoicesField. * * @param mixed $currentValue Can be either an array of values (in case of multiple values) or just a simple value - * @return \Combodo\iTop\Form\Field\MultipleChoicesField + * @return $this */ public function SetCurrentValue($currentValue) { @@ -86,29 +96,52 @@ abstract class MultipleChoicesField extends Field return $this; } + /** + * @return bool + */ public function GetMultipleValuesEnabled() { return $this->bMultipleValuesEnabled; } + /** + * @param bool $bMultipleValuesEnabled + * + * @return $this + */ public function SetMultipleValuesEnabled($bMultipleValuesEnabled) { $this->bMultipleValuesEnabled = $bMultipleValuesEnabled; return $this; } + /** + * @param array $aValues + * + * @return $this + */ public function SetValues($aValues) { $this->currentValue = $aValues; return $this; } + /** + * @param mixed $value + * + * @return $this + */ public function AddValue($value) { $this->currentValue = $value; return $this; } + /** + * @param mixed $value + * + * @return $this + */ public function RemoveValue($value) { if (array_key_exists($value, $this->currentValue)) @@ -118,22 +151,41 @@ abstract class MultipleChoicesField extends Field return $this; } + /** + * @param mixed $value + * + * @return bool + */ public function IsAmongValues($value) { return in_array($value, $this->currentValue); } + /** + * @return array + */ public function GetChoices() { return $this->aChoices; } + /** + * @param array $aChoices + * + * @return $this + */ public function SetChoices($aChoices) { $this->aChoices = $aChoices; return $this; } + /** + * @param string $sId + * @param null $choice + * + * @return $this + */ public function AddChoice($sId, $choice = null) { if ($choice === null) @@ -144,6 +196,11 @@ abstract class MultipleChoicesField extends Field return $this; } + /** + * @param string $sId + * + * @return $this + */ public function RemoveChoice($sId) { if (in_array($sId, $this->aChoices)) @@ -153,6 +210,9 @@ abstract class MultipleChoicesField extends Field return $this; } + /** + * @inheritDoc + */ public function Validate() { $this->SetValid(true); diff --git a/sources/form/field/selectfield.class.inc.php b/sources/form/field/selectfield.class.inc.php index ee330c08a..0cae8a562 100644 --- a/sources/form/field/selectfield.class.inc.php +++ b/sources/form/field/selectfield.class.inc.php @@ -26,15 +26,24 @@ use Dict; * Description of SelectField * * @author Guillaume Lajarige + * @since 2.3.0 */ class SelectField extends MultipleChoicesField { + // Overloaded constants const DEFAULT_MULTIPLE_VALUES_ENABLED = false; + + /** @var string DEFAULT_NULL_CHOICE_LABEL */ const DEFAULT_NULL_CHOICE_LABEL = 'UI:SelectOne'; + /** @var bool DEFAULT_STARTS_WITH_NULL_CHOICE */ const DEFAULT_STARTS_WITH_NULL_CHOICE = true; + /** @var bool $bStartsWithNullChoice */ protected $bStartsWithNullChoice; + /** + * @inheritDoc + */ public function __construct($sId, Closure $onFinalizeCallback = null) { parent::__construct($sId, $onFinalizeCallback); @@ -55,7 +64,7 @@ class SelectField extends MultipleChoicesField /** * @param $bStartsWithNullChoice * - * @return \Combodo\iTop\Form\Field\SelectField + * @return $this */ public function SetStartsWithNullChoice($bStartsWithNullChoice) { @@ -84,7 +93,7 @@ class SelectField extends MultipleChoicesField * Overloads the method to prevent changing this property. * * @param boolean $bMultipleValuesEnabled - * @return \Combodo\iTop\Form\Field\SelectField + * @return $this */ public function SetMultipleValuesEnabled($bMultipleValuesEnabled) { diff --git a/sources/form/formmanager.class.inc.php b/sources/form/formmanager.class.inc.php index 6e88a0fcf..8d733ae60 100644 --- a/sources/form/formmanager.class.inc.php +++ b/sources/form/formmanager.class.inc.php @@ -19,11 +19,12 @@ namespace Combodo\iTop\Form; -use \Combodo\iTop\Renderer\FormRenderer; +use Combodo\iTop\Renderer\FormRenderer; /** * Description of formmanager * + * @package Combodo\iTop\Form * @author Guillaume Lajarige */ abstract class FormManager @@ -68,6 +69,9 @@ abstract class FormManager return $oFormManager; } + /** + * FormManager constructor. + */ public function __construct() { // Overload in child class when needed