Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Conversation

teldosas
Copy link
Contributor

@teldosas teldosas commented Dec 24, 2016

I made an initial attempt to add full batch support without the BC breaks that #706 introduced. Awaiting review @yguedidi @SammyK . :) I will adjust the docs too in the following days. :)

*
* @param FacebookRequest|array $request
* @param string|null $name
* @param string|null|array $optionsOrName When it is a string it is the name of the request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd name it just $options and describe it like "array of batch request options (e.g. ...). If a string is given, it will be the value of the name option." or something like that :)

return $this;
}

if (null === $optionsOrName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you must check for this one before !is_array($optionsOrName). Currently you will never enter this case

@@ -85,17 +87,35 @@ public function add($request, $name = null)
throw new \InvalidArgumentException('Argument for add() must be of type array or FacebookRequest.');
}

if (!is_array($optionsOrName)) {
$this->add($request, ['name' => $optionsOrName]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just change the $options value here: $options = ['name' => $options];

}

if (null === $optionsOrName) {
$this->add($request, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just change the $options value here: $options = [];

* @param string|null $requestName The name of the request.
* @param string|null $attachedFiles Names of files associated with the request.
* @param FacebookRequest $request The request entity to convert.
* @param string|null|array $requestNameOrOptions If it is a string it is the name of the request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, $options is enough

return $this->requestEntityToBatchArray($request, ['name' => $requestNameOrOptions], $attachedFiles);
}

if (null === $requestNameOrOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, check for this one before !is_array(...)

{

if (!is_array($requestNameOrOptions)) {
return $this->requestEntityToBatchArray($request, ['name' => $requestNameOrOptions], $attachedFiles);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, just change the $options value

}

if (null === $requestNameOrOptions) {
return $this->requestEntityToBatchArray($request, [], $attachedFiles);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, just change the $options value

@teldosas
Copy link
Contributor Author

I made the changes :) @yguedidi

Copy link
Contributor

@yguedidi yguedidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a testBatchRequestsWithNameGetConvertedToAnArray test :)
I think you can add the doc now! Thanks

* @param FacebookRequest $request The request entity to convert.
* @param string|null|array $options Array of batch request options e.g. 'name', 'omit_response_on_success'.
* If a string is given, it is the value of the 'name' option.
* @param string|null $attachedFiles Names of files associated with the request.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra spaces, each "column" should be separated by only one space :)

$options = [];
}

if (!is_array($options)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use elseif here to avoid this if in case $options was null and it become an empty array

@teldosas
Copy link
Contributor Author

I'd add a testBatchRequestsWithNameGetConvertedToAnArray test :)

@yguedidi Don't these two tests (and a few others)

@yguedidi
Copy link
Contributor

@teldosas right! :)

@teldosas
Copy link
Contributor Author

@yguedidi Ok then I made the last changes too. I'll add the docs asap :)

@teldosas
Copy link
Contributor Author

@yguedidi I added the docs. It should be ready now :)


```php
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation here and in the other PHP code examples in this file seems to be off, can we consistently use PSR-2 here instead and indent with 4 spaces?

@teldosas
Copy link
Contributor Author

I fixed the spaces in the examples too @localheinz

@teldosas
Copy link
Contributor Author

@yguedidi @SammyK this should be ready to merge :)

@SammyK
Copy link
Contributor

SammyK commented Jan 16, 2017

Thanks @teldosas! I'll let @yguedidi give the final review and we'll pull it in. :)

Copy link
Contributor

@yguedidi yguedidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SammyK if it looks good to you, you can merge and release :)
Thanks a lot @teldosas!

@teldosas
Copy link
Contributor Author

@yguedidi It's been my pleasure 😄 Now that I think of it again couldn't we have just overloaded the add method to avoid BC? I think it would be cleaner.

@SammyK
Copy link
Contributor

SammyK commented Jan 19, 2017

Sounds good! I'll try to give this a more detailed look tomorrow. I'm curious about the status of #706. I might be able to cherry-pick this one over to master and we could create a new PR with the cleaner API for v6. Thoughts? :)

@teldosas
Copy link
Contributor Author

teldosas commented Jan 19, 2017

@SammyK #706 was approved by @yguedidi before we decide to start a PR with no BCs. What if after you cherry pick this to master we resolve any conflicts with #706 and merge it?

```php
<?php
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is still off, can we adjust?

```php
<?php
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is still off, can we adjust?

## newBatchRequest()
```php
public Facebook\FacebookBatchRequest newBatchRequest(
string|AccessToken|null $accessToken,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is still off, can we adjust?

@@ -62,12 +63,12 @@ Since the `Facebook\FacebookBatchRequest` is extended from the [`Facebook\Facebo
```php
public add(
array|Facebook\FacebookBatchRequest $request,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is still off, can we adjust?

@teldosas
Copy link
Contributor Author

@localheinz done!

@SammyK SammyK merged commit ecab68b into facebookarchive:5.4 Apr 20, 2017
@SammyK
Copy link
Contributor

SammyK commented Apr 20, 2017

Thanks so much for your hard work on this @teldosas! Feel free to send a new PR to the master branch with this feature without worrying about BC if you want to. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants