arendjantetteroo / guzzle-toggl

A Toggl API client based on guzzle
MIT License
88 stars 42 forks source link

Toggl Numerical ID's Have Exceeded the PHP Maximum Value of 2147483647 #35

Closed lambjs closed 3 months ago

lambjs commented 3 years ago

Example:

use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
use AJT\Toggl\TogglClient;

$config = array(...);
$client_config = TogglClient::getClientConfig($config);
$http_client = new HttpClient($client_config);
$description = TogglClient::getAPIDescriptionByJsonFile('services_v8.json');
$toggl_api = new GuzzleClient($http_client, $description);

$time_entry = array(
    'time_entry' => array(
            'description' => 'Test',
            'wid' => 1234,
            'pid' => 0,
            'start' => '2021-09-01T08:15:30-04:00',
            'duration' => 900,
            'created_with' => 'My Application',
            'tags' => array(),
            'at' => 1630528866
        ),

    'id' => 2152691234
);

$toggl_api->updateTimeEntry($time_entry, $time_entry['id']);

Gets me this ugly looking exception on Guzzl 1.2.1:

Fatal error: Uncaught exception 'GuzzleHttp\Command\Exception\CommandException'
with message 'Validation errors: [id] must be of type integer' in vendor\guzzlehttp\guzzle-services\src\Handler\ValidatedDescriptionHandler.php:76
Stack trace:
#0 vendor\guzzlehttp\command\src\ServiceClient.php(85): GuzzleHttp\Command\Guzzle\Handler\ValidatedDescriptionHandler->GuzzleHttp\Command\Guzzle\Handler\{closure}(Object(GuzzleHttp\Command\Command))
#1 vendor\guzzlehttp\command\src\ServiceClient.php(77): GuzzleHttp\Command\ServiceClient->executeAsync(Object(GuzzleHttp\Command\Command))
#2 vendor\guzzlehttp\command\src\ServiceClient.php(153): GuzzleHttp\Command\ServiceClient->execute(Object(GuzzleHttp\Command\Command))
#3 TogglBillingReport.php(1146): GuzzleHttp\Command\ServiceClient->__call('updateTimeEntry', Array in vendor\guzzlehttp\guzzle-services\src\Handler\ValidatedDescriptionHandler.php on line 76

Note that $time_entry['id'] is stored as a string since its integer value exceeds the maximum 2147483647. It seems that Toggl's ID's have passed the INT threshold.

Are you able to push a change so that internally Guzzle validates this as a numeric string?

Also really hoping you'll apply this to Guzzl 1.2 and 1.3 as I'm still chugging along on PHP 5.6 on this old utility box where this code is deployed (I know... I know...)

arendjantetteroo commented 3 years ago

@lambjs did you try this on a recent version with a supported PHP version?

This sounds like something that is a problem in guzzle itself and not something easily fixable on our end. I'm willing to look at a pull request if you are up for it?

lambjs commented 3 years ago

I think the issue is in services_v8.json. If I understand the docs correctly for the JSON service definitions, then anywhere you've defined the parameter "id", you'll want to change it's type to be ["integer", "string"] so that it accepts either format. You'll also probably want to use the "filters" option to specify a custom callback that applies an is_numeric check on the value.

I don't have time to do the pull request this week. I suspect that this is a major issue that will affect multiple users of your library in the coming weeks.

arendjantetteroo commented 3 years ago

Thanks for that extra information, i'll see what i can do the coming days.

Indeed sounds like an issue others will run into soon.

arendjantetteroo commented 3 months ago

As this didn't get any traction, it seems others are not affected. Closing as not planned