diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a3c30f2..25418dc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -54,11 +54,7 @@ jobs: uses: sudo-bot/action-scrutinizer@latest with: cli-args: "--format=php-clover tests/reports/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}" - phpcs: - name: phpcs - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: php-actions/composer@v6 - - name: Check PSR-12 Codestyle - run: composer check-style + pint: + uses: intouchinsight/github-workflows/.github/workflows/laravel-pint.yml@main + with: + php_version: '8.3' diff --git a/composer.json b/composer.json index 6954ad9..f046eab 100644 --- a/composer.json +++ b/composer.json @@ -19,18 +19,19 @@ } }, "require": { - "illuminate/support": "^10", + "illuminate/support": "^10.0|^11.0", "aws/aws-sdk-php": "^3.20.6" }, "require-dev": { "mockery/mockery": "^1.5", - "laravel/framework": "^10", + "laravel/framework": "^10.0|^11.0", "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.5", "scrutinizer/ocular": "^1.3", "phpstan/phpstan": "^1.9", "nunomaduro/larastan": "^1|^2", - "orchestra/testbench": "^8" + "orchestra/testbench": "^8.0|^9.0", + "laravel/pint": "^1.16" }, "scripts": { "test": "phpunit", diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..a2dd735 --- /dev/null +++ b/pint.json @@ -0,0 +1,9 @@ +{ + "preset": "laravel", + "rules": { + "not_operator_with_successor_space": false, + "concat_space": { + "spacing": "one" + } + } +} \ No newline at end of file diff --git a/src/BatchQueueServiceProvider.php b/src/BatchQueueServiceProvider.php index f8662e1..63e6c2e 100644 --- a/src/BatchQueueServiceProvider.php +++ b/src/BatchQueueServiceProvider.php @@ -43,8 +43,7 @@ public function boot() /** * Register the Batch queue connector. * - * @param \Illuminate\Queue\QueueManager $manager - * + * @param \Illuminate\Queue\QueueManager $manager * @return void */ protected function registerBatchConnector($manager) diff --git a/src/Connectors/BatchConnector.php b/src/Connectors/BatchConnector.php index d0c9026..f7cbcc3 100644 --- a/src/Connectors/BatchConnector.php +++ b/src/Connectors/BatchConnector.php @@ -22,7 +22,6 @@ class BatchConnector extends DatabaseConnector /** * Establish a queue connection. * - * @param array $config * * @return \Illuminate\Contracts\Queue\Queue */ @@ -35,7 +34,7 @@ public function connect(array $config) Arr::get($config, 'expire', 60), $config['jobDefinition'], new BatchClient([ - 'region' => $config['region'], + 'region' => $config['region'], 'version' => '2016-08-10', ]) ); diff --git a/src/Console/QueueWorkBatchCommand.php b/src/Console/QueueWorkBatchCommand.php index b46f82b..c37486e 100644 --- a/src/Console/QueueWorkBatchCommand.php +++ b/src/Console/QueueWorkBatchCommand.php @@ -15,14 +15,12 @@ use Illuminate\Console\Command; use Illuminate\Contracts\Cache\Repository as Cache; use Illuminate\Foundation\Exceptions\Handler; -use Illuminate\Queue\Console\WorkCommand; use Illuminate\Queue\QueueManager; use Illuminate\Queue\Worker; use Illuminate\Queue\WorkerOptions; use LukeWaite\LaravelQueueAwsBatch\Exceptions\JobNotFoundException; use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException; use LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue; -use Symfony\Component\Debug\Exception\FatalThrowableError; class QueueWorkBatchCommand extends Command { @@ -38,10 +36,12 @@ class QueueWorkBatchCommand extends Command {--force : Force the worker to run even in maintenance mode} {--tries= : Number of times to attempt a job before logging it failed}'; - protected $manager; + protected $exceptions; + protected $worker; + protected $cache; public function __construct(QueueManager $manager, Worker $worker, Handler $exceptions, Cache $cache) @@ -87,6 +87,7 @@ protected function runJob() $job, $this->gatherWorkerOptions() ); + return; } diff --git a/src/Jobs/BatchJob.php b/src/Jobs/BatchJob.php index 8ec389a..402a656 100644 --- a/src/Jobs/BatchJob.php +++ b/src/Jobs/BatchJob.php @@ -29,9 +29,9 @@ class BatchJob extends DatabaseJob * * Here we need to retain the same jobId, so Batch can retry it, so we need to override the parent. * - * @param int $delay - * + * @param int $delay * @return void + * * @throws UnsupportedException */ public function release($delay = 0) diff --git a/src/Queues/BatchQueue.php b/src/Queues/BatchQueue.php index aa8b77b..ce7597c 100644 --- a/src/Queues/BatchQueue.php +++ b/src/Queues/BatchQueue.php @@ -47,6 +47,7 @@ public function __construct( public function push($job, $data = '', $queue = null) { $payload = $this->createPayload($job, $data); + return $this->pushToBatch($queue, $payload, $this->getBatchDisplayName($job)); } @@ -65,7 +66,7 @@ protected function getBatchDisplayName($job) { if (is_object($job)) { return method_exists($job, 'displayName') - ? $job->displayName() : str_replace('\\', '_', (string)get_class($job)); + ? $job->displayName() : str_replace('\\', '_', (string) get_class($job)); } else { return is_string($job) ? explode('@', $job)[0] : null; } @@ -74,10 +75,9 @@ protected function getBatchDisplayName($job) /** * Push a raw payload to the database, then to AWS Batch, with a given delay. * - * @param string|null $queue - * @param string $payload - * @param string $jobName - * + * @param string|null $queue + * @param string $payload + * @param string $jobName * @return int */ protected function pushToBatch($queue, $payload, $jobName) @@ -86,11 +86,11 @@ protected function pushToBatch($queue, $payload, $jobName) $this->batch->submitJob([ 'jobDefinition' => $this->jobDefinition, - 'jobName' => $jobName, - 'jobQueue' => $this->getQueue($queue), - 'parameters' => [ + 'jobName' => $jobName, + 'jobQueue' => $this->getQueue($queue), + 'parameters' => [ 'jobId' => $jobId, - ] + ], ]); return $jobId; @@ -105,7 +105,6 @@ public function getJobById($id) ->where('id', $id) ->first(); - if (!isset($job)) { throw new JobNotFoundException('Could not find the job'); } @@ -133,11 +132,11 @@ protected function marshalJob($queue, $job) /** * Release the job, without deleting first from the Queue * - * @param string $queue - * @param \StdClass $job - * @param int $delay - * + * @param string $queue + * @param \StdClass $job + * @param int $delay * @return int + * * @throws UnsupportedException */ public function release($queue, $job, $delay) @@ -147,8 +146,8 @@ public function release($queue, $job, $delay) } return $this->database->table($this->table)->where('id', $job->id)->update([ - 'attempts' => $job->attempts, - 'reserved_at' => null + 'attempts' => $job->attempts, + 'reserved_at' => null, ]); } diff --git a/tests/BatchJobTest.php b/tests/BatchJobTest.php index 9631c87..14f44b1 100644 --- a/tests/BatchJobTest.php +++ b/tests/BatchJobTest.php @@ -3,12 +3,12 @@ namespace LukeWaite\LaravelQueueAwsBatch\Tests; use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException; -use Mockery as m; use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase; +use Mockery as m; class BatchJobTest extends TestCase { - public function setUp() : void + public function setUp(): void { $this->job = new \stdClass(); $this->job->payload = '{"job":"foo","data":["data"]}'; @@ -22,7 +22,7 @@ public function setUp() : void $this->batchQueue = m::mock('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue'), $this->job, 'testConnection', - 'defaultQueue' + 'defaultQueue', ])->getMock(); } diff --git a/tests/BatchQueueTest.php b/tests/BatchQueueTest.php index 186ef66..717ce5e 100644 --- a/tests/BatchQueueTest.php +++ b/tests/BatchQueueTest.php @@ -4,12 +4,12 @@ use Carbon\Carbon; use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException; -use Mockery as m; use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase; +use Mockery as m; class BatchQueueTest extends TestCase { - public function setUp() : void + public function setUp(): void { $this->queue = $this->getMockBuilder('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue')->setMethods(null)->setConstructorArgs([ $this->database = m::mock('Illuminate\Database\Connection'), @@ -17,7 +17,7 @@ public function setUp() : void 'default', '60', 'jobdefinition', - $this->batch = m::mock('Aws\Batch\BatchClient') + $this->batch = m::mock('Aws\Batch\BatchClient'), ])->getMock(); $this->queue->setContainer(m::mock('Illuminate\Container\Container')); @@ -80,7 +80,7 @@ public function testGetJobById() $queryResult->id = 1; $table->shouldReceive('where')->once()->with('id', 1)->andReturn($reserved = m::mock('StdClass')); - $reserved->shouldReceive('update')->with(['reserved_at'=> 1473004800, 'attempts'=> 1])->once()->andReturn($job = m::mock('StdClass')); + $reserved->shouldReceive('update')->with(['reserved_at' => 1473004800, 'attempts' => 1])->once()->andReturn($job = m::mock('StdClass')); $this->database->shouldReceive('commit')->once(); @@ -94,7 +94,7 @@ public function testRelease() $this->database->shouldReceive('table')->once()->with('table')->andReturn($table = m::mock('StdClass')); $table->shouldReceive('where')->once()->with('id', 4)->andReturn($query = m::mock('StdClass')); $query->shouldReceive('update')->once()->with([ - 'attempts' => 1, + 'attempts' => 1, 'reserved_at' => null, ])->andReturn(4);