From 2d0951dca1b2fd99d3a8f706da4bd5306bf94650 Mon Sep 17 00:00:00 2001 From: Petr Levtonov Date: Sat, 23 Nov 2019 14:11:01 +0100 Subject: [PATCH] Apply php-cs-fixer --- .php_cs.dist | 8 +------- src/Spork/Batch/BatchJob.php | 4 ++-- src/Spork/Batch/BatchRunner.php | 2 +- src/Spork/Batch/Strategy/MongoStrategy.php | 4 ++-- src/Spork/Deferred/Deferred.php | 8 ++++---- src/Spork/Deferred/DeferredAggregate.php | 2 +- src/Spork/Deferred/DeferredInterface.php | 6 +++--- src/Spork/Deferred/PromiseInterface.php | 2 +- src/Spork/EventDispatcher/EventDispatcher.php | 2 +- src/Spork/Fork.php | 14 +++++++------- src/Spork/ProcessManager.php | 6 +++--- src/Spork/SharedMemory.php | 12 ++++++------ src/Spork/Util/Error.php | 4 ++-- src/Spork/Util/ExitMessage.php | 4 ++-- tests/Spork/Batch/Strategy/ChunkStrategyTest.php | 1 - tests/Spork/Batch/Strategy/MongoStrategyTest.php | 1 - tests/Spork/Deferred/DeferredAggregateTest.php | 2 -- tests/Spork/Deferred/DeferredTest.php | 1 - tests/Spork/ProcessManagerTest.php | 2 -- tests/Spork/SignalTest.php | 2 -- tests/Spork/Util/ThrottleIteratorStub.php | 2 -- 21 files changed, 36 insertions(+), 53 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 8549468..406fefd 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -13,7 +13,7 @@ return PhpCsFixer\Config::create() ->setRules([ '@PSR2' => true, 'psr4' => true, - 'binary_operator_spaces' => false, + 'binary_operator_spaces' => true, 'array_syntax' => ['syntax' => 'short'], 'linebreak_after_opening_tag' => true, 'not_operator_with_successor_space' => true, @@ -50,11 +50,5 @@ return PhpCsFixer\Config::create() 'compact_nullable_typehint' => true, 'ternary_operator_spaces' => true, 'unary_operator_spaces' => true, - 'binary_operator_spaces' => [ - 'default' => 'single_space', - 'operators' => [ - '|' => 'no_space', - ] - ] ]) ->setFinder($finder); diff --git a/src/Spork/Batch/BatchJob.php b/src/Spork/Batch/BatchJob.php index d469420..de2f17a 100644 --- a/src/Spork/Batch/BatchJob.php +++ b/src/Spork/Batch/BatchJob.php @@ -80,7 +80,7 @@ public function execute($callback = null) */ public function __invoke() { - $forks = array(); + $forks = []; foreach ($this->strategy->createBatches($this->data) as $index => $batch) { $forks[] = $this->manager ->fork($this->strategy->createRunner($batch, $this->callback)) @@ -91,7 +91,7 @@ public function __invoke() // block until all forks have exited $this->manager->wait(); - $results = array(); + $results = []; foreach ($forks as $fork) { $results = array_merge($results, $fork->getResult()); } diff --git a/src/Spork/Batch/BatchRunner.php b/src/Spork/Batch/BatchRunner.php index 81149d6..50584b3 100644 --- a/src/Spork/Batch/BatchRunner.php +++ b/src/Spork/Batch/BatchRunner.php @@ -46,7 +46,7 @@ public function __invoke(SharedMemory $shm) $this->batch = call_user_func($this->batch); } - $results = array(); + $results = []; foreach ($this->batch as $index => $item) { $results[$index] = call_user_func($this->callback, $item, $index, $this->batch, $shm); } diff --git a/src/Spork/Batch/Strategy/MongoStrategy.php b/src/Spork/Batch/Strategy/MongoStrategy.php index d82ae0b..add43f9 100644 --- a/src/Spork/Batch/Strategy/MongoStrategy.php +++ b/src/Spork/Batch/Strategy/MongoStrategy.php @@ -48,10 +48,10 @@ public function createBatches($cursor) throw new UnexpectedTypeException($cursor, $expected); } - $skip = $this->skip; + $skip = $this->skip; $limit = ceil(($cursor->count(true) - $skip) / $this->size); - $batches = array(); + $batches = []; for ($i = 0; $i < $this->size; $i++) { $batches[] = function () use ($cursor, $skip, $i, $limit) { return $cursor->skip($skip + $i * $limit)->limit($limit); diff --git a/src/Spork/Deferred/Deferred.php b/src/Spork/Deferred/Deferred.php index 8f92116..183e305 100644 --- a/src/Spork/Deferred/Deferred.php +++ b/src/Spork/Deferred/Deferred.php @@ -26,10 +26,10 @@ public function __construct() { $this->state = DeferredInterface::STATE_PENDING; - $this->progressCallbacks = array(); - $this->alwaysCallbacks = array(); - $this->doneCallbacks = array(); - $this->failCallbacks = array(); + $this->progressCallbacks = []; + $this->alwaysCallbacks = []; + $this->doneCallbacks = []; + $this->failCallbacks = []; } public function getState() diff --git a/src/Spork/Deferred/DeferredAggregate.php b/src/Spork/Deferred/DeferredAggregate.php index 4042093..6947d88 100644 --- a/src/Spork/Deferred/DeferredAggregate.php +++ b/src/Spork/Deferred/DeferredAggregate.php @@ -32,7 +32,7 @@ public function __construct(array $children) // connect to each child foreach ($this->children as $child) { - $child->always(array($this, 'tick')); + $child->always([$this, 'tick']); } // always tick once now diff --git a/src/Spork/Deferred/DeferredInterface.php b/src/Spork/Deferred/DeferredInterface.php index e3aa1cb..3c6ede5 100644 --- a/src/Spork/Deferred/DeferredInterface.php +++ b/src/Spork/Deferred/DeferredInterface.php @@ -18,8 +18,8 @@ interface DeferredInterface extends PromiseInterface * * @param mixed $args Any arguments will be passed along to the callbacks * - * @return DeferredInterface The current promise * @throws \LogicException If the promise is not pending + * @return DeferredInterface The current promise */ public function notify(); @@ -30,8 +30,8 @@ public function notify(); * * @param mixed $args Any arguments will be passed along to the callbacks * - * @return DeferredInterface The current promise * @throws \LogicException If the promise was previously rejected + * @return DeferredInterface The current promise */ public function resolve(); @@ -42,8 +42,8 @@ public function resolve(); * * @param mixed $args Any arguments will be passed along to the callbacks * - * @return DeferredInterface The current promise * @throws \LogicException If the promise was previously resolved + * @return DeferredInterface The current promise */ public function reject(); } diff --git a/src/Spork/Deferred/PromiseInterface.php b/src/Spork/Deferred/PromiseInterface.php index 1082d24..dd92a54 100644 --- a/src/Spork/Deferred/PromiseInterface.php +++ b/src/Spork/Deferred/PromiseInterface.php @@ -13,7 +13,7 @@ interface PromiseInterface { - public const STATE_PENDING = 'pending'; + public const STATE_PENDING = 'pending'; public const STATE_RESOLVED = 'resolved'; public const STATE_REJECTED = 'rejected'; diff --git a/src/Spork/EventDispatcher/EventDispatcher.php b/src/Spork/EventDispatcher/EventDispatcher.php index 0d686e4..93b7c20 100644 --- a/src/Spork/EventDispatcher/EventDispatcher.php +++ b/src/Spork/EventDispatcher/EventDispatcher.php @@ -28,7 +28,7 @@ public function dispatchSignal($signal) public function addSignalListener($signal, $callable, $priority = 0) { $this->addListener('spork.signal.' . $signal, $callable, $priority); - pcntl_signal($signal, array($this, 'dispatchSignal')); + pcntl_signal($signal, [$this, 'dispatchSignal']); } public function removeSignalListener($signal, $callable) diff --git a/src/Spork/Fork.php b/src/Spork/Fork.php index 84a6208..29e4167 100644 --- a/src/Spork/Fork.php +++ b/src/Spork/Fork.php @@ -30,10 +30,10 @@ class Fork implements DeferredInterface public function __construct($pid, SharedMemory $shm, $debug = false) { $this->defer = new Deferred(); - $this->pid = $pid; - $this->shm = $shm; + $this->pid = $pid; + $this->shm = $shm; $this->debug = $debug; - $this->name = ''; + $this->name = ''; } /** @@ -92,7 +92,7 @@ public function processWaitStatus($status) public function receive() { - $messages = array(); + $messages = []; foreach ($this->shm->receive() as $message) { if ($message instanceof ExitMessage) { @@ -221,7 +221,7 @@ public function notify() $args = func_get_args(); array_unshift($args, $this); - call_user_func_array(array($this->defer, 'notify'), $args); + call_user_func_array([$this->defer, 'notify'], $args); return $this; } @@ -231,7 +231,7 @@ public function resolve() $args = func_get_args(); array_unshift($args, $this); - call_user_func_array(array($this->defer, 'resolve'), $args); + call_user_func_array([$this->defer, 'resolve'], $args); return $this; } @@ -241,7 +241,7 @@ public function reject() $args = func_get_args(); array_unshift($args, $this); - call_user_func_array(array($this->defer, 'reject'), $args); + call_user_func_array([$this->defer, 'reject'], $args); return $this; } diff --git a/src/Spork/ProcessManager.php b/src/Spork/ProcessManager.php index 51412e7..f9a749f 100644 --- a/src/Spork/ProcessManager.php +++ b/src/Spork/ProcessManager.php @@ -38,7 +38,7 @@ public function __construct(EventDispatcherInterface $dispatcher = null, Factory $this->factory = $factory ?: new Factory(); $this->debug = $debug; $this->zombieOkay = false; - $this->forks = array(); + $this->forks = []; } public function __destruct() @@ -100,7 +100,7 @@ public function fork($callable) if (0 === $pid) { // reset the list of child processes - $this->forks = array(); + $this->forks = []; // setup the shared memory $shm = $this->factory->createSharedMemory(null, $this->signal); @@ -156,7 +156,7 @@ public function fork($callable) public function monitor($signal = SIGUSR1) { $this->signal = $signal; - $this->dispatcher->addSignalListener($signal, array($this, 'check')); + $this->dispatcher->addSignalListener($signal, [$this, 'check']); } public function check() diff --git a/src/Spork/SharedMemory.php b/src/Spork/SharedMemory.php index 81c2beb..254c252 100644 --- a/src/Spork/SharedMemory.php +++ b/src/Spork/SharedMemory.php @@ -32,14 +32,14 @@ public function __construct($pid = null, $signal = null) { if (null === $pid) { // child - $pid = posix_getpid(); - $ppid = posix_getppid(); + $pid = posix_getpid(); + $ppid = posix_getppid(); } else { // parent - $ppid = null; + $ppid = null; } - $this->pid = $pid; + $this->pid = $pid; $this->ppid = $ppid; $this->signal = $signal; } @@ -59,7 +59,7 @@ public function receive() return unserialize($serializedMessages); } - return array(); + return []; } /** @@ -71,7 +71,7 @@ public function receive() */ public function send($message, $signal = null, $pause = 500) { - $messageArray = array(); + $messageArray = []; if (($shmId = @shmop_open($this->pid, 'a', 0, 0)) > 0) { // Read any existing messages in shared memory diff --git a/src/Spork/Util/Error.php b/src/Spork/Util/Error.php index 12fbabd..b4286d7 100644 --- a/src/Spork/Util/Error.php +++ b/src/Spork/Util/Error.php @@ -83,13 +83,13 @@ public function setCode($code) public function serialize() { - return serialize(array( + return serialize([ $this->class, $this->message, $this->file, $this->line, $this->code, - )); + ]); } public function unserialize($str) diff --git a/src/Spork/Util/ExitMessage.php b/src/Spork/Util/ExitMessage.php index 9d8b652..b212f97 100644 --- a/src/Spork/Util/ExitMessage.php +++ b/src/Spork/Util/ExitMessage.php @@ -49,11 +49,11 @@ public function setError(Error $error) public function serialize() { - return serialize(array( + return serialize([ $this->result, $this->output, $this->error, - )); + ]); } public function unserialize($str) diff --git a/tests/Spork/Batch/Strategy/ChunkStrategyTest.php b/tests/Spork/Batch/Strategy/ChunkStrategyTest.php index 199f85c..b589f73 100644 --- a/tests/Spork/Batch/Strategy/ChunkStrategyTest.php +++ b/tests/Spork/Batch/Strategy/ChunkStrategyTest.php @@ -12,7 +12,6 @@ namespace Spork\Batch\Strategy; use PHPUnit\Framework\TestCase; -use Spork\Batch\Strategy\ChunkStrategy; class ChunkStrategyTest extends TestCase { diff --git a/tests/Spork/Batch/Strategy/MongoStrategyTest.php b/tests/Spork/Batch/Strategy/MongoStrategyTest.php index 6b832e1..568a7b3 100644 --- a/tests/Spork/Batch/Strategy/MongoStrategyTest.php +++ b/tests/Spork/Batch/Strategy/MongoStrategyTest.php @@ -12,7 +12,6 @@ namespace Spork\Batch\Strategy; use PHPUnit\Framework\TestCase; -use Spork\Batch\Strategy\MongoStrategy; use Spork\EventDispatcher\Events; use Spork\ProcessManager; diff --git a/tests/Spork/Deferred/DeferredAggregateTest.php b/tests/Spork/Deferred/DeferredAggregateTest.php index 9b0b83e..0eaa8d6 100644 --- a/tests/Spork/Deferred/DeferredAggregateTest.php +++ b/tests/Spork/Deferred/DeferredAggregateTest.php @@ -12,8 +12,6 @@ namespace Spork\Deferred; use PHPUnit\Framework\TestCase; -use Spork\Deferred\Deferred; -use Spork\Deferred\DeferredAggregate; use Spork\Exception\UnexpectedTypeException; class DeferredAggregateTest extends TestCase diff --git a/tests/Spork/Deferred/DeferredTest.php b/tests/Spork/Deferred/DeferredTest.php index 7b3ca61..fc256f7 100644 --- a/tests/Spork/Deferred/DeferredTest.php +++ b/tests/Spork/Deferred/DeferredTest.php @@ -13,7 +13,6 @@ use LogicException; use PHPUnit\Framework\TestCase; -use Spork\Deferred\Deferred; use Spork\Exception\UnexpectedTypeException; class DeferredTest extends TestCase diff --git a/tests/Spork/ProcessManagerTest.php b/tests/Spork/ProcessManagerTest.php index 4ac8f7a..03c9fc7 100644 --- a/tests/Spork/ProcessManagerTest.php +++ b/tests/Spork/ProcessManagerTest.php @@ -13,8 +13,6 @@ use Exception; use PHPUnit\Framework\TestCase; -use Spork\Fork; -use Spork\ProcessManager; class ProcessManagerTest extends TestCase { diff --git a/tests/Spork/SignalTest.php b/tests/Spork/SignalTest.php index 3aeb4c6..aae25b6 100644 --- a/tests/Spork/SignalTest.php +++ b/tests/Spork/SignalTest.php @@ -12,8 +12,6 @@ namespace Spork; use PHPUnit\Framework\TestCase; -use Spork\ProcessManager; -use Spork\SharedMemory; class SignalTest extends TestCase { diff --git a/tests/Spork/Util/ThrottleIteratorStub.php b/tests/Spork/Util/ThrottleIteratorStub.php index eaf8e1e..ab6deba 100644 --- a/tests/Spork/Util/ThrottleIteratorStub.php +++ b/tests/Spork/Util/ThrottleIteratorStub.php @@ -11,8 +11,6 @@ namespace Spork\Util; -use Spork\Util\ThrottleIterator; - class ThrottleIteratorStub extends ThrottleIterator { public $loads = [];