Skip to content

Commit ffe9d83

Browse files
committed
refactor(workflowengine): Check if class is correct
Signed-off-by: Carl Schwan <[email protected]>
1 parent 9d41f4b commit ffe9d83

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

apps/workflowengine/lib/Manager.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,16 +422,18 @@ public function deleteOperation(int $id, ScopeContext $scopeContext): bool {
422422
* @param array $events
423423
*/
424424
protected function validateEvents(string $entity, array $events, IOperation $operation): void {
425+
/** @psalm-suppress TaintedCallable newInstance is not called */
426+
$reflection = new \ReflectionClass($entity);
427+
if (!in_array(IEntity::class, $reflection->getInterfaceNames())) {
428+
throw new \UnexpectedValueException($this->l->t('Entity %s is invalid', [$entity]));
429+
}
430+
425431
try {
426432
$instance = $this->container->get($entity);
427433
} catch (ContainerExceptionInterface $e) {
428434
throw new \UnexpectedValueException($this->l->t('Entity %s does not exist', [$entity]));
429435
}
430436

431-
if (!$instance instanceof IEntity) {
432-
throw new \UnexpectedValueException($this->l->t('Entity %s is invalid', [$entity]));
433-
}
434-
435437
if (empty($events)) {
436438
if (!$operation instanceof IComplexOperation) {
437439
throw new \UnexpectedValueException($this->l->t('No events are chosen.'));
@@ -458,17 +460,19 @@ protected function validateEvents(string $entity, array $events, IOperation $ope
458460
* @throws \UnexpectedValueException
459461
*/
460462
public function validateOperation(string $class, string $name, array $checks, string $operation, ScopeContext $scope, string $entity, array $events): void {
463+
/** @psalm-suppress TaintedCallable newInstance is not called */
464+
$reflection = new \ReflectionClass($class);
465+
if (!in_array(IOperation::class, $reflection->getInterfaceNames())) {
466+
throw new \UnexpectedValueException($this->l->t('Operation %s is invalid', [$class]));
467+
}
468+
461469
try {
462470
/** @var IOperation $instance */
463471
$instance = $this->container->get($class);
464472
} catch (ContainerExceptionInterface $e) {
465473
throw new \UnexpectedValueException($this->l->t('Operation %s does not exist', [$class]));
466474
}
467475

468-
if (!($instance instanceof IOperation)) {
469-
throw new \UnexpectedValueException($this->l->t('Operation %s is invalid', [$class]));
470-
}
471-
472476
if (!$instance->isAvailableForScope($scope->getScope())) {
473477
throw new \UnexpectedValueException($this->l->t('Operation %s is invalid', [$class]));
474478
}

0 commit comments

Comments
 (0)