0

Hi I am using repository pattern PHP and from the controller or the service I need to call 1 after 1 to different repository function

$lists is a list of list objects that comes from DB. the repository pattern is the sample Repository pattern

like :

        $lists = $this->_listRepo->findAllX($this->config["same_config_param"]);
        $arrayToUpdate = $this->someProcess($lists , $statusA);
        $this->updateDBStatus($arrayToUpdate , $statusA);


        $lists = $this->_listRepo->findAllB($this->config["same_config_param"]);
        $arrayToUpdate = $this->someProcess($lists , $statusB);
        $this->updateDBStatus($arrayToUpdate , $statusB);


        $lists = $this->_listRepo->findAnotherCase($this->config["same_config_param"]);
        $arrayToUpdate = $this->someProcess($lists , $statusC);
        $this->updateDBStatus($arrayToUpdate , $statusC);

is there a design pattern to handle it differently and nicely? maybe should I use FACADE?

thanks

2
  • 2
    A function, into which you simply pass the variables (literally, the things that vary in these snippets) as parameters…? Commented Jan 25, 2018 at 16:26
  • did not get you could you share an example ? Commented Jan 25, 2018 at 17:04

1 Answer 1

1

The only difference between those snippets appears to be the method you call and the $status variable. Just make a function with parameters out of that:

function doThatThing($method, $status) {
    $lists = $this->_listRepo->$method($this->config["same_config_param"]);
    $arrayToUpdate = $this->someProcess($lists, $status);
    $this->updateDBStatus($arrayToUpdate, $status);
}

And call it like:

$this->doThatThing('findAllX', $statusA);
$this->doThatThing('findAllB', $statusB);
$this->doThatThing('findAnotherCase', $statusC);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.