Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if -> switch? #2

Open
VladislavSournine opened this issue Apr 11, 2011 · 1 comment
Open

if -> switch? #2

VladislavSournine opened this issue Apr 11, 2011 · 1 comment

Comments

@VladislavSournine
Copy link

Hi!

What do you think about using switch (not if) in read function? More readable, more fast (if you need to use a lot of api/params). Less chance to make error when adding other "if". What do you think?

function read($model, $queryData = array()) {
    switch ($queryData['fields']) {
        case 'people' : if (!empty($queryData['conditions']['username'])) {
                                $url = 'flickr.people.findByUsername&' . $this->_buildParams(array(
                                    'username',
                                ), $queryData, true);}
                                break;
        case 'photos' : if (!empty($queryData['conditions']['photoset_id'])) {
                                $url = 'flickr.photosets.getPhotos&' . $this->_buildParams(array(
                                    'photoset_id',
                                ), $queryData, true);}
                                break;
        case 'sizes' : if (!empty($queryData['conditions']['photo_id'])) {
                                $url = 'flickr.photos.getSizes&' . $this->_buildParams(array(
                                    'photo_id',
                                ), $queryData, true);}
                                break;
        case 'sets' : if (!empty($queryData['conditions']['user_id'])) {
                                $url = 'flickr.photosets.getList&' . $this->_buildParams(array(
                                    'photo_id',
                                ), $queryData, true);}
                                break;
        default:
    }
    return $this->_request($url);
}
@ProLoser
Copy link
Member

I'm testing a rewrite on the last push that actually completely optimizes the code even further. I have thought of using a switch, and with the fields comparison part at the very least it's not ruled out.

Unfortunately I haven't taken the time to look at the write actions (Insert, Update, Delete) yet to determine if this new approach will work for them too.

I highly recommend taking a glance at the new code and if you wish you can fill out the (plenty) missing api methods I haven't bothered to get to yet in the config file

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

No branches or pull requests

2 participants