googleapis / googleapis/google-api-php-client

Google_Http_MediaFileUpload PHPDoc issues?

Open
#1,881 6 comments 1 reaction 0 assignees View on GitHub
type: feature request
Dominant language
PHP
Stars
9.8k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

I've been using Google_Http_MediaFileUpload to upload videos to YouTube. I have no issue with the actual functionalities of the code, only with the type hinting that seems to be incorrect for a lot of the constructor / methods parameters.

#### Code example

The following code is mostly taken from the documentation.

```php
$chunkSizeBytes = 10 * 1024 * 1024; // 10 MB
$fileSize = filesize($videoFile->getRealPath());

$this->googleClient->setDefer(true);

$insertRequest = $ytService->videos->insert(
'snippet,status',
$ytVideo
);

$media = new \Google_Http_MediaFileUpload($this->googleClient, $insertRequest, 'video/*', null, true, $chunkSizeBytes);
$media->setFileSize($fileSize);
```
This works perfectly fine, but triggers a lot of linting warnings from, for example, PHPStan or Intelephense in VSCode, because of the PHPDoc block of `Google_Http_MediaFileUpload` constructor.

Here's the warnings:
> Parameter #2 $request of class Google_Http_MediaFileUpload constructor expects 'Psr\Http\Message\RequestInterface', 'Google_Service_YouTube_Video' given.
> Parameter #4 $data of class Google_Http_MediaFileUpload constructor expects string, null given.
> Parameter #6 $chunkSize of class Google_Http_MediaFileUpload constructor expects bool, int given.

For the first, I'm not really sure what's the issue here. Using the result of `$ytService->videos->insert` is what the doc says to do, but the returned type is not compatible at all (but it works when it actually runs, so it's correct...)

Is it intentional that `$chunkSize` is defined as a bool (seems weird to me, but maybe there's a reason)? `$data` should also specify `|null`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.