New answers tagged

0

As others have said The [Facade pattern][1] is an obvious way to go. To add to the answers thought I'd like to say you need to think carefully about the semantics of the API you are trying to wrap when creating the simpler Facade. Syntax is the easy part. For example your API may require an initialisation function followed by functions which actually do the ...


1

If instead of: $result = (object) ['isfound' => null, 'issubscribed' => null]; the initial values were: $result = (object) ['isfound' => false, 'issubscribed' => false]; most of the other code could be simplified. E.g. if (!($found->data->recipient_count > 0)) { $result->isfound = false; $result->issubscribed = false; ...


1

This is a good use case for using Exception, if the language supports exception. You can just write: public function getSubscriberStatus(string $email): object { $endpoint = "contactdb/recipients/search?email=$email"; $found = $this->urlget($endpoint, 200); // this validation is probably unnecessary, looping over empty object has the same ...


2

Your example is not the much maligned "magic string", rather its a bit like a Translation Dictionary, where you supply the dict key (which is a string) and get back a value. Now, your code is not ideal because I could mistype string value "$globl.name" and not know until runtime that I messed up, but that's not the worst thing in the world. Here's an ...


0

There is no such thing as a "magic string" all the definitions on the web would be better called "hard-coded values" A magic number is a hard-coded value that has no relation to the information it is encoding. int Port = 80 // hard-coded value, literally the value to use for the port where UserType == 7 // magic number You don't get magic strings because ...


Top 50 recent answers are included