Skip to content

Commit

Permalink
Refactor fill method
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Feb 23, 2019
1 parent 80b96d4 commit 9e3c7f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions src/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,20 @@ public function setCommand($command) : self
/**
* Fills the bucket with payload data from command class.
*
* @param \Denpa\Levin\CommandInterface $command
* @param \Denpa\Levin\CommandInterface|null $command
*
* @return self
*/
public function fill(CommandInterface $command) : self
public function fill(?CommandInterface $command = null) : self
{
$method = $this->isRequest() ? 'request' : 'response';
$command = $command ?? $this->getCommand();

if (!is_null($command)) {
$method = $this->isRequest() ? 'request' : 'response';

$this->command = $command;
$this->setPayload($command->$method());
$this->command = $command;
$this->setPayload($command->$method());
}

return $this;
}
Expand Down Expand Up @@ -367,15 +371,11 @@ public function read(Connection $connection) : ?self
*/
public function request(?CommandInterface $command = null) : self
{
$command = $command ?? $this->getCommand();

$this->setReturnData(true);
$this->setReturnCode(1);
$this->setFlags(self::LEVIN_PACKET_REQUEST);

if (!is_null($command)) {
$this->fill($command);
}
$this->fill($command);

return $this;
}
Expand All @@ -394,10 +394,7 @@ public function response(?CommandInterface $command = null) : self
$this->setReturnData(false);
$this->setReturnCode(1);
$this->setFlags(self::LEVIN_PACKET_RESPONSE);

if (!is_null($command)) {
$this->fill($command);
}
$this->fill($command);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Connection implements ConnectionInterface
*
* @return void
*/
public function __construct(string $host, $port, int $timeout = 5)
public function __construct(string $host, $port)
{
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1);
Expand Down

0 comments on commit 9e3c7f2

Please sign in to comment.