From 5b927c3302a053b2e74b6a7b5332ba083178ae44 Mon Sep 17 00:00:00 2001 From: Matt Janiszewski Date: Fri, 17 Apr 2015 19:27:08 -0500 Subject: [PATCH] Fixing PSR-2 coding standards in the project. --- src/Spork/Batch/Strategy/MongoStrategy.php | 2 +- .../Batch/Strategy/StrategyInterface.php | 4 +-- src/Spork/Deferred/DeferredInterface.php | 6 ++-- src/Spork/Deferred/PromiseInterface.php | 12 ++++---- .../EventDispatcherInterface.php | 6 ++-- src/Spork/ProcessManager.php | 2 +- src/Spork/SharedMemory.php | 2 +- .../Test/Batch/Strategy/MongoStrategyTest.php | 4 +-- .../Test/Deferred/DeferredAggregateTest.php | 12 ++++---- tests/Spork/Test/Deferred/DeferredTest.php | 14 ++++----- tests/Spork/Test/ProcessManagerTest.php | 28 +++++++---------- tests/Spork/Test/SignalTest.php | 4 +-- tests/Spork/Test/Unserializable.php | 20 +++++++++++++ .../Spork/Test/Util/ThrottleIteratorStub.php | 30 +++++++++++++++++++ .../Spork/Test/Util/ThrottleIteratorTest.php | 18 ----------- 15 files changed, 94 insertions(+), 70 deletions(-) create mode 100644 tests/Spork/Test/Unserializable.php create mode 100644 tests/Spork/Test/Util/ThrottleIteratorStub.php diff --git a/src/Spork/Batch/Strategy/MongoStrategy.php b/src/Spork/Batch/Strategy/MongoStrategy.php index 14a21b6..f0603ca 100644 --- a/src/Spork/Batch/Strategy/MongoStrategy.php +++ b/src/Spork/Batch/Strategy/MongoStrategy.php @@ -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); }; } diff --git a/src/Spork/Batch/Strategy/StrategyInterface.php b/src/Spork/Batch/Strategy/StrategyInterface.php index d58d562..27d78f5 100644 --- a/src/Spork/Batch/Strategy/StrategyInterface.php +++ b/src/Spork/Batch/Strategy/StrategyInterface.php @@ -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. @@ -36,5 +36,5 @@ function createBatches($data); * * @return callable A callable for the child process */ - function createRunner($batch, $callback); + public function createRunner($batch, $callback); } diff --git a/src/Spork/Deferred/DeferredInterface.php b/src/Spork/Deferred/DeferredInterface.php index 05cd55c..e3aa1cb 100644 --- a/src/Spork/Deferred/DeferredInterface.php +++ b/src/Spork/Deferred/DeferredInterface.php @@ -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. @@ -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. @@ -45,5 +45,5 @@ function resolve(); * @return DeferredInterface The current promise * @throws \LogicException If the promise was previously resolved */ - function reject(); + public function reject(); } diff --git a/src/Spork/Deferred/PromiseInterface.php b/src/Spork/Deferred/PromiseInterface.php index 7d6671a..cda5dea 100644 --- a/src/Spork/Deferred/PromiseInterface.php +++ b/src/Spork/Deferred/PromiseInterface.php @@ -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. @@ -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. @@ -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. @@ -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. @@ -69,7 +69,7 @@ function done($done); * * @return PromiseInterface The current promise */ - function fail($fail); + public function fail($fail); /** * Adds done and fail callbacks. @@ -79,5 +79,5 @@ function fail($fail); * * @return PromiseInterface The current promise */ - function then($done, $fail = null); + public function then($done, $fail = null); } diff --git a/src/Spork/EventDispatcher/EventDispatcherInterface.php b/src/Spork/EventDispatcher/EventDispatcherInterface.php index 4ed04e9..6f8e77b 100644 --- a/src/Spork/EventDispatcher/EventDispatcherInterface.php +++ b/src/Spork/EventDispatcher/EventDispatcherInterface.php @@ -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); } diff --git a/src/Spork/ProcessManager.php b/src/Spork/ProcessManager.php index 663c5a8..9f29389 100644 --- a/src/Spork/ProcessManager.php +++ b/src/Spork/ProcessManager.php @@ -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 { diff --git a/src/Spork/SharedMemory.php b/src/Spork/SharedMemory.php index 337960f..b5a5405 100644 --- a/src/Spork/SharedMemory.php +++ b/src/Spork/SharedMemory.php @@ -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) ); diff --git a/tests/Spork/Test/Batch/Strategy/MongoStrategyTest.php b/tests/Spork/Test/Batch/Strategy/MongoStrategyTest.php index c2aa544..1d5e588 100644 --- a/tests/Spork/Test/Batch/Strategy/MongoStrategyTest.php +++ b/tests/Spork/Test/Batch/Strategy/MongoStrategyTest.php @@ -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(); }); } @@ -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)) diff --git a/tests/Spork/Test/Deferred/DeferredAggregateTest.php b/tests/Spork/Test/Deferred/DeferredAggregateTest.php index 382625d..cf9d83b 100644 --- a/tests/Spork/Test/Deferred/DeferredAggregateTest.php +++ b/tests/Spork/Test/Deferred/DeferredAggregateTest.php @@ -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'; }); @@ -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'; }); @@ -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'; }); @@ -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'; }); @@ -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'; }); diff --git a/tests/Spork/Test/Deferred/DeferredTest.php b/tests/Spork/Test/Deferred/DeferredTest.php index 8d0af61..6b78d35 100644 --- a/tests/Spork/Test/Deferred/DeferredTest.php +++ b/tests/Spork/Test/Deferred/DeferredTest.php @@ -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(); }); @@ -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'; }); @@ -80,7 +80,7 @@ public function testMultipleResolve($method) { $log = array(); - $this->defer->always(function() use(& $log) { + $this->defer->always(function () use (& $log) { $log[] = 'always'; }); @@ -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; }); diff --git a/tests/Spork/Test/ProcessManagerTest.php b/tests/Spork/Test/ProcessManagerTest.php index 6c39361..693fb14 100644 --- a/tests/Spork/Test/ProcessManagerTest.php +++ b/tests/Spork/Test/ProcessManagerTest.php @@ -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; }); @@ -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; }); @@ -73,7 +73,7 @@ public function testFailCallbacks() public function testObjectReturn() { - $fork = $this->manager->fork(function() { + $fork = $this->manager->fork(function () { return new Unserializable(); }); @@ -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; }); @@ -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"; }); @@ -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; }); @@ -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!'); - } -} diff --git a/tests/Spork/Test/SignalTest.php b/tests/Spork/Test/SignalTest.php index af0e0a8..8d6b3b8 100644 --- a/tests/Spork/Test/SignalTest.php +++ b/tests/Spork/Test/SignalTest.php @@ -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); }); diff --git a/tests/Spork/Test/Unserializable.php b/tests/Spork/Test/Unserializable.php new file mode 100644 index 0000000..5c03ef1 --- /dev/null +++ b/tests/Spork/Test/Unserializable.php @@ -0,0 +1,20 @@ +loads); + } + + protected function sleep($period) + { + $this->sleeps[] = $period; + } +} diff --git a/tests/Spork/Test/Util/ThrottleIteratorTest.php b/tests/Spork/Test/Util/ThrottleIteratorTest.php index c661fcd..edf7b6e 100644 --- a/tests/Spork/Test/Util/ThrottleIteratorTest.php +++ b/tests/Spork/Test/Util/ThrottleIteratorTest.php @@ -11,8 +11,6 @@ namespace Spork\Test\Util; -use Spork\Util\ThrottleIterator; - class ThrottleIteratorTest extends \PHPUnit_Framework_TestCase { private $iterator; @@ -34,19 +32,3 @@ public function testIteration() $this->assertEquals(array(1, 2, 4), $this->iterator->sleeps); } } - -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; - } -}