Skip to content

Commit 5504048

Browse files
committed
Separate method to get exceptions for a screen
1 parent 6678c47 commit 5504048

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

‎ProcessMaker/SanitizeHelper.php‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,22 @@ public static function sanitizeData($data, $task)
132132
}
133133

134134
/**
135-
* Sanitize data for a screen instead of a task. Used for start events when no task exists yet.
135+
* Get exceptions for a screen. Used for web entry start events when no task exists yet.
136136
*
137-
* @param array $data
138137
* @param Screen $screen
139138
*
140139
* @return array
141140
*/
142-
public static function sanitizeDataForScreen($data, Screen $screen)
141+
public static function getExceptionsForScreen(Screen $screen)
143142
{
144-
$screens = [
145-
$screen,
146-
...array_map(fn ($id) => Screen::findOrFail($id), $screen->nestedScreenIds()),
147-
];
148-
$except = [];
143+
$screens = collect([$screen]);
144+
$nestedScreens = collect($screen->nestedScreenIds())->map(fn ($id) => Screen::findOrFail($id));
145+
$screens = $screens->concat($nestedScreens);
149146

150-
foreach ($screens as $screen) {
151-
$except = array_merge($except, self::getExceptions($screen));
152-
}
153-
154-
return self::sanitizeWithExceptions($data, $except);
147+
return $screens->flatMap(fn ($screen) => self::getExceptions($screen))->toArray();
155148
}
156149

157-
private static function sanitizeWithExceptions(array $data, array $except, $parent = null)
150+
public static function sanitizeWithExceptions(array $data, array $except, $parent = null)
158151
{
159152
foreach ($data as $key => $value) {
160153
if (!is_int($key)) {

‎tests/Feature/Api/SanitizeHelperTest.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ public function testSanitizeDataForScreen()
323323
],
324324
];
325325

326-
$result = SanitizeHelper::sanitizeDataForScreen($data, $screen);
326+
$exceptions = SanitizeHelper::getExceptionsForScreen($screen);
327+
$result = SanitizeHelper::sanitizeWithExceptions($data, $exceptions);
328+
327329
$this->assertEquals([
328330
'input' => 'foo',
329331
'richtext' => '<h1>bar</h1>',

0 commit comments

Comments
 (0)