@@ -33,7 +33,7 @@ class IdentityDecorator implements IdentityInterface
3333 /**
3434 * Identity data
3535 *
36- * @var \ArrayAccess|array
36+ * @var \ArrayAccess<string, mixed> |array<string, mixed>
3737 */
3838 protected ArrayAccess |array $ identity ;
3939
@@ -48,7 +48,7 @@ class IdentityDecorator implements IdentityInterface
4848 * Constructor
4949 *
5050 * @param \Authorization\AuthorizationServiceInterface $service The authorization service.
51- * @param \ArrayAccess|array $identity Identity data
51+ * @param \ArrayAccess<string, mixed> |array<string, mixed> $identity Identity data
5252 */
5353 public function __construct (AuthorizationServiceInterface $ service , ArrayAccess |array $ identity )
5454 {
@@ -86,8 +86,7 @@ public function applyScope(string $action, mixed $resource, mixed ...$optionalAr
8686 public function getOriginalData (): ArrayAccess |array
8787 {
8888 if (
89- $ this ->identity
90- && !is_array ($ this ->identity )
89+ is_object ($ this ->identity )
9190 && method_exists ($ this ->identity , 'getOriginalData ' )
9291 ) {
9392 return $ this ->identity ->getOriginalData ();
@@ -100,18 +99,25 @@ public function getOriginalData(): ArrayAccess|array
10099 * Delegate unknown methods to decorated identity.
101100 *
102101 * @param string $method The method being invoked.
103- * @param array $args The arguments for the method.
102+ * @param array<mixed> $args The arguments for the method.
104103 * @return mixed
105104 */
106105 public function __call (string $ method , array $ args ): mixed
107106 {
108107 if (!is_object ($ this ->identity )) {
109108 throw new BadMethodCallException ("Cannot call ` {$ method }`. Identity data is not an object. " );
110109 }
111- $ call = [$ this ->identity , $ method ];
110+
111+ if (!method_exists ($ this ->identity , $ method )) {
112+ throw new BadMethodCallException (sprintf (
113+ 'Method `%s` does not exist on `%s`. ' ,
114+ $ method ,
115+ $ this ->identity ::class,
116+ ));
117+ }
112118
113119 /** @phpstan-ignore callable.nonCallable */
114- return $ call (...$ args );
120+ return [ $ this -> identity , $ method ] (...$ args );
115121 }
116122
117123 /**
0 commit comments