Skip to content

Conversation

kleisauke
Copy link
Member

@kleisauke kleisauke commented Oct 3, 2016

TODO:

  • Add unit tests for edited functions which are not tested yet (although it's passing now: OK (27 tests, 64 assertions)).
  • Add automatic all the property and method PHPDoc tags.
  • Add automatic constants for common string types (VIPS_INTERPRETATION, VIPS_ANGLE etc.).
src/Image.php Outdated
* @method Image flip($direction, array $options = [])
* @method Image rot($angle, array $options = [])
* @method static Image black(int $width, int $height, array $options = [])
* @method static Image linear(float $a, float $b, array $options = [])
Copy link
Member

@jcupitt jcupitt Oct 4, 2016

Choose a reason for hiding this comment

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

I'm planning to generate most of these automatically from introspection, I wouldn't spend too much time writing them by hand. For example, the Ruby binding has this file:

https://github.com/jcupitt/ruby-vips/blob/master/lib/vips/methods.rb

Generated automatically by this code:

https://github.com/jcupitt/ruby-vips/blob/master/lib/vips/image.rb#L1282

It should be easy to adapt to PHP.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, it should be possible to generate the constants automatically too, I'd leave those.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! Removed mine in the new commit (writing them by hand is hard and time inefficient.)

Copy link
Member

Choose a reason for hiding this comment

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

And makes maintenance harder going forward :( Yes, we should auto-generate as much as we can, I think.

src/Image.php Outdated
* @param Image $match_image Use this image as a guide.
* @param mixed $value Turn this into an image.
* @param Image $match_image Use this image as a guide.
* @param mixed $value Turn this into an image.
Copy link
Member

Choose a reason for hiding this comment

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

phpcs insists on this strange indenting, we probably need to keep it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in the new commit.

src/Image.php Outdated
*/

$arguments = array_merge([$name, $instance], $arguments);
$arguments = array_merge([$name, $instance], $options, $arguments);
Copy link
Member

@jcupitt jcupitt Oct 4, 2016

Choose a reason for hiding this comment

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

I'm getting confused :( Do we really want to make self::call into a varargs function?

How about separating options out as a separate argument, so it's

call(string $name, $instance, array $arguments, array $options = []) : array 

Now when we call it from a method, we can do:

 return self::call($base . "_const", $this, [$op, $other], $options); 

And avoid the array_merge(), at least some of the time.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, we don't need to make self::call into a varargs function! I've fixed it in the new commit.

Sorry about the the confusing.

@kleisauke kleisauke force-pushed the scalar-return-type-declarations-and-phpdoc-fix branch from 6160d29 to 457ffb5 Compare October 5, 2016 09:34
@jcupitt
Copy link
Member

jcupitt commented Oct 5, 2016

Are we ready to merge to dev, do you think? We can leave the tests for another pull request.

src/Image.php Outdated
}

// TODO Unused variable
$height = count($value);
Copy link
Member Author

Choose a reason for hiding this comment

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

This variable is still unused. What should we do with it?

Copy link
Member

Choose a reason for hiding this comment

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

Ooops, yes, let's remove it. It was legft over from an earlier edit.

* @param array $options An array of options to pass to the operation.
*
* @return mixed The result(s) of the operation.
* @return mixed The result(s) of the operation.
Copy link
Member Author

Choose a reason for hiding this comment

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

mixed -> Image|array? Or are the more types that vips_call can return?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, Image::call can return numbers (min() for example), strings, arrays ... lots of stuff.

src/Image.php Outdated
* @param array $options An array of options to pass to the operation.
*
* @return mixed[] The operation result.
* @return Image The operation result.
Copy link
Member Author

Choose a reason for hiding this comment

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

Can _callEnum return a other type than Image? Because call returns mixed.

Copy link
Member

Choose a reason for hiding this comment

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

It'll always be Image at the moment, but it could potentially return anything. It should probaly be mixed to match Vips::call.

@kleisauke
Copy link
Member Author

@jcupitt I think we are ready to merge this to dev. Added a few inline comments.

- Added scalar & return type declarations - Fixed some issues with `array_merge` (libvips#11). - Fixed return and scalar PHPDoc values (long -> int, double -> float, mixed[] -> array). And edited some to the right ones. - Updated PHPUnit. - Corrected some typos. - phpcs indenting fixes.
@kleisauke kleisauke force-pushed the scalar-return-type-declarations-and-phpdoc-fix branch from 457ffb5 to 8ed79bd Compare October 5, 2016 10:19
@kleisauke kleisauke changed the title WIP - Scalar and return type declarations + more Scalar and return type declarations + more Oct 5, 2016
@kleisauke
Copy link
Member Author

@jcupitt _callEnum returns now mixed. And the unused variable is removed. Ready for merging to dev.

@jcupitt jcupitt merged commit 8129b80 into libvips:dev Oct 5, 2016
@jcupitt
Copy link
Member

jcupitt commented Oct 5, 2016

OK, merged! Nice work Kleis!

@kleisauke kleisauke deleted the scalar-return-type-declarations-and-phpdoc-fix branch November 25, 2016 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants