Answer the question
In order to leave comments, you need to log in
How not to build a facade, but write code that does not repeat itself?
Good afternoon, there is a facade in which there are 2 public methods that are 70% similar
, for example:
class facade
{
public function __construct()
{
}
public function run(){
if ($this->card) {
$transaction =
new Transaction(
new Request( //generate Request (not send)
new Curl( //generate sign and curl params for request
new HeadersWithoutSign(), //generate headers for curl
new FieldsAsString( // generate fields for curl as string
new Fields( //generate fields for curl
$this->card,
'usd'
)
)
)
)
); //don't validate this transaction;
new Logger($transaction);
$this->billing($transaction);
$this->redirect($transaction);
} else {
$this->redirect(new EmptyClass());
}
}
public function notification(){
$transaction =
new ValidTransaction( //need Validate this transaction
new Transaction(
new InputRequest()
)
);
new Logger($transaction);
$this->confirmOperation($transaction);
$this->sendToCrm($transaction);
new Answer($transaction);
}
}
Answer the question
In order to leave comments, you need to log in
Yes, this is not a facade, it is a controller, judging by the redirects and so on, and the di level is some kind of prohibitive. I would understand if it was FP. See how the guys make http clients - https://github.com/guzzle/guzzle , it's impossible to use your fake.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question