Skip to content

Commit 570e9e4

Browse files
committed
chore(stan): update & fix issue
1 parent 3473017 commit 570e9e4

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

phpstan.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ parameters:
22
level: max
33
paths:
44
- lib
5+
- public
56
ignoreErrors:
67
- identifier: missingType.iterableValue
78
phpVersion:
8-
min: 80100 # PHP 8.1.0
9+
min: 80000 # PHP 8.0.0
910
max: 80410 # PHP 8.4.10
1011
treatPhpDocTypesAsCertain: false

public/index.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
use GraphQL\Error\DebugFlag;
1717

1818
// Disable default PHP error reporting - we have better one for debug mode (see bellow)
19-
ini_set('display_errors', 0);
19+
ini_set('display_errors', '0');
2020

21-
$debug = false;
21+
$debug = DebugFlag::NONE;
2222
if (!empty($_GET['debug'])) {
23-
set_error_handler(function ($severity, $message, $file, $line) use (&$phpErrors) {
23+
set_error_handler(function ($severity, $message, $file, $line) {
2424
throw new ErrorException($message, 0, $severity, $file, $line);
2525
});
2626
$debug = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE;
@@ -33,16 +33,18 @@
3333
// Prepare context that will be available in all field resolvers (as 3rd argument):
3434
$appContext = new AppContext();
3535
$appContext->viewer = '';
36-
$appContext->rootUrl = $_SERVER['REQUEST_URI'];
36+
$appContext->rootUrl = $_SERVER['REQUEST_URI']; // @phpstan-ignore assign.propertyType
3737
$appContext->request = $_REQUEST;
3838

3939
// Parse incoming query and variables
40-
if (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
40+
if (
41+
isset($_SERVER['CONTENT_TYPE'])
42+
&& is_string($_SERVER['CONTENT_TYPE'])
43+
&& strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false
44+
) {
4145
$raw = file_get_contents('php://input') ?: '';
42-
$data = json_decode($raw, true);
43-
}
44-
45-
if (is_null($data)) {
46+
$data = (array)json_decode($raw, true);
47+
} else {
4648
$data = $appContext->request;
4749
}
4850

@@ -53,18 +55,26 @@
5355

5456
$result = GraphQL::executeQuery(
5557
$schema,
56-
$data['query'],
58+
$data['query'], // @phpstan-ignore argument.type
5759
null,
5860
$appContext,
59-
array_key_exists('variables', $data) ? $data['variables'] : []
61+
array_key_exists('variables', $data) ? $data['variables'] : [] // @phpstan-ignore argument.type
6062
);
6163
$output = $result->toArray($debug);
6264
$httpStatus = 200;
6365
} catch (\Exception $error) {
6466
$httpStatus = 500;
65-
$output['errors'] = [
67+
$errors = [
6668
FormattedError::createFromException($error, $debug)
6769
];
70+
71+
if (isset($output) && is_array($output)) {
72+
$output['errors'] = $errors;
73+
} else {
74+
$output = [
75+
'errors' => $errors
76+
];
77+
}
6878
}
6979

7080
header('Content-Type: application/json', true, $httpStatus);

tests/FilmTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
final class FilmTest extends TestCase
1212
{
13-
public static function filmData()
13+
/**
14+
* @return array<array<array<string, mixed>>>
15+
*/
16+
public static function filmData(): array
1417
{
1518
return [
1619
[
@@ -36,7 +39,7 @@ public static function filmData()
3639
}
3740

3841
#[DataProvider('filmData')]
39-
public function testFilm(array $data)
42+
public function testFilm(array $data): void
4043
{
4144
$film = new Film($data);
4245

0 commit comments

Comments
 (0)