New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHPStan level 7 #1045
PHPStan level 7 #1045
Conversation
Co-authored-by: Simon Podlipsky <simon@podlipsky.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow btw
Co-authored-by: Simon Podlipsky <simon@podlipsky.net>
Co-authored-by: Simon Podlipsky <simon@podlipsky.net>
@simPod anything else before I 🚢 ? |
Nice one, way to kill it 👍 |
@@ -8,6 +8,5 @@ class FloatValueNode extends Node implements ValueNode | |||
{ | |||
public string $kind = NodeKind::FLOAT; | |||
|
|||
/** @var string */ | |||
public $value; | |||
public string $value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the value is not a float
in the FloatValueNode
?
Same for IntValueNode
. For BooleanValueNode
this is fine, the value is a boolean
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of BooleanValueNode
, the PHP type can accurately represent all possible values. However, that is not the case for IntValueNode
or FloatValueNode
- the PHP types are limited in their range, whereas the GraphQL AST is not (see https://spec.graphql.org/draft/#sec-Int-Value - it can be an arbitrarily long sequence of digits, PHP int
is limited to 32 bytes).
Scalar types are based upon those value nodes and impose certain restrictions (see https://spec.graphql.org/draft/#sec-Int), which allows us to parse incoming values of Int
to a native PHP int
(see
graphql-php/src/Type/Definition/IntType.php
Lines 70 to 81 in 7a78690
public function parseLiteral(Node $valueNode, ?array $variables = null): int | |
{ | |
if ($valueNode instanceof IntValueNode) { | |
$val = (int) $valueNode->value; | |
if ($valueNode->value === (string) $val && $val >= self::MIN_INT && $val <= self::MAX_INT) { | |
return $val; | |
} | |
} | |
$notInt = Printer::doPrint($valueNode); | |
throw new Error("Int cannot represent non-integer value: {$notInt}", $valueNode); | |
} |
IntValueNode
which do not fit a PHP int
, e.g. BigInt
.
No description provided.