Skip to content

Commit

Permalink
fix(cr): improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
devmiguelangel committed May 27, 2024
1 parent 478ca10 commit 105c797
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,31 @@ public function assignableUsers()
return new TokenAssignableUsers($query, $this);
}

/**
* Returns either the owner element or its properties
*
* @param asObject Boolean flag that determines whether the function should return the element directly or its
* properties as an object.
*
* @return If the parameter is true, the function will return the object. If is false, the
* function will return the properties of the object.
*/
private function getDefinitionFromOwner($asObject)
{
$element = $this->getOwnerElement();

return $asObject ? $element : $element->getProperties();
}

/**
* Retrieves a specific element's BPMN definition from a request object and returns either the element
* itself or its properties.
*
* @param asObject Boolean flag that determines whether the function should return the BPMN element instance
* as an object or just its properties.
*
* @return If `asObject` is false, the properties of the BPMN element instance are returned.
*/
private function getDefinitionFromRequest($asObject)
{
$request = $this->processRequest ?: $this->getInstance();
Expand Down Expand Up @@ -1172,26 +1190,9 @@ public function reassign($toUserId, User $requestingUser)
event(new ActivityAssigned($this));
}

/**
* Determines the destination URL based on the element destination type specified in the definition.
*
* @return string|null
*/
public function getElementDestinationAttribute(): ?string
private function getElementDestination($elementDestinationType, $elementDestinationProp)
{
$definition = $this->getDefinition();
$elementDestinationProp = $definition['elementDestination'] ?? null;
$elementDestination = null;
$elementDestinationType = null;

try {
$elementDestinationProp = json_decode($elementDestinationProp, true);
if (is_array($elementDestinationProp) && array_key_exists('type', $elementDestinationProp)) {
$elementDestinationType = $elementDestinationProp['type'];
}
} catch (Exception $e) {
return null;
}

switch ($elementDestinationType) {
case 'customDashboard':
Expand Down Expand Up @@ -1227,8 +1228,32 @@ public function getElementDestinationAttribute(): ?string
default:
$elementDestination = null;
break;

}

return $elementDestination;
}

/**
* Determines the destination URL based on the element destination type specified in the definition.
*
* @return string|null
*/
public function getElementDestinationAttribute(): ?string
{
$definition = $this->getDefinition();
$elementDestinationProp = $definition['elementDestination'] ?? null;
$elementDestinationType = null;

try {
$elementDestinationProp = json_decode($elementDestinationProp, true);
if (is_array($elementDestinationProp) && array_key_exists('type', $elementDestinationProp)) {
$elementDestinationType = $elementDestinationProp['type'];
}
} catch (Exception $e) {
return null;
}

return $this->getElementDestination($elementDestinationType, $elementDestinationProp);
}
}

0 comments on commit 105c797

Please sign in to comment.