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

Fixing PSR-2 coding standards in the project. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Spork/Batch/Strategy/MongoStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function createBatches($cursor)

$batches = array();
for ($i = 0; $i < $this->size; $i++) {
$batches[] = function() use($cursor, $skip, $i, $limit) {
$batches[] = function () use ($cursor, $skip, $i, $limit) {
return $cursor->skip($skip + $i * $limit)->limit($limit);
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Spork/Batch/Strategy/StrategyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface StrategyInterface
*
* @return array|\Traversable An iterator of batches
*/
function createBatches($data);
public function createBatches($data);

/**
* Creates a batch runner for the supplied list.
Expand All @@ -36,5 +36,5 @@ function createBatches($data);
*
* @return callable A callable for the child process
*/
function createRunner($batch, $callback);
public function createRunner($batch, $callback);
}
6 changes: 3 additions & 3 deletions src/Spork/Deferred/DeferredInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface DeferredInterface extends PromiseInterface
* @return DeferredInterface The current promise
* @throws \LogicException If the promise is not pending
*/
function notify();
public function notify();

/**
* Marks the current promise as successful.
Expand All @@ -33,7 +33,7 @@ function notify();
* @return DeferredInterface The current promise
* @throws \LogicException If the promise was previously rejected
*/
function resolve();
public function resolve();

/**
* Marks the current promise as failed.
Expand All @@ -45,5 +45,5 @@ function resolve();
* @return DeferredInterface The current promise
* @throws \LogicException If the promise was previously resolved
*/
function reject();
public function reject();
}
12 changes: 6 additions & 6 deletions src/Spork/Deferred/PromiseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface PromiseInterface
*
* @return string A promise state constant
*/
function getState();
public function getState();

/**
* Adds a callback to be called upon progress.
Expand All @@ -35,7 +35,7 @@ function getState();
*
* @return PromiseInterface The current promise
*/
function progress($progress);
public function progress($progress);

/**
* Adds a callback to be called whether the promise is resolved or rejected.
Expand All @@ -47,7 +47,7 @@ function progress($progress);
*
* @return PromiseInterface The current promise
*/
function always($always);
public function always($always);

/**
* Adds a callback to be called when the promise completes successfully.
Expand All @@ -58,7 +58,7 @@ function always($always);
*
* @return PromiseInterface The current promise
*/
function done($done);
public function done($done);

/**
* Adds a callback to be called when the promise fails.
Expand All @@ -69,7 +69,7 @@ function done($done);
*
* @return PromiseInterface The current promise
*/
function fail($fail);
public function fail($fail);

/**
* Adds done and fail callbacks.
Expand All @@ -79,5 +79,5 @@ function fail($fail);
*
* @return PromiseInterface The current promise
*/
function then($done, $fail = null);
public function then($done, $fail = null);
}
6 changes: 3 additions & 3 deletions src/Spork/EventDispatcher/EventDispatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

interface EventDispatcherInterface extends BaseEventDispatcherInterface
{
function dispatchSignal($signal);
function addSignalListener($signal, $callable, $priority = 0);
function removeSignalListener($signal, $callable);
public function dispatchSignal($signal);
public function addSignalListener($signal, $callable, $priority = 0);
public function removeSignalListener($signal, $callable);
}
2 changes: 1 addition & 1 deletion src/Spork/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function fork($callable)
$message = new ExitMessage();

// phone home on shutdown
register_shutdown_function(function() use($shm, $message) {
register_shutdown_function(function () use ($shm, $message) {
$status = null;

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Spork/SharedMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function send($message, $signal = null, $pause = 500)
$shmId = shmop_open($this->pid, 'c', 0644, strlen($serializedMessage));
if (!$shmId) {
throw new ProcessControlException(sprintf('Not able to create shared memory segment for PID: %s', $this->pid));
} else if (shmop_write($shmId, $serializedMessage, 0) !== strlen($serializedMessage)) {
} elseif (shmop_write($shmId, $serializedMessage, 0) !== strlen($serializedMessage)) {
throw new ProcessControlException(
sprintf('Not able to write message to shared memory segment for segment ID: %s', $shmId)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Spork/Test/Batch/Strategy/MongoStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function setUp()

// close the connection prior to forking
$mongo = $this->mongo;
$this->manager->addListener(Events::PRE_FORK, function() use($mongo) {
$this->manager->addListener(Events::PRE_FORK, function () use ($mongo) {
$mongo->close();
});
}
Expand All @@ -63,7 +63,7 @@ public function testBatchJob()
));

$this->manager->createBatchJob($coll->find(), new MongoStrategy())
->execute(function($doc) use($coll) {
->execute(function ($doc) use ($coll) {
$coll->update(
array('_id' => $doc['_id']),
array('$set' => array('seen' => true))
Expand Down
12 changes: 6 additions & 6 deletions tests/Spork/Test/Deferred/DeferredAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testNoChildren()
$defer = new DeferredAggregate(array());

$log = array();
$defer->done(function() use(& $log) {
$defer->done(function () use (& $log) {
$log[] = 'done';
});

Expand All @@ -43,7 +43,7 @@ public function testResolvedChildren()
$defer = new DeferredAggregate(array($child));

$log = array();
$defer->done(function() use(& $log) {
$defer->done(function () use (& $log) {
$log[] = 'done';
});

Expand All @@ -58,7 +58,7 @@ public function testResolution()
$defer = new DeferredAggregate(array($child1, $child2));

$log = array();
$defer->done(function() use(& $log) {
$defer->done(function () use (& $log) {
$log[] = 'done';
});

Expand All @@ -80,9 +80,9 @@ public function testRejection()
$defer = new DeferredAggregate(array($child1, $child2, $child3));

$log = array();
$defer->then(function() use(& $log) {
$defer->then(function () use (& $log) {
$log[] = 'done';
}, function() use(& $log) {
}, function () use (& $log) {
$log[] = 'fail';
});

Expand Down Expand Up @@ -120,7 +120,7 @@ public function testFail()
$defer = new DeferredAggregate(array($child));

$log = array();
$defer->fail(function() use(& $log) {
$defer->fail(function () use (& $log) {
$log[] = 'fail';
});

Expand Down
14 changes: 7 additions & 7 deletions tests/Spork/Test/Deferred/DeferredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public function testCallbackOrder($method, $expected)
{
$log = array();

$this->defer->always(function() use(& $log) {
$this->defer->always(function () use (& $log) {
$log[] = 'always';
$log[] = func_get_args();
})->done(function() use(& $log) {
})->done(function () use (& $log) {
$log[] = 'done';
$log[] = func_get_args();
})->fail(function() use(& $log) {
})->fail(function () use (& $log) {
$log[] = 'fail';
$log[] = func_get_args();
});
Expand All @@ -62,9 +62,9 @@ public function testThen($method, $expected)
{
$log = array();

$this->defer->then(function() use(& $log) {
$this->defer->then(function () use (& $log) {
$log[] = 'done';
}, function() use(& $log) {
}, function () use (& $log) {
$log[] = 'fail';
});

Expand All @@ -80,7 +80,7 @@ public function testMultipleResolve($method)
{
$log = array();

$this->defer->always(function() use(& $log) {
$this->defer->always(function () use (& $log) {
$log[] = 'always';
});

Expand Down Expand Up @@ -110,7 +110,7 @@ public function testAlreadyResolved($resolve, $queue, $expect = true)
$this->defer->$resolve();

$log = array();
$this->defer->$queue(function() use(& $log, $queue) {
$this->defer->$queue(function () use (& $log, $queue) {
$log[] = $queue;
});

Expand Down
28 changes: 10 additions & 18 deletions tests/Spork/Test/ProcessManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function testDoneCallbacks()
{
$success = null;

$fork = $this->manager->fork(function() {
$fork = $this->manager->fork(function () {
echo 'output';
return 'result';
})->done(function() use(& $success) {
})->done(function () use (& $success) {
$success = true;
})->fail(function() use(& $success) {
})->fail(function () use (& $success) {
$success = false;
});

Expand All @@ -57,11 +57,11 @@ public function testFailCallbacks()
{
$success = null;

$fork = $this->manager->fork(function() {
$fork = $this->manager->fork(function () {
throw new \Exception('child error');
})->done(function() use(& $success) {
})->done(function () use (& $success) {
$success = true;
})->fail(function() use(& $success) {
})->fail(function () use (& $success) {
$success = false;
});

Expand All @@ -73,7 +73,7 @@ public function testFailCallbacks()

public function testObjectReturn()
{
$fork = $this->manager->fork(function() {
$fork = $this->manager->fork(function () {
return new Unserializable();
});

Expand All @@ -87,7 +87,7 @@ public function testBatchProcessing()
{
$expected = range(100, 109);

$fork = $this->manager->process($expected, function($item) {
$fork = $this->manager->process($expected, function ($item) {
return $item;
});

Expand Down Expand Up @@ -116,7 +116,7 @@ public function testBatchProcessingWithNewlineReturnValues()
);

$this->manager->setDebug(true);
$fork = $this->manager->process($range, function($item) {
$fork = $this->manager->process($range, function ($item) {
return "SomeString\n$item";
});

Expand Down Expand Up @@ -153,7 +153,7 @@ public function testLargeBatchProcessing($rangeEnd)
$expected = array_fill(0, $rangeEnd, null);

/** @var Fork $fork */
$fork = $this->manager->process($expected, function($item) {
$fork = $this->manager->process($expected, function ($item) {
return $item;
});

Expand All @@ -162,11 +162,3 @@ public function testLargeBatchProcessing($rangeEnd)
$this->assertEquals($expected, $fork->getResult());
}
}

class Unserializable
{
public function __sleep()
{
throw new \Exception('Hey, don\'t serialize me!');
}
}
4 changes: 2 additions & 2 deletions tests/Spork/Test/SignalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ protected function tearDown()
public function testSignalParent()
{
$signaled = false;
$this->manager->addListener(SIGUSR1, function() use(& $signaled) {
$this->manager->addListener(SIGUSR1, function () use (& $signaled) {
$signaled = true;
});

$this->manager->fork(function($sharedMem) {
$this->manager->fork(function ($sharedMem) {
$sharedMem->signal(SIGUSR1);
});

Expand Down
20 changes: 20 additions & 0 deletions tests/Spork/Test/Unserializable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of Spork, an OpenSky project.
*
* (c) OpenSky Project Inc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Spork\Test;

class Unserializable
{
public function __sleep()
{
throw new \Exception('Hey, don\'t serialize me!');
}
}
30 changes: 30 additions & 0 deletions tests/Spork/Test/Util/ThrottleIteratorStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of Spork, an OpenSky project.
*
* (c) OpenSky Project Inc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Spork\Test\Util;

use Spork\Util\ThrottleIterator;

class ThrottleIteratorStub extends ThrottleIterator
{
public $loads = array();
public $sleeps = array();

protected function getLoad()
{
return (integer) array_shift($this->loads);
}

protected function sleep($period)
{
$this->sleeps[] = $period;
}
}