for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace BenatEspina\StackExchangeApiClient\Application\Service\Answer;
use BenatEspina\StackExchangeApiClient\Application\DataTransformer\ResponseAnswerDataTransformer;
use BenatEspina\StackExchangeApiClient\Domain\Model\Authentication;
use BenatEspina\StackExchangeApiClient\Domain\Model\Http;
/**
* Accept answer command handler.
*
* @author Beñat Espiña <[email protected]>
*/
class AcceptAnswerHandler
{
* The authentication.
* @var Authentication
private $authentication;
* The data transformer.
* @var ResponseAnswerDataTransformer
private $dataTransformer;
* The HTTP domain class.
* @var Http
private $http;
* Constructor.
* @param Http $http The HTTP domain class
* @param ResponseAnswerDataTransformer $dataTransformer The answer data transformer
* @param Authentication $authentication The authentication
public function __construct(
Http $http,
ResponseAnswerDataTransformer $dataTransformer,
Authentication $authentication
) {
$this->authentication = $authentication;
$this->dataTransformer = $dataTransformer;
$this->http = $http;
}
* Casts an accept vote on the given answer.
* More info: https://api.stackexchange.com/docs/accept-answer
* @param AcceptAnswerCommand $command The command
* @return mixed
public function handle(AcceptAnswerCommand $command)
$response = $this->http->put(
$command->url(),
array_merge($command->params(), $this->authentication->toArray())
);
$this->dataTransformer->write($response);
return $this->dataTransformer->read();