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 #6

Merged
merged 1 commit into from
Dec 22, 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
5 changes: 2 additions & 3 deletions src/ParallelProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace Spatie\Async;

use Error;
use PHPUnit\Runner\Exception;
use Spatie\Async\Output\SerializableException;
use Symfony\Component\Process\Process;
use Throwable;
use Symfony\Component\Process\Process;
use Spatie\Async\Output\SerializableException;

class ParallelProcess
{
Expand Down
4 changes: 2 additions & 2 deletions src/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function notify(): void

public function add($process): ParallelProcess
{
if (!$process instanceof ParallelProcess) {
if (! $process instanceof ParallelProcess) {
$process = ParentRuntime::createChildProcess($process);
}

Expand Down Expand Up @@ -207,7 +207,7 @@ protected function registerListener(): void

$process = $this->inProgress[$pid] ?? null;

if (!$process) {
if (! $process) {
continue;
}

Expand Down
14 changes: 7 additions & 7 deletions src/Runtime/ChildRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
$autoloader = $argv[1];
$serializedClosure = base64_decode($argv[2]);

if (!$autoloader) {
if (! $autoloader) {
throw new InvalidArgumentException('No autoloader provided in child process.');
}

if (!file_exists($autoloader)) {
if (! file_exists($autoloader)) {
throw new InvalidArgumentException("Could not find autoloader in child process: {$autoloader}");
}

if (!$serializedClosure) {
throw new InvalidArgumentException("No valid closure was passed to the child process.");
if (! $serializedClosure) {
throw new InvalidArgumentException('No valid closure was passed to the child process.');
}

require_once $autoloader;
Expand All @@ -22,15 +22,15 @@

$output = call_user_func($closure);

fputs(STDOUT, base64_encode(serialize($output)));
fwrite(STDOUT, base64_encode(serialize($output)));

exit(0);
} catch (Throwable $e) {
require_once __DIR__ . '/../Output/SerializableException.php';
require_once __DIR__.'/../Output/SerializableException.php';

$output = new \Spatie\Async\Output\SerializableException($e);

fputs(STDERR, base64_encode(serialize($output)));
fwrite(STDERR, base64_encode(serialize($output)));

exit(1);
}
14 changes: 7 additions & 7 deletions src/Runtime/ParentRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Spatie\Async\Runtime;

use Opis\Closure\SerializableClosure;
use Spatie\Async\ParallelProcess;
use Symfony\Component\Process\Process;
use function Opis\Closure\serialize;
use Opis\Closure\SerializableClosure;
use Symfony\Component\Process\Process;

class ParentRuntime
{
Expand All @@ -16,21 +16,21 @@ class ParentRuntime
public static function init()
{
$existingAutoloaderFiles = array_filter([
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../vendor/autoload.php',
__DIR__.'/../../vendor/autoload.php',
__DIR__.'/../../../vendor/autoload.php',
], function (string $path) {
return file_exists($path);
});

self::$autoloader = reset($existingAutoloaderFiles);
self::$childProcessScript = __DIR__ . '/ChildRuntime.php';
self::$childProcessScript = __DIR__.'/ChildRuntime.php';

self::$isInitialised = true;
}

public static function createChildProcess(callable $callable): ParallelProcess
{
if (!self::$isInitialised) {
if (! self::$isInitialised) {
self::init();
}

Expand All @@ -40,7 +40,7 @@ public static function createChildProcess(callable $callable): ParallelProcess
'exec php',
self::$childProcessScript,
self::$autoloader,
base64_encode(serialize($closure))
base64_encode(serialize($closure)),
]));

return ParallelProcess::create($process);
Expand Down
8 changes: 4 additions & 4 deletions tests/ChildRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace Spatie\Async\Tests;

use Opis\Closure\SerializableClosure;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
use function Opis\Closure\serialize;
use Opis\Closure\SerializableClosure;
use Symfony\Component\Process\Process;

class ChildRuntimeTest extends TestCase
{
/** @test */
public function it_can_run()
{
$bootstrap = __DIR__ . '/../src/Runtime/ChildRuntime.php';
$bootstrap = __DIR__.'/../src/Runtime/ChildRuntime.php';

$autoloader = __DIR__ . '/../vendor/autoload.php';
$autoloader = __DIR__.'/../vendor/autoload.php';

$serializedClosure = base64_encode(serialize(new SerializableClosure(function () {
echo 'child';
Expand Down
2 changes: 1 addition & 1 deletion tests/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ public function it_returns_all_the_output_as_an_array()
$this->assertCount(5, $result);
$this->assertEquals(10, array_sum($result));
}
};
}