@@ -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 ($ entity !== IEntity::class && !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,23 @@ 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+ if (strlen ($ operation ) > IManager::MAX_OPERATION_VALUE_BYTES ) {
464+ throw new \UnexpectedValueException ($ this ->l ->t ('The provided operation data is too long ' ));
465+ }
466+
467+ /** @psalm-suppress TaintedCallable newInstance is not called */
468+ $ reflection = new \ReflectionClass ($ class );
469+ if ($ class !== IOperation::class && !in_array (IOperation::class, $ reflection ->getInterfaceNames ())) {
470+ throw new \UnexpectedValueException ($ this ->l ->t ('Operation %s is invalid ' , [$ class ]) . join (', ' , $ reflection ->getInterfaceNames ()));
471+ }
472+
461473 try {
462474 /** @var IOperation $instance */
463475 $ instance = $ this ->container ->get ($ class );
464476 } catch (ContainerExceptionInterface $ e ) {
465477 throw new \UnexpectedValueException ($ this ->l ->t ('Operation %s does not exist ' , [$ class ]));
466478 }
467479
468- if (!($ instance instanceof IOperation)) {
469- throw new \UnexpectedValueException ($ this ->l ->t ('Operation %s is invalid ' , [$ class ]));
470- }
471-
472480 if (!$ instance ->isAvailableForScope ($ scope ->getScope ())) {
473481 throw new \UnexpectedValueException ($ this ->l ->t ('Operation %s is invalid ' , [$ class ]));
474482 }
@@ -479,38 +487,35 @@ public function validateOperation(string $class, string $name, array $checks, st
479487 throw new \UnexpectedValueException ($ this ->l ->t ('At least one check needs to be provided ' ));
480488 }
481489
482- if (strlen ($ operation ) > IManager::MAX_OPERATION_VALUE_BYTES ) {
483- throw new \UnexpectedValueException ($ this ->l ->t ('The provided operation data is too long ' ));
484- }
485-
486490 $ instance ->validateOperation ($ name , $ checks , $ operation );
487491
488492 foreach ($ checks as $ check ) {
489493 if (!is_string ($ check ['class ' ])) {
490494 throw new \UnexpectedValueException ($ this ->l ->t ('Invalid check provided ' ));
491495 }
492496
497+ if (strlen ((string )$ check ['value ' ]) > IManager::MAX_CHECK_VALUE_BYTES ) {
498+ throw new \UnexpectedValueException ($ this ->l ->t ('The provided check value is too long ' ));
499+ }
500+
501+ $ reflection = new \ReflectionClass ($ check ['class ' ]);
502+ if ($ check ['class ' ] !== ICheck::class && !in_array (ICheck::class, $ reflection ->getInterfaceNames ())) {
503+ throw new \UnexpectedValueException ($ this ->l ->t ('Check %s is invalid ' , [$ class ]));
504+ }
505+
493506 try {
494507 /** @var ICheck $instance */
495508 $ instance = $ this ->container ->get ($ check ['class ' ]);
496509 } catch (ContainerExceptionInterface ) {
497510 throw new \UnexpectedValueException ($ this ->l ->t ('Check %s does not exist ' , [$ class ]));
498511 }
499512
500- if (!($ instance instanceof ICheck)) {
501- throw new \UnexpectedValueException ($ this ->l ->t ('Check %s is invalid ' , [$ class ]));
502- }
503-
504513 if (!empty ($ instance ->supportedEntities ())
505514 && !in_array ($ entity , $ instance ->supportedEntities ())
506515 ) {
507516 throw new \UnexpectedValueException ($ this ->l ->t ('Check %s is not allowed with this entity ' , [$ class ]));
508517 }
509518
510- if (strlen ((string )$ check ['value ' ]) > IManager::MAX_CHECK_VALUE_BYTES ) {
511- throw new \UnexpectedValueException ($ this ->l ->t ('The provided check value is too long ' ));
512- }
513-
514519 $ instance ->validateCheck ($ check ['operator ' ], $ check ['value ' ]);
515520 }
516521 }
0 commit comments