Skip to content

Commit 051faab

Browse files
committed
Fix PHPStan
1 parent 7052c81 commit 051faab

10 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/Type/Definition/CustomScalarType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ public function assertValid(): void
101101
throw new InvariantViolation("{$this->name} must provide \"parseValue\" and \"parseLiteral\" functions, \"serialize\" function, or both.");
102102
}
103103

104-
// @phpstan-ignore-next-line not necessary according to types, but can happen during runtime
104+
// @phpstan-ignore-next-line unnecessary according to types, but can happen during runtime
105105
if ($hasSerialize && ! is_callable($serialize)) {
106106
$notCallable = Utils::printSafe($serialize);
107107
throw new InvariantViolation("{$this->name} must provide \"serialize\" as a callable if given, but got: {$notCallable}.");
108108
}
109109

110-
// @phpstan-ignore-next-line not necessary according to types, but can happen during runtime
110+
// @phpstan-ignore-next-line unnecessary according to types, but can happen during runtime
111111
if ($hasParseValue && ! is_callable($parseValue)) {
112112
$notCallable = Utils::printSafe($parseValue);
113113
throw new InvariantViolation("{$this->name} must provide \"parseValue\" as a callable if given, but got: {$notCallable}.");
114114
}
115115

116-
// @phpstan-ignore-next-line not necessary according to types, but can happen during runtime
116+
// @phpstan-ignore-next-line unnecessary according to types, but can happen during runtime
117117
if ($hasParseLiteral && ! is_callable($parseLiteral)) {
118118
$notCallable = Utils::printSafe($parseLiteral);
119119
throw new InvariantViolation("{$this->name} must provide \"parseLiteral\" as a callable if given, but got: {$notCallable}.");

src/Type/Definition/EnumType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function assertValid(): void
222222
{
223223
Utils::assertValidName($this->name);
224224

225-
$values = $this->config['values'] ?? null;
225+
$values = $this->config['values'] ?? null; // @phpstan-ignore nullCoalesce.initializedProperty (unnecessary according to types, but can happen during runtime)
226226
if (! is_iterable($values) && ! is_callable($values)) {
227227
$notIterable = Utils::printSafe($values);
228228
throw new InvariantViolation("{$this->name} values must be an iterable or callable, got: {$notIterable}");

src/Type/Definition/FieldDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function assertValid(Type $parentType): void
238238
throw new InvariantViolation("{$parentType->name}.{$this->name} field type must be Output Type but got: {$safeType}.");
239239
}
240240

241-
// @phpstan-ignore-next-line not necessary according to types, but can happen during runtime
241+
// @phpstan-ignore-next-line unnecessary according to types, but can happen during runtime
242242
if ($this->resolveFn !== null && ! is_callable($this->resolveFn)) {
243243
$safeResolveFn = Utils::printSafe($this->resolveFn);
244244
throw new InvariantViolation("{$parentType->name}.{$this->name} field resolver must be a function if provided, but got: {$safeResolveFn}.");

src/Type/Definition/InputObjectType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function assertValid(): void
181181
{
182182
Utils::assertValidName($this->name);
183183

184-
$fields = $this->config['fields'] ?? null;
184+
$fields = $this->config['fields'] ?? null; // @phpstan-ignore nullCoalesce.initializedProperty (unnecessary according to types, but can happen during runtime)
185185
if (is_callable($fields)) {
186186
$fields = $fields();
187187
}

src/Type/Definition/InterfaceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function assertValid(): void
8585
Utils::assertValidName($this->name);
8686

8787
$resolveType = $this->config['resolveType'] ?? null;
88-
// @phpstan-ignore-next-line not necessary according to types, but can happen during runtime
88+
// @phpstan-ignore-next-line unnecessary according to types, but can happen during runtime
8989
if ($resolveType !== null && ! is_callable($resolveType)) {
9090
$notCallable = Utils::printSafe($resolveType);
9191
throw new InvariantViolation("{$this->name} must provide \"resolveType\" as null or a callable, but got: {$notCallable}.");

src/Type/Definition/ObjectType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function assertValid(): void
154154
Utils::assertValidName($this->name);
155155

156156
$isTypeOf = $this->config['isTypeOf'] ?? null;
157-
// @phpstan-ignore-next-line not necessary according to types, but can happen during runtime
157+
// @phpstan-ignore-next-line unnecessary according to types, but can happen during runtime
158158
if (isset($isTypeOf) && ! is_callable($isTypeOf)) {
159159
$notCallable = Utils::printSafe($isTypeOf);
160160
throw new InvariantViolation("{$this->name} must provide \"isTypeOf\" as null or a callable, but got: {$notCallable}.");

src/Type/Definition/UnionType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function getTypes(): array
8989
if (! isset($this->types)) {
9090
$this->types = [];
9191

92-
$types = $this->config['types'] ?? null;
92+
$types = $this->config['types'] ?? null; // @phpstan-ignore nullCoalesce.initializedProperty (unnecessary according to types, but can happen during runtime)
9393
if (is_callable($types)) {
9494
$types = $types();
9595
}
@@ -120,7 +120,7 @@ public function assertValid(): void
120120
Utils::assertValidName($this->name);
121121

122122
$resolveType = $this->config['resolveType'] ?? null;
123-
// @phpstan-ignore-next-line not necessary according to types, but can happen during runtime
123+
// @phpstan-ignore-next-line unnecessary according to types, but can happen during runtime
124124
if (isset($resolveType) && ! is_callable($resolveType)) {
125125
$notCallable = Utils::printSafe($resolveType);
126126
throw new InvariantViolation("{$this->name} must provide \"resolveType\" as null or a callable, but got: {$notCallable}.");

src/Utils/Utils.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ public static function chr(int $ord, string $encoding = 'UTF-8'): string
116116
return pack('N', $ord);
117117
}
118118

119-
return mb_convert_encoding(self::chr($ord, 'UCS-4BE'), $encoding, 'UCS-4BE');
119+
$converted = mb_convert_encoding(self::chr($ord, 'UCS-4BE'), $encoding, 'UCS-4BE');
120+
assert(is_string($converted), 'format string is statically known to be correct');
121+
122+
return $converted;
120123
}
121124

122125
/** UTF-8 compatible ord(). */
@@ -128,10 +131,13 @@ public static function ord(string $char, string $encoding = 'UTF-8'): int
128131

129132
if ($encoding !== 'UCS-4BE') {
130133
$char = mb_convert_encoding($char, 'UCS-4BE', $encoding);
134+
assert(is_string($char), 'format string is statically known to be correct');
131135
}
132136

133-
// @phpstan-ignore-next-line format string is statically known to be correct
134-
return unpack('N', $char)[1];
137+
$unpacked = unpack('N', $char);
138+
assert(is_array($unpacked), 'format string is statically known to be correct');
139+
140+
return $unpacked[1];
135141
}
136142

137143
/** Returns UTF-8 char code at given $positing of the $string. */

tests/Language/PrinterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testPrintsMinimalAst(): void
4444
/** @see it('produces helpful error messages', () => { */
4545
public function testProducesHelpfulErrorMessages(): void
4646
{
47-
self::markTestSkipped('Not necessary because our class based AST makes it impossible to pass bad data.');
47+
self::markTestSkipped('Unnecessary because our class based AST makes it impossible to pass bad data.');
4848
}
4949

5050
/** @see it('correctly prints non-query operations without name', () => { */

tests/Utils/CoerceInputValueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public function testReturnsNestedNullForNestedNullValues(): void
479479
* @see it('throw error without path', () => {
480480
* @see it('throw error with path', () => {
481481
*
482-
* Not necessary because we do not implement the callback variant coerceInputValue.
482+
* Unnecessary because we do not implement the callback variant coerceInputValue.
483483
*/
484484

485485
/**

0 commit comments

Comments
 (0)