You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have an API that maps the URL to PHP method and the POST JSON data to method arguments, for example curl -XPOST https://mysite/api/device/add -d'{"id": 1, "data": [1,2,3]}' would call
class Device
{
/** @param array<int> $data */functionadd(int$id, array$data)
}
Thanks to PHP strict typing, it checks the type of basic types (int, string, booo) but it does not check content of arrays. We are already using PHPStan to pass static analysis tests and it would be cool to enforce the already existing rules via Nette\Schema.
Using reflection, I can get the phpdoc but there is no way (I think) that I could validate it using Nette/Schema. To accomplish that, a new method fromPhpstanArrayShape(string $shape) (with a much better name) would have to be created.
// this is just a sample with simple array shape but we sometimes use more coplicated ones as well$schema = Expect::fromPhpstanArrayShape('array<int>'); // = Expect::arrayOf('int')$data = [1, 'one', 2];
// this would throw an exception since the second element is not integer$normalized = $processor->process($schema, $data);
Do you think this is something that could be useful?
The text was updated successfully, but these errors were encountered:
We have an API that maps the URL to PHP method and the POST JSON data to method arguments, for example
curl -XPOST https://mysite/api/device/add -d'{"id": 1, "data": [1,2,3]}'
would callThanks to PHP strict typing, it checks the type of basic types (int, string, booo) but it does not check content of arrays. We are already using PHPStan to pass static analysis tests and it would be cool to enforce the already existing rules via Nette\Schema.
Using reflection, I can get the phpdoc but there is no way (I think) that I could validate it using Nette/Schema. To accomplish that, a new method
fromPhpstanArrayShape(string $shape)
(with a much better name) would have to be created.Do you think this is something that could be useful?
The text was updated successfully, but these errors were encountered: