We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 17 | class AccessResolver |
||
| 18 | { |
||
| 19 | /** @var PromiseAdapter */ |
||
| 20 | private $promiseAdapter; |
||
| 21 | |||
| 22 | 98 | public function __construct(PromiseAdapter $promiseAdapter) |
|
| 26 | |||
| 27 | 11 | public function resolve(callable $accessChecker, callable $resolveCallback, array $resolveArgs = [], $useStrictAccess = false) |
|
| 28 | { |
||
| 29 | if ($useStrictAccess || self::isMutationRootField($resolveArgs[3])) { |
||
| 30 | 11 | return $this->checkAccessForStrictMode($accessChecker, $resolveCallback, $resolveArgs); |
|
| 31 | 3 | } |
|
| 32 | 1 | ||
| 33 | $result = \call_user_func_array($resolveCallback, $resolveArgs); |
||
| 34 | |||
| 35 | 2 | if ($result instanceof Promise) { |
|
|
|
|||
| 36 | $result = $result->adoptedPromise; |
||
| 37 | 10 | } |
|
| 38 | |||
| 39 | if ($this->promiseAdapter->isThenable($result) || $result instanceof SyncPromise) { |
||
| 40 | 8 | return $this->promiseAdapter->then( |
|
| 41 | new Promise($result, $this->promiseAdapter), |
||
| 42 | function ($result) use ($accessChecker, $resolveArgs) { |
||
| 43 | 10 | return $this->processFilter($result, $accessChecker, $resolveArgs); |
|
| 44 | } |
||
| 45 | 10 | ); |
|
| 46 | 10 | } |
|
| 47 | 1 | ||
| 48 | return $this->processFilter($result, $accessChecker, $resolveArgs); |
||
| 49 | } |
||
| 50 | 10 | ||
| 51 | 1 | private static function isMutationRootField(ResolveInfo $info): bool |
|
| 52 | 1 | { |
|
| 53 | return 'mutation' === $info->operation->operation && $info->parentType === $info->schema->getMutationType(); |
||
| 54 | 1 | } |
|
| 55 | 1 | ||
| 56 | private function checkAccessForStrictMode(callable $accessChecker, callable $resolveCallback, array $resolveArgs = []) |
||
| 57 | { |
||
| 58 | if (!$this->hasAccess($accessChecker, $resolveArgs)) { |
||
| 59 | 10 | $exceptionClassName = self::isMutationRootField($resolveArgs[3]) ? UserError::class : UserWarning::class; |
|
| 60 | throw new $exceptionClassName('Access denied to this field.'); |
||
| 61 | } |
||
| 62 | 10 | ||
| 63 | return \call_user_func_array($resolveCallback, $resolveArgs); |
||
| 64 | } |
||
| 65 | 10 | ||
| 66 | private function processFilter($result, $accessChecker, $resolveArgs) |
||
| 90 | 11 | ||
| 91 | private function hasAccess(callable $accessChecker, array $resolveArgs = [], $object = null): bool |
||
| 92 | 11 | { |
|
| 93 | $resolveArgs[] = $object; |
||
| 98 | } |
||
| 99 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.