Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

code duplication in Query:_render_* methods #35

Closed
DarkSide666 opened this issue Mar 22, 2016 · 4 comments
Closed

code duplication in Query:_render_* methods #35

DarkSide666 opened this issue Mar 22, 2016 · 4 comments
Assignees

Comments

@DarkSide666
Copy link
Member

This piece of code is found in _render_where, _render_orwhere, _render_andwhere, _render_having:

        if (!isset($this->args['where'])) {
            return;
        }

It can me moved to __render_where method to not duplicate code:

        if (!isset($this->args[$kind])) {
            return;
        }

and in previously mentioned methods do simply like this:

    protected function _render_orwhere()
    {
        $ret = $this->__render_where('where');
        return $ret ? implode(' or ', $ret) : null;
    }
@romaninsh romaninsh self-assigned this Apr 8, 2016
@romaninsh
Copy link
Member

I have commented on this i think, but just in case - we can't move this into __render_where, because the wrapping methods would typically prepend " having", " where" and if there are no clauses at all, we should return null, that's why this check is done on the top-level.

@DarkSide666
Copy link
Member Author

not sure I understood your comment :)

        $ret = $this->__render_where('where');
        return $ret ? implode(' or ', $ret) : null;

should do that same thing.

@romaninsh
Copy link
Member

Yeah, but I've read in the code developer guidelines to return from methods early if possible.

It's not a huge deal really. Plus all of the _render() methods have the same code to return 'null' if their presence is not needed. Perhaps we can even move it to render() method, but I'm not sure at this time if it can create more problems or not.

When in doubt, leave as-is.

@DarkSide666
Copy link
Member Author

I agree.

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

No branches or pull requests

2 participants