Skip to content

Commit

Permalink
Merge pull request #652 from biigle/php-cs-fixer
Browse files Browse the repository at this point in the history
Apply coding style
  • Loading branch information
mzur authored Oct 11, 2023
2 parents df6c0c9 + de0659c commit 759687c
Show file tree
Hide file tree
Showing 191 changed files with 1,383 additions and 1,338 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ npm-debug.log
yarn-error.log
/*.sublime-*
/*.phar
/*.php_cs.cache
/*.php-cs-fixer.cache
/.idea
/.vscode
34 changes: 34 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

$finder = (new PhpCsFixer\Finder())
->files()
->in([
__DIR__.'/app',
__DIR__.'/tests',
__DIR__.'/config',
__DIR__.'/database',
// __DIR__.'/vendor/biigle',
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'ordered_imports' => true,
'single_space_around_construct' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one', ]],
'no_whitespace_before_comma_in_array' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
'method_chaining_indentation' => true,
'use_arrow_functions' => true,
'no_unused_imports' => true
])
->setFinder($finder)
->setRiskyAllowed(true)
->setUsingCache(true);
16 changes: 0 additions & 16 deletions .php_cs

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ The default development setup of BIIGLE uses the `dev-modules` branch of the cor

BIIGLE uses readable and meaningful commit messages. Please follow [this guide](https://chris.beams.io/posts/git-commit/) for your commits to BIIGLE.

BIIGLE also defines a PHP coding style in [`.php_cs`](.php_cs). Use the [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) to apply the coding style to your source code.
BIIGLE also defines a PHP coding style in [`.php-cs-fixer.php`](.php-cs-fixer.php). Use the [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) to apply the coding style to your source code.

All changes or new features that affect the API or backend PHP code should be thoroughly tested.
81 changes: 42 additions & 39 deletions app/AnnotationSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ public function getVolumeFileAnnotations(VolumeFile $file, User $user)
$query->with(['labels' => function ($query) use ($user) {
// wrap this in a where because the default query already has a where
$query->where(function ($query) use ($user) {
$query->where(function ($query) {
$query->where('created_at', '>=', $this->starts_at)
->where('created_at', '<', $this->ends_at);
})
->orWhere('user_id', '!=', $user->id);
$query
->where(function ($query) {
$query->where('created_at', '>=', $this->starts_at)
->where('created_at', '<', $this->ends_at);
})
->orWhere('user_id', '!=', $user->id);
});
}]);
} else {
Expand Down Expand Up @@ -205,25 +206,26 @@ public function imageAnnotations()
{
return ImageAnnotation::where(function ($query) {
// all annotations of the associated volume
return $query->whereIn('image_id', function ($query) {
$query->select('id')
return $query
->whereIn('image_id', function ($query) {
$query->select('id')
->from('images')
->where('volume_id', $this->volume_id);
})
// that were created between the start and end date
->where('created_at', '>=', $this->starts_at)
->where('created_at', '<', $this->ends_at)
// and have a label by one of the members of this session
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('image_annotation_labels')
->whereRaw('image_annotation_labels.annotation_id = image_annotations.id')
->whereIn('image_annotation_labels.user_id', function ($query) {
$query->select('user_id')
->from('annotation_session_user')
->where('annotation_session_id', $this->id);
});
});
})
// that were created between the start and end date
->where('created_at', '>=', $this->starts_at)
->where('created_at', '<', $this->ends_at)
// and have a label by one of the members of this session
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('image_annotation_labels')
->whereRaw('image_annotation_labels.annotation_id = image_annotations.id')
->whereIn('image_annotation_labels.user_id', function ($query) {
$query->select('user_id')
->from('annotation_session_user')
->where('annotation_session_id', $this->id);
});
});
});
}

Expand All @@ -238,25 +240,26 @@ public function videoAnnotations()
{
return VideoAnnotation::where(function ($query) {
// all annotations of the associated volume
return $query->whereIn('video_id', function ($query) {
$query->select('id')
return $query
->whereIn('video_id', function ($query) {
$query->select('id')
->from('videos')
->where('volume_id', $this->volume_id);
})
// that were created between the start and end date
->where('created_at', '>=', $this->starts_at)
->where('created_at', '<', $this->ends_at)
// and have a label by one of the members of this session
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('video_annotation_labels')
->whereRaw('video_annotation_labels.annotation_id = video_annotations.id')
->whereIn('video_annotation_labels.user_id', function ($query) {
$query->select('user_id')
->from('annotation_session_user')
->where('annotation_session_id', $this->id);
});
});
})
// that were created between the start and end date
->where('created_at', '>=', $this->starts_at)
->where('created_at', '<', $this->ends_at)
// and have a label by one of the members of this session
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('video_annotation_labels')
->whereRaw('video_annotation_labels.annotation_id = video_annotations.id')
->whereIn('video_annotation_labels.user_id', function ($query) {
$query->select('user_id')
->from('annotation_session_user')
->where('annotation_session_id', $this->id);
});
});
});
}
}
1 change: 0 additions & 1 deletion app/Console/Commands/MigrateTiledImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Biigle\Image;
use Biigle\Jobs\MigrateTiledImage;
use Biigle\Volume;
use Illuminate\Console\Command;
use Queue;

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/UpdateVideoMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function processVolume(Volume $volume)
$query = $volume->videos()
->where(function ($query) {
$query->whereNull('attrs->width')
->orWhereNull('attrs->height');
->orWhereNull('attrs->height');
});

if ($volume->isRemote()) {
Expand Down
4 changes: 1 addition & 3 deletions app/Console/Commands/UpdateVolumeUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ protected function updateVolumes($volumes)
$url = $volumes->first();
$prefix = $this->ask('Please enter the volume URL prefix that you want to replace with a storage disk.', dirname($url));

$matches = $volumes->filter(function ($url) use ($prefix) {
return strpos($url, $prefix) === 0;
});
$matches = $volumes->filter(fn ($url) => strpos($url, $prefix) === 0);
$matchesCount = $matches->count();

if ($matchesCount > 0) {
Expand Down
6 changes: 4 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ protected function schedule(Schedule $schedule): void
->daily()
->onOneServer();

$schedule->call(function () {
$schedule
->call(function () {
if (FederatedSearchInstance::withLocalToken()->exists()) {
GenerateFederatedSearchIndex::dispatch();
}
Expand All @@ -38,7 +39,8 @@ protected function schedule(Schedule $schedule): void
->hourlyAt(55)
->onOneServer();

$schedule->call(function () {
$schedule
->call(function () {
FederatedSearchInstance::withRemoteToken()
->eachById([UpdateFederatedSearchIndex::class, 'dispatch']);
})
Expand Down
3 changes: 0 additions & 3 deletions app/Events/ObjectTrackingFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use Biigle\Broadcasting\UserChannel;
use Biigle\User;
use Biigle\VideoAnnotation;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand Down
3 changes: 0 additions & 3 deletions app/Events/ObjectTrackingSucceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use Biigle\Broadcasting\UserChannel;
use Biigle\User;
use Biigle\VideoAnnotation;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/AnnotationSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Biigle\Http\Controllers\Api;

use Biigle\AnnotationSession;
use Biigle\Http\Requests\DestroyAnnotationSession;
use Biigle\Http\Requests\UpdateAnnotationSession;
use Biigle\Volume;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ public function index(Request $request, $tid, $uid)
$ownerKeyName = $fileRelation->getQualifiedOwnerKeyName();
$labelsRelation = $model->labels();

return $query->join($labelsRelation->getRelated()->getTable(), $labelsRelation->getQualifiedParentKeyName(), '=', $labelsRelation->getQualifiedForeignKeyName())
->where($labelsRelation->getRelated()->user()->getQualifiedForeignKeyName(), $uid)
->join($fileRelation->getRelated()->getTable(), $fileRelation->getQualifiedForeignKeyName(), '=', $ownerKeyName)
->where($fileRelation->getRelated()->volume()->getQualifiedForeignKeyName(), $tid)
->select($ownerKeyName)
->distinct()
->pluck($ownerKeyName);
return $query
->join($labelsRelation->getRelated()->getTable(), $labelsRelation->getQualifiedParentKeyName(), '=', $labelsRelation->getQualifiedForeignKeyName())
->where($labelsRelation->getRelated()->user()->getQualifiedForeignKeyName(), $uid)
->join($fileRelation->getRelated()->getTable(), $fileRelation->getQualifiedForeignKeyName(), '=', $ownerKeyName)
->where($fileRelation->getRelated()->volume()->getQualifiedForeignKeyName(), $tid)
->select($ownerKeyName)
->distinct()
->pluck($ownerKeyName);
}
}
3 changes: 1 addition & 2 deletions app/Http/Controllers/Api/AnnouncementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace Biigle\Http\Controllers\Api;

use Biigle\Http\Requests\StoreAnnouncement;
use Biigle\Announcement;
use Illuminate\Http\Request;
use Biigle\Http\Requests\StoreAnnouncement;

class AnnouncementController extends Controller
{
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/ImageAnnotationBulkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public function store(StoreImageAnnotations $request)
$annotations->each(function ($annotation) use ($request) {
$label = $request->labels[$annotation->label_id];
$confidence = $annotation->confidence;
unset($annotation->label_id);
unset($annotation->confidence);
unset($annotation->label_id, $annotation->confidence);

$this->authorize('attach-label', [$annotation, $label]);
$annotation->save();

Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function show($id)
return $image;
}


/**
* Shows the specified image file.
*
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/LabelTreeMergeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Biigle\Http\Controllers\Api;

use Biigle\Http\Controllers\Api\Controller;
use Biigle\Http\Requests\StoreLabelTreeMerge;
use Biigle\Label;
use DB;
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/Api/LabelTreeVersionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
use Biigle\Http\Requests\DestroyLabelTreeVersion;
use Biigle\Http\Requests\StoreLabelTreeVersion;
use Biigle\Http\Requests\UpdateLabelTreeVersion;
use Biigle\LabelTree;
use Biigle\LabelTreeVersion;
use DB;
use Ramsey\Uuid\Uuid;

class LabelTreeVersionController extends Controller
{

/**
* Creates a new label tree version.
*
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/Api/LinkVideoAnnotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Biigle\Http\Controllers\Api;

use Biigle\Http\Controllers\Api\Controller;
use Biigle\Http\Requests\LinkVideoAnnotation;
use Biigle\VideoAnnotation;
use Biigle\VideoAnnotationLabel;
use DB;

class LinkVideoAnnotationController extends Controller
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Biigle\Http\Requests\UpdateProject;
use Biigle\Project;
use Illuminate\Http\Request;
use Route;
use Symfony\Component\HttpKernel\Exception\HttpException;

class ProjectController extends Controller
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/Api/ProjectLabelTreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Biigle\Http\Requests\StoreProjectLabelTree;
use Biigle\LabelTree;
use Biigle\Project;
use Biigle\Visibility;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;

class ProjectLabelTreeController extends Controller
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/ProjectVolumeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Biigle\Http\Requests\StoreVolume;
use Biigle\Jobs\CreateNewImagesOrVideos;
use Biigle\MediaType;
use Biigle\Project;
use Biigle\Volume;
use DB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Biigle\Http\Controllers\Api;

use Biigle\Http\Controllers\Api\Controller;
use Biigle\Project;
use Biigle\Role;
use Biigle\Volume;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Biigle\Http\Controllers\Api;

use Biigle\Http\Controllers\Api\Controller;
use Biigle\Http\Requests\SplitVideoAnnotation;
use Biigle\Shape;
use Biigle\VideoAnnotation;
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/UserRegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Biigle\User;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Validation\ValidationException;

class UserRegistrationController extends Controller
{
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Biigle\Http\Controllers\Api;

use Biigle\Http\Requests\UpdateUserSettings;
use Illuminate\Http\Request;

class UserSettingsController extends Controller
{
Expand Down
Loading

0 comments on commit 759687c

Please sign in to comment.