diff --git a/Domain/Access/AttributeFilter.php b/Domain/Access/AttributeFilter.php index 887e9a0b5..3403b5708 100644 --- a/Domain/Access/AttributeFilter.php +++ b/Domain/Access/AttributeFilter.php @@ -27,9 +27,9 @@ public static function Create($entityTableAndColumn, $attributes) $idEquals = new SqlFilterEquals($attributeId, $attribute->Id()); $f->AppendSql('LEFT JOIN `' . TableNames::CUSTOM_ATTRIBUTE_VALUES . '` `a' . $id . '` ON `a0`.`entity_id` = `a' . $id . '`.`entity_id` '); - if ($attribute->Type() == CustomAttributeTypes::MULTI_LINE_TEXTBOX || $attribute->Type() == CustomAttributeTypes::SINGLE_LINE_TEXTBOX) { + if ((int)$attribute->Type() === CustomAttributeTypes::MULTI_LINE_TEXTBOX || (int)$attribute->Type() === CustomAttributeTypes::SINGLE_LINE_TEXTBOX) { $attributeFragment->_And($idEquals->_And(new SqlFilterLike($attributeValue, $attribute->Value()))); - } elseif ($attribute->Type() == CustomAttributeTypes::CHECKBOX && $attribute->Value() == '0') { + } elseif ((int)$attribute->Type() === CustomAttributeTypes::CHECKBOX && $attribute->Value() == '0') { $attributeFragment->_And(new SqlFilterFreeForm('NOT EXISTS (SELECT 1 FROM `' . TableNames::CUSTOM_ATTRIBUTE_VALUES . '` `b` WHERE `b`.`entity_id` = `a0`.`entity_id` AND `b`.`custom_attribute_id` = ' . $id . ')')); } else { $attributeFragment->_And($idEquals->_And(new SqlFilterEquals($attributeValue, $attribute->Value()))); diff --git a/Domain/CustomAttribute.php b/Domain/CustomAttribute.php index 62d1bd97a..c442c0c23 100644 --- a/Domain/CustomAttribute.php +++ b/Domain/CustomAttribute.php @@ -308,7 +308,7 @@ public function __construct( $this->category = $category; $this->SetRegex($regex); $this->required = $required; - if ($category != CustomAttributeCategory::RESERVATION) { + if ((int)$category !== CustomAttributeCategory::RESERVATION) { $this->entityIds = is_array($entityIds) ? $entityIds : ($entityIds); } $this->adminOnly = $adminOnly; @@ -452,7 +452,7 @@ public function Update($label, $regex, $required, $possibleValues, $sortOrder, $ $this->SetRegex($regex); $this->required = $required; - if ($this->category != CustomAttributeCategory::RESERVATION) { + if ((int)$this->category !== CustomAttributeCategory::RESERVATION) { $entityIds = is_array($entityIds) ? $entityIds : [$entityIds]; $removed = array_diff($this->entityIds, $entityIds); $added = array_diff($entityIds, $this->entityIds); @@ -503,7 +503,7 @@ public function WithEntityDescriptions($entityDescriptions) */ public function WithSecondaryEntities($category, $entityIds, $entityDescriptions = null) { - if ($this->category != CustomAttributeCategory::RESERVATION) { + if ((int)$this->category != CustomAttributeCategory::RESERVATION) { return; } diff --git a/Pages/Admin/ManageAttributesPage.php b/Pages/Admin/ManageAttributesPage.php index 19d832438..9c100670b 100644 --- a/Pages/Admin/ManageAttributesPage.php +++ b/Pages/Admin/ManageAttributesPage.php @@ -13,12 +13,12 @@ public function GetLabel(); /** * @abstract - * return int|CustomAttributeTypes + * return CustomAttributeTypes */ public function GetType(); /** - * return int|CustomAttributeCategory + * return CustomAttributeCategory */ public function GetCategory(); @@ -43,7 +43,7 @@ public function GetEntityIds(); public function GetPossibleValues(); /** - * return int|CustomAttributeCategory + * return CustomAttributeCategory */ public function GetRequestedCategory(); @@ -63,7 +63,7 @@ public function GetIsAdminOnly(); public function BindAttributes($attributes); /** - * @param $categoryId int|CustomAttributeCategory + * @param $categoryId CustomAttributeCategory */ public function SetCategory($categoryId); @@ -78,7 +78,7 @@ public function GetAttributeId(); public function GetSecondaryEntityIds(); /** - * @return CustomAttributeCategory|int|null + * @return CustomAttributeCategory|null */ public function GetSecondaryCategory(); diff --git a/Pages/Admin/ManageResourcesPage.php b/Pages/Admin/ManageResourcesPage.php index c137536d1..3e117b7e6 100644 --- a/Pages/Admin/ManageResourcesPage.php +++ b/Pages/Admin/ManageResourcesPage.php @@ -1323,7 +1323,7 @@ public function AsFilter($customAttributes) $idEquals = new SqlFilterEquals($attributeId, $id); $f->AppendSql('LEFT JOIN `' . TableNames::CUSTOM_ATTRIBUTE_VALUES . '` `a' . $id . '` ON `a0`.`entity_id` = `a' . $id . '`.`entity_id` '); - if ($attribute->Type() == CustomAttributeTypes::MULTI_LINE_TEXTBOX || $attribute->Type() == CustomAttributeTypes::SINGLE_LINE_TEXTBOX) { + if ((int)$attribute->Type() === CustomAttributeTypes::MULTI_LINE_TEXTBOX || (int)$attribute->Type() === CustomAttributeTypes::SINGLE_LINE_TEXTBOX) { $attributeFragment->_And($idEquals->_And(new SqlFilterLike($attributeValue, $value))); } else { $attributeFragment->_And($idEquals->_And(new SqlFilterEquals($attributeValue, $value))); diff --git a/WebServices/Controllers/AttributeSaveController.php b/WebServices/Controllers/AttributeSaveController.php index 9a221e3fd..76da161cc 100644 --- a/WebServices/Controllers/AttributeSaveController.php +++ b/WebServices/Controllers/AttributeSaveController.php @@ -169,24 +169,26 @@ private function ValidateRequest($request) $errors[] = 'label is required'; } - if ($request->type != CustomAttributeTypes::CHECKBOX && - $request->type != CustomAttributeTypes::MULTI_LINE_TEXTBOX && - $request->type != CustomAttributeTypes::SELECT_LIST && - $request->type != CustomAttributeTypes::SINGLE_LINE_TEXTBOX + if ((int)$request->type !== CustomAttributeTypes::CHECKBOX && + (int)$request->type !== CustomAttributeTypes::MULTI_LINE_TEXTBOX && + (int)$request->type !== CustomAttributeTypes::SELECT_LIST && + (int)$request->type !== CustomAttributeTypes::SINGLE_LINE_TEXTBOX && + (int)$request->type !== CustomAttributeTypes::DATETIME ) { $errors[] = sprintf( - 'type is invalid. Allowed values for type: %s (checkbox), %s (multi line), %s (select list), %s (single line)', + 'type is invalid. Allowed values for type: %s (checkbox), %s (multi line), %s (select list), %s (single line), %s (datetime)', CustomAttributeTypes::CHECKBOX, CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeTypes::SELECT_LIST, - CustomAttributeTypes::SINGLE_LINE_TEXTBOX + CustomAttributeTypes::SINGLE_LINE_TEXTBOX, + CustomAttributeTypes::DATETIME ); } - if ($request->categoryId != CustomAttributeCategory::RESERVATION && - $request->categoryId != CustomAttributeCategory::RESOURCE && - $request->categoryId != CustomAttributeCategory::RESOURCE_TYPE && - $request->categoryId != CustomAttributeCategory::USER + if ((int)$request->categoryId !== CustomAttributeCategory::RESERVATION && + (int)$request->categoryId !== CustomAttributeCategory::RESOURCE && + (int)$request->categoryId !== CustomAttributeCategory::RESOURCE_TYPE && + (int)$request->categoryId !== CustomAttributeCategory::USER ) { $errors[] = sprintf( 'categoryId is invalid. Allowed values for category: %s (reservation), %s (resource), %s (resource type), %s (user)', @@ -197,15 +199,15 @@ private function ValidateRequest($request) ); } - if ($request->type == CustomAttributeTypes::SELECT_LIST && empty($request->possibleValues)) { + if ((int)$request->type === CustomAttributeTypes::SELECT_LIST && empty($request->possibleValues)) { $errors[] = 'possibleValues is required when the type is a select list'; } - if ($request->type != CustomAttributeTypes::SELECT_LIST && !empty($request->possibleValues)) { + if ((int)$request->type !== CustomAttributeTypes::SELECT_LIST && !empty($request->possibleValues)) { $errors[] = 'possibleValues is only valid when the type is a select list'; } - if ($request->categoryId == CustomAttributeCategory::RESERVATION && !empty($request->appliesToIds)) { + if ((int)$request->categoryId === CustomAttributeCategory::RESERVATION && !empty($request->appliesToIds)) { $errors[] = 'appliesToId is not valid when the type is reservation'; } diff --git a/lib/Application/Attributes/AttributeService.php b/lib/Application/Attributes/AttributeService.php index 31fbe4322..7a1bb2275 100644 --- a/lib/Application/Attributes/AttributeService.php +++ b/lib/Application/Attributes/AttributeService.php @@ -231,9 +231,9 @@ public function GetReservationAttributes(UserSession $userSession, ReservationVi $secondaryCategory = $attribute->SecondaryCategory(); if (empty($secondaryCategory) || ( - $secondaryCategory == CustomAttributeCategory::USER && + (int)$secondaryCategory === CustomAttributeCategory::USER && $this->AvailableForUser($userSession, $requestedUserId, $secondaryCategory, $attribute) || - (($secondaryCategory == CustomAttributeCategory::RESOURCE || $secondaryCategory == CustomAttributeCategory::RESOURCE_TYPE) + (((int)$secondaryCategory === CustomAttributeCategory::RESOURCE || (int)$secondaryCategory === CustomAttributeCategory::RESOURCE_TYPE) && $this->AvailableForResource($userSession, $secondaryCategory, $attribute, $requestedResourceIds)) ) ) { @@ -276,8 +276,8 @@ private function AvailableForUser(UserSession $userSession, $requestedUserId, $s */ private function AvailableForResource($userSession, $secondaryCategory, $attribute, $requestedResourceIds) { - if ($secondaryCategory == CustomAttributeCategory::RESOURCE || $secondaryCategory == CustomAttributeCategory::RESOURCE_TYPE) { - if ($secondaryCategory == CustomAttributeCategory::RESOURCE) { + if ((int)$secondaryCategory === CustomAttributeCategory::RESOURCE || (int)$secondaryCategory === CustomAttributeCategory::RESOURCE_TYPE) { + if ((int)$secondaryCategory === CustomAttributeCategory::RESOURCE) { $applies = array_intersect($attribute->SecondaryEntityIds(), $requestedResourceIds); $allowed = array_intersect($attribute->SecondaryEntityIds(), array_keys($this->GetAllowedResources($userSession))); diff --git a/lib/Application/Reservation/Validation/CustomAttributeValidationRule.php b/lib/Application/Reservation/Validation/CustomAttributeValidationRule.php index ec5382d99..99c580523 100644 --- a/lib/Application/Reservation/Validation/CustomAttributeValidationRule.php +++ b/lib/Application/Reservation/Validation/CustomAttributeValidationRule.php @@ -38,15 +38,15 @@ public function Validate($reservationSeries, $retryParameters) $secondaryCategory = $invalidAttribute->Attribute->SecondaryCategory(); $secondaryEntityIds = $invalidAttribute->Attribute->SecondaryEntityIds(); - if ($secondaryCategory == CustomAttributeCategory::USER && !in_array($reservationSeries->UserId(), $secondaryEntityIds)) { + if ((int)$secondaryCategory === CustomAttributeCategory::USER && !in_array($reservationSeries->UserId(), $secondaryEntityIds)) { // the attribute applies to a different user continue; } - if ($secondaryCategory == CustomAttributeCategory::RESOURCE && count(array_intersect($secondaryEntityIds, $reservationSeries->AllResourceIds())) == 0) { + if ((int)$secondaryCategory === CustomAttributeCategory::RESOURCE && count(array_intersect($secondaryEntityIds, $reservationSeries->AllResourceIds())) == 0) { // the attribute is not for a resource that is being booked continue; } - if ($secondaryCategory == CustomAttributeCategory::RESOURCE_TYPE) { + if ((int)$secondaryCategory === CustomAttributeCategory::RESOURCE_TYPE) { $appliesToResourceType = false; foreach ($reservationSeries->AllResources() as $resource) { if ($appliesToResourceType) { diff --git a/lib/Application/Schedule/ScheduleResourceFilter.php b/lib/Application/Schedule/ScheduleResourceFilter.php index 8a67d9bf1..197b61d72 100644 --- a/lib/Application/Schedule/ScheduleResourceFilter.php +++ b/lib/Application/Schedule/ScheduleResourceFilter.php @@ -160,9 +160,9 @@ public function FilterResources($resources, IResourceRepository $resourceReposit } /** - * @param Attribute[] $attributes + * @param LBAttribute[] $attributes * @param int $attributeId - * @return null|Attribute + * @return null|LBAttribute */ private function GetAttribute($attributes, $attributeId) { @@ -176,7 +176,7 @@ private function GetAttribute($attributes, $attributeId) /** * @param AttributeValue $attribute - * @param Attribute $value + * @param LBAttribute $value * @return bool */ private function AttributeValueMatches($attribute, $value) @@ -185,7 +185,7 @@ private function AttributeValueMatches($attribute, $value) return false; } - if ($value->Type() == CustomAttributeTypes::SINGLE_LINE_TEXTBOX || $value->Type() == CustomAttributeTypes::MULTI_LINE_TEXTBOX) { + if ((int)$value->Type() == CustomAttributeTypes::SINGLE_LINE_TEXTBOX || (int)$value->Type() == CustomAttributeTypes::MULTI_LINE_TEXTBOX) { return strripos($value->Value() ?? "", $attribute->Value) !== false; } elseif (is_numeric($value->Value())) { return floatval($value->Value()) == $attribute->Value; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index aa376af4a..d49e694a9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -96,24 +96,6 @@ parameters: count: 1 path: lib/Application/Schedule/ReservationService.php - - - message: '#^Call to an undefined method Attribute\:\:Id\(\)\.$#' - identifier: method.notFound - count: 1 - path: lib/Application/Schedule/ScheduleResourceFilter.php - - - - message: '#^Call to an undefined method Attribute\:\:Type\(\)\.$#' - identifier: method.notFound - count: 2 - path: lib/Application/Schedule/ScheduleResourceFilter.php - - - - message: '#^Call to an undefined method Attribute\:\:Value\(\)\.$#' - identifier: method.notFound - count: 4 - path: lib/Application/Schedule/ScheduleResourceFilter.php - - message: '#^PHPDoc tag @return with type Server is not subtype of native type IRestServer\|null\.$#' identifier: return.phpDocType