Skip to content

Commit

Permalink
Refactor code for consistency and formatting
Browse files Browse the repository at this point in the history
Standardize formatting by adjusting whitespace and quotation styles across multiple files. This includes adding spaces in conditional statements, aligning parameter annotations, and ensuring consistent object literals formatting in test cases.
  • Loading branch information
mvd81 committed Nov 2, 2024
1 parent 8a460ae commit 2044e92
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/Http/Controllers/CompletedJobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class CompletedJobsController extends Controller
/**
* Create a new controller instance.
*
* @param JobRepository $jobs
* @param TagRepository $tags
* @param JobRepository $jobs
* @param TagRepository $tags
*/
public function __construct(JobRepository $jobs, TagRepository $tags)
{
Expand Down Expand Up @@ -75,7 +75,7 @@ protected function paginate(Request $request)
* Paginate the completed jobs for the request and tag.
*
* @param \Illuminate\Http\Request $request
* @param $tag
* @param $tag
* @return \Illuminate\Support\Collection
*/
protected function paginateByTag(Request $request, $tag)
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/PendingJobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ protected function paginate(Request $request)
/**
* Paginate the pending jobs for the request and tag.
*
* @param \Illuminate\Http\Request $request
* @param $tag
* @param \Illuminate\Http\Request $request
* @param $tag
* @return \Illuminate\Support\Collection
*/
protected function paginateByTag(Request $request, $tag)
Expand Down
5 changes: 2 additions & 3 deletions src/Listeners/ForgetJobInPendingTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ public function __construct(TagRepository $tags)
* @param \Laravel\Horizon\Events\JobDeleted $event
* @return void
*/
public function handle(JobDeleted $event):void
public function handle(JobDeleted $event): void
{
$pendingTags = collect($event->payload->tags())->map(function ($tag) {
return 'pending:'.$tag;
})->all();

if (!empty($pendingTags)) {

if (! empty($pendingTags)) {
$this->tags->forgetJobs($pendingTags, $event->payload->id());
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Listeners/StoreTagsForCompletedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(TagRepository $tags)
* @param \Laravel\Horizon\Events\JobDeleted $event
* @return void
*/
public function handle(JobDeleted $event):void
public function handle(JobDeleted $event): void
{
if ($event->job->hasFailed()) {
return;
Expand All @@ -41,8 +41,7 @@ public function handle(JobDeleted $event):void
return 'completed:'.$tag;
})->all();

if (!empty($tags)) {

if ( !empty($tags)) {
$this->tags->addTemporary(
config('horizon.trim.completed', 2880), $event->payload->id(), $tags
);
Expand Down
4 changes: 1 addition & 3 deletions src/Listeners/StoreTagsForPendingJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Horizon\Listeners;

use Illuminate\Support\Facades\Log;
use Laravel\Horizon\Contracts\TagRepository;
use Laravel\Horizon\Events\JobPushed;

Expand Down Expand Up @@ -40,8 +39,7 @@ public function handle(JobPushed $event)
})->all();

// Only create tags if there are tags in the job payload.
if (!empty($tags)) {

if ( !empty($tags)) {
$this->tags->addTemporary(
config('horizon.trim.pending', 2880), $event->payload->id(), $tags
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function test_if_pending_tags_are_removed_when_a_job_is_completed(): void
$event = new JobDeleted(
new PendingJob(),
json_encode([
"id" => "1",
"displayName" => "displayName",
"tags" => ["foobar", "bar"]
'id' => '1',
'displayName' => 'displayName',
'tags' => ['foobar', 'bar'],
])
);

Expand Down
1 change: 0 additions & 1 deletion tests/Feature/Listeners/StoreTagsForCompletedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function test_completed_tag_is_added_when_job_completes(): void
$this->app->make(Dispatcher::class)->dispatch(new JobDeleted(
new CompletedJob(), '{"id":"1","displayName":"displayName","tags":["foobar"]}'
));

}
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/Listeners/StoreTagsForPendingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laravel\Horizon\Tests\Feature\Listeners;

use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Queue\Jobs\Job;
use Laravel\Horizon\Contracts\TagRepository;
use Laravel\Horizon\Events\JobPushed;
use Laravel\Horizon\Tests\IntegrationTest;
Expand Down Expand Up @@ -32,6 +31,5 @@ public function test_a_pending_tag_is_added_when_the_job_is_pushed(): void
$this->app->make(Dispatcher::class)->dispatch(new JobPushed(
'{"id":"1","displayName":"displayName","tags":["bar"]}'
));

}
}
14 changes: 7 additions & 7 deletions tests/Feature/RetrieveCompletedJobsFilteredByTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ protected function setUp(): void
public function test_can_retrieve_completed_jobs_without_tag_search()
{
$jobs = collect([
(object)['id' => 1, 'payload' => json_encode(['tags' => []])],
(object)['id' => 2, 'payload' => json_encode(['tags' => []])],
(object)['id' => 3, 'payload' => json_encode(['tags' => ['tag A']])],
(object)['id' => 4, 'payload' => json_encode(['tags' => []])]
(object) ['id' => 1, 'payload' => json_encode(['tags' => []])],
(object) ['id' => 2, 'payload' => json_encode(['tags' => []])],
(object) ['id' => 3, 'payload' => json_encode(['tags' => ['tag A']])],
(object) ['id' => 4, 'payload' => json_encode(['tags' => []])],
]);

$this->jobRepository->method('getCompleted')->willReturn($jobs);
Expand All @@ -49,9 +49,9 @@ public function test_can_retrieve_completed_jobs_with_tag_search()
{
$tag = 'foobar';
$jobs = collect([
(object)['id' => 3838, 'status' => 'completed', 'payload' => json_encode(['tags' => [$tag]])],
(object)['id' => 3838, 'status' => 'pending', 'payload' => json_encode(['tags' => [$tag]])],
(object)['id' => 9933, 'status' => 'completed', 'payload' => json_encode(['tags' => [$tag]])]
(object) ['id' => 3838, 'status' => 'completed', 'payload' => json_encode(['tags' => [$tag]])],
(object) ['id' => 3838, 'status' => 'pending', 'payload' => json_encode(['tags' => [$tag]])],
(object) ['id' => 9933, 'status' => 'completed', 'payload' => json_encode(['tags' => [$tag]])],
]);

$this->tagRepository->method('paginate')->willReturn([$jobs[0]->id, $jobs[2]->id]);
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/RetrievePendingJobsFilteredByTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ protected function setUp(): void
public function test_can_retrieve_pending_jobs_without_tag_search()
{
$jobs = collect([
(object)['id' => 1, 'payload' => json_encode(['tags' => []])],
(object)['id' => 2, 'payload' => json_encode(['tags' => []])],
(object)['id' => 3, 'payload' => json_encode(['tags' => ['tag 1']])],
(object) ['id' => 1, 'payload' => json_encode(['tags' => []])],
(object) ['id' => 2, 'payload' => json_encode(['tags' => []])],
(object) ['id' => 3, 'payload' => json_encode(['tags' => ['tag 1']])],
]);

$this->jobRepository->method('getPending')->willReturn($jobs);
Expand All @@ -47,9 +47,9 @@ public function test_can_retrieve_pending_jobs_with_tag_search()
{
$tag = 'developer';
$jobs = collect([
(object)['id' => 1093, 'status' => 'pending', 'payload' => json_encode(['tags' => [$tag]])],
(object)['id' => 2839, 'status' => 'completed', 'payload' => json_encode(['tags' => [$tag]])],
(object)['id' => 2839, 'status' => 'pending', 'payload' => json_encode(['tags' => [$tag]])],
(object) ['id' => 1093, 'status' => 'pending', 'payload' => json_encode(['tags' => [$tag]])],
(object) ['id' => 2839, 'status' => 'completed', 'payload' => json_encode(['tags' => [$tag]])],
(object) ['id' => 2839, 'status' => 'pending', 'payload' => json_encode(['tags' => [$tag]])],
]);

$this->tagRepository->method('paginate')->willReturn([$jobs[0]->id, $jobs[2]->id]);
Expand Down

0 comments on commit 2044e92

Please sign in to comment.