Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #1

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ErrorProcessOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Spatie\Async;

use InvalidArgumentException;
use Throwable;
use InvalidArgumentException;

// TODO: Move to separate namespace
class ErrorProcessOutput extends ProcessOutput
Expand All @@ -15,7 +15,7 @@ class ErrorProcessOutput extends ProcessOutput
*/
public static function create($payload)
{
if (!$payload instanceof Throwable) {
if (! $payload instanceof Throwable) {
throw new InvalidArgumentException('ErrorProcessOutput only accepts Throwables.');
}

Expand Down
10 changes: 4 additions & 6 deletions src/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public static function create()
return new static();
}

public function concurrency(int $concurrency): Pool
public function concurrency(int $concurrency): self
{
$this->concurrency = $concurrency;

return $this;
}

public function maximumExecutionTime(int $maximumExecutionTime): Pool
public function maximumExecutionTime(int $maximumExecutionTime): self
{
$this->maximumExecutionTime = $maximumExecutionTime;

Expand Down Expand Up @@ -124,10 +124,10 @@ public function wait(): void
}

$this->finished($process);
} else if ($processStatus == 0) {
} elseif ($processStatus == 0) {
if ($process->startTime() + $this->maximumExecutionTime < time() || pcntl_wifstopped($status)) {
if (! posix_kill($process->pid(), SIGKILL)) {
throw new Exception("Failed to kill {$process->pid()}: " . posix_strerror(posix_get_last_error()));
throw new Exception("Failed to kill {$process->pid()}: ".posix_strerror(posix_get_last_error()));
}

$process->triggerTimeout();
Expand Down Expand Up @@ -189,8 +189,6 @@ public function offsetExists($offset)
public function offsetGet($offset)
{
// TODO

return null;
}

public function offsetSet($offset, $value)
Expand Down
22 changes: 11 additions & 11 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class Process
protected $errorCallback;
protected $timeoutCallback;

public abstract function execute();
abstract public function execute();

public function internalId()
{
Expand All @@ -36,21 +36,21 @@ public function startTime()
return $this->startTime;
}

public function then(callable $callback): Process
public function then(callable $callback): self
{
$this->successCallback = $callback;

return $this;
}

public function catch(callable $callback): Process
public function catch(callable $callback): self
{
$this->errorCallback = $callback;

return $this;
}

public function timeout(callable $callback): Process
public function timeout(callable $callback): self
{
$this->timeoutCallback = $callback;

Expand All @@ -60,7 +60,7 @@ public function timeout(callable $callback): Process
public function triggerSuccess($output = null)
{
if (! $this->successCallback) {
return null;
return;
}

return call_user_func_array($this->successCallback, [$output]);
Expand All @@ -69,7 +69,7 @@ public function triggerSuccess($output = null)
public function triggerError($output = null)
{
if (! $this->errorCallback) {
return null;
return;
}

return call_user_func_array($this->errorCallback, [$output]);
Expand All @@ -78,34 +78,34 @@ public function triggerError($output = null)
public function triggerTimeout($output = null)
{
if (! $this->timeoutCallback) {
return null;
return;
}

return call_user_func_array($this->timeoutCallback, [$output]);
}

public function setInternalId($internalId): Process
public function setInternalId($internalId): self
{
$this->internalId = $internalId;

return $this;
}

public function setPid($pid): Process
public function setPid($pid): self
{
$this->pid = $pid;

return $this;
}

public function setSocket($socket): Process
public function setSocket($socket): self
{
$this->socket = $socket;

return $this;
}

public function setStartTime($startTime): Process
public function setStartTime($startTime): self
{
$this->startTime = $startTime;

Expand Down
4 changes: 2 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

use Spatie\Async\CallableProcess;
use Spatie\Async\Pool;
use Spatie\Async\Process;
use Spatie\Async\CallableProcess;

if (! function_exists('async')) {
function async($process): Process
{
if (!$process instanceof Process) {
if (! $process instanceof Process) {
$process = new CallableProcess($process);
}

Expand Down