Cast getLimit() result to int instead of string
Currently method getLimit() returns string, which is different from PHPDoc. It could affect PHP apps which used declare(strict_types=1);
It could affect PHP apps which used declare(strict_types=1);
As far as I know, docblocks aren't affected by strict_types, only real type hints are?
Yes, you're right declare(strict_types=1) affect only real type hints.
Let me show you my case.
I read PHPDoc of getLimit(), which declared return type as int.
Then I implement some code in project which relay on it
<?php declare(strict_types=1);
class OffsetLimitFilter {
public function __construct(int $limit, int $offset) {
// ..
}
}
Finally I'm trying to pass getLimit() to this class
$parameters = new \Tobscure\JsonApi\Parameters($request->query->all());
$offsetOrderFilter = new OffsetLimitFilter(
$parameters->getLimit() ? (int)$parameters->getLimit() : 10, // Cast to int is necessary due to return value actually is string, and php will throw type error
$parameters->getOffset()
);
If this patch will be applied then source code could be simplified
$parameters = new \Tobscure\JsonApi\Parameters($request->query->all());
$offsetOrderFilter = new OffsetLimitFilter(
$parameters->getLimit() ? : 10, // Cast to int is not necessary
$parameters->getOffset()
);
By all means, I like the change. Sorry for not communicating this clearly. :laughing: