-
-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathErrorHelper.php
More file actions
33 lines (28 loc) · 734 Bytes
/
ErrorHelper.php
File metadata and controls
33 lines (28 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php declare(strict_types=1);
namespace GraphQL\Tests;
use GraphQL\Language\SourceLocation;
/**
* @phpstan-type ErrorArray array{
* message: string,
* locations?: array<int, array{line: int, column: int}>
* }
*/
final class ErrorHelper
{
/**
* @param array<SourceLocation> $locations
*
* @phpstan-return ErrorArray
*/
public static function create(string $error, array $locations = []): array
{
$formatted = ['message' => $error];
if ($locations !== []) {
$formatted['locations'] = array_map(
static fn (SourceLocation $loc): array => $loc->toArray(),
$locations
);
}
return $formatted;
}
}