Skip to content

if -> switch? #2

@VladislavSournine

Description

@VladislavSournine

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions