-
Notifications
You must be signed in to change notification settings - Fork 335
fix: Update type comparisons to strict equality for CustomAttributeTy… #974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,12 +13,12 @@ public function GetLabel(); | |||||
|
|
||||||
| /** | ||||||
| * @abstract | ||||||
| * return int|CustomAttributeTypes | ||||||
| * return CustomAttributeTypes | ||||||
| */ | ||||||
| public function GetType(); | ||||||
|
|
||||||
| /** | ||||||
| * return int|CustomAttributeCategory | ||||||
| * return CustomAttributeCategory | ||||||
| */ | ||||||
| public function GetCategory(); | ||||||
|
Comment on lines
14
to
23
|
||||||
|
|
||||||
|
|
@@ -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 | ||||||
|
||||||
| * @return CustomAttributeCategory|null | |
| * @return int|null |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Comment on lines
+172
to
+176
|
||
| ) { | ||
| $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)) { | ||
|
Comment on lines
172
to
210
|
||
| $errors[] = 'appliesToId is not valid when the type is reservation'; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Comment on lines
+279
to
281
|
||
| $allowed = array_intersect($attribute->SecondaryEntityIds(), array_keys($this->GetAllowedResources($userSession))); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||
| } | ||||||||
|
Comment on lines
178
to
186
|
||||||||
|
|
||||||||
| 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) { | ||||||||
|
||||||||
| if ((int)$value->Type() == CustomAttributeTypes::SINGLE_LINE_TEXTBOX || (int)$value->Type() == CustomAttributeTypes::MULTI_LINE_TEXTBOX) { | |
| $type = (int)$value->Type(); | |
| if ($type === CustomAttributeTypes::SINGLE_LINE_TEXTBOX || $type === CustomAttributeTypes::MULTI_LINE_TEXTBOX) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WithSecondaryEntitiesuses(int)$this->category != ...which is still a non-strict comparison. For consistency with the rest of this PR (and to avoid loose-comparison surprises), change this to strict!==(keeping the cast if needed).