Skip to content

Commit

Permalink
Fix issues found by Psalm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten Staa committed Oct 29, 2020
1 parent d7b81c1 commit 0bf4508
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/Actions/SendTracingToApollo.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ private function transformTracing(TracingResult $tracingResult): Trace
return empty($error['path']) || empty($tracingResult->tracing['execution']['resolvers']);
})
);
/** @var Trace\Node|null $rootNode */
$rootNode = $result->getRoot();
if ($rootNode === null) {
$result->setRoot($rootNode = new Trace\Node([
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/RegisterSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function handle(): void

$response = ($this->sendSchemaToApollo($variables));
if (!empty($response['errors'])) {
throw new RegisterSchemaFailedException(implode(', ', array_map(function ($error) {
throw new RegisterSchemaFailedException(implode(', ', array_map(function (array $error): string {
return $error['message'];
}, $response['errors'])));
}
Expand All @@ -110,7 +110,7 @@ public function handle(): void
}

/**
* @param array $variables
* @param UploadSchemaVariables $variables
* @return array
* @throws RegisterSchemaRequestFailedException
* @throws JsonException
Expand All @@ -135,7 +135,7 @@ protected function sendSchemaToApollo(UploadSchemaVariables $variables): array
$response = curl_exec($request);

$errorCode = curl_errno($request);
if ($errorCode) {
if ($errorCode || !is_string($response)) {
throw new RegisterSchemaRequestFailedException($errorCode, curl_error($request));
}

Expand Down
11 changes: 11 additions & 0 deletions src/Graph/ArrayableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

trait ArrayableTrait
{
/**
* Convert a field to something for an array.
*
* @param mixed $field
* @return mixed
*/
private function mapField($field)
{
if ($field instanceof Arrayable) {
Expand All @@ -24,6 +30,11 @@ private function mapField($field)
return $field;
}

/**
* Get the instance as an array.
*
* @return array
*/
public function toArray(): array
{
return array_map([$this, 'mapField'], get_object_vars($this));
Expand Down
25 changes: 10 additions & 15 deletions src/Listeners/ManipulateResultListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function handle(ManipulateResult $event): void

if (
!isset($event->result->extensions['tracing']) &&
!isset($event->result->errors)
!count($event->result->errors)
) {
return;
}
Expand All @@ -87,7 +87,7 @@ public function handle(ManipulateResult $event): void
$event->result->extensions['tracing'] ?? [],
array_map(function (Error $error) {
return FormattedError::createFromException($error, true);
}, $event->result->errors ?? []),
}, $event->result->errors),
);

$this->removeTracingFromExtensionsIfNeeded($event);
Expand All @@ -100,19 +100,14 @@ public function handle(ManipulateResult $event): void
->send();
} catch (Exception $e) {
// We should probably not cause pain for the end users. Just include this in the extensions instead.
if (!isset($event->result->extensions['errors'])) {
$event->result->extensions['errors'] = [];
}

$event->result->extensions['errors'][] = [
'message' => $e->getMessage(),
'extensions' => array_merge([
'type' => get_class($e),
'code' => $e->getCode(),
], $this->config->get('app.debug') ? [
'trace' => $e->getTraceAsString(),
] : []),
];
$event->result->errors[] = new Error(
'Failed to send tracing to Apollo',
null,
null,
null,
null,
$e
);
}
break;
case 'redis':
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function register(): void
private function bootForConsole(): void
{
$this->publishes([
__DIR__ . '/../config/lighthouse-apollo.php' => config_path('lighthouse-apollo.php')
__DIR__ . '/../config/lighthouse-apollo.php' => $this->app->configPath('lighthouse-apollo.php')
], 'lighthouse-apollo');

$this->commands([
Expand Down
17 changes: 9 additions & 8 deletions src/TracingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ class TracingResult

/**
* @var array{
* duration: int
* endTime: string
* startTime: string
* version: int
* duration: int,
* endTime: string,
* startTime: string,
* version: int,
* execution: array{
* resolvers: array{
* duration: int
* parentType: string
* path: string
* returnType: string
* duration: int,
* fieldName: string,
* parentType: string,
* path: (int|string)[],
* returnType: string,
* startOffset: int
* }[]
* }
Expand Down

0 comments on commit 0bf4508

Please sign in to comment.