2 ms·
Not a big fan of the API here. I had a teacher that called this "knocking", so that's what I call it. It's better known though as the Sequential Coupling Antip
by donatj 10y ago
Not a big fan of the API here.
I had a teacher that called this "knocking", so that's what I call it. It's better known though as the Sequential Coupling Antipattern[1].
e.g.: Requiring methods to be called in a particular order.
The following works:
$editor = Grafika\Grafika::createEditor();
$editor->open( "/Users/jdonat/Desktop/Screen Shot 2016-07-25 at 11.33.53 AM.png" );
$editor->resizeExact( 200, 200 );
$editor->save( "edited.jpg", null, 90 );
Whereas this throws `Fatal error: Uncaught exception 'Exception' with message 'No image to edit.' in /private/tmp/grafika/src/Grafika/Gd/Editor.php on line 1056`
$editor = Grafika\Grafika::createEditor();
$editor->resizeExact( 200, 200 );
$editor->open( "/Users/jdonat/Desktop/Screen Shot 2016-07-25 at 11.33.53 AM.png" );
$editor->save( "edited.jpg", null, 90 );
Required parameters should be required on the constructor, not on a setter. That's basically just requiring someone to know your secret handshake to use your API.
I'd say in general you'd be better off restructuring this to defer GD/ImgMagick selection until it's actually needed, eg: calling save. I'd personally defer applying any of the filters until save.
Also the static factory is gross and old-school php, I'd avoid that.
1. https://en.wikipedia.org/wiki/Sequential_coupling https://en.wikipedia.org/wiki/Sequential_coupling
- ec109685 10y agoRAII is another way of putting this. You could use a builder pattern to setup your class, build it and then start deriving value from the object. Mutable objects that incorporate behavior are largely evil.
- reitanqild 10y agoWhat about when you want to resize multilple images using the same editor then?