Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply coding style #652

Merged
merged 14 commits into from
Oct 11, 2023
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ npm-debug.log
yarn-error.log
/*.sublime-*
/*.phar
/*.php_cs.cache
/*.php-cs-fixer.cache
/.idea
/.vscode
10 changes: 4 additions & 6 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
->setRules([
'@PSR2' => true,
'ordered_imports' => true,
'single_space_after_construct' => true,
'single_quote' => true,
'single_space_around_construct' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
Expand All @@ -21,10 +20,9 @@
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
'method_chaining_indentation' => true,
mzur marked this conversation as resolved.
Show resolved Hide resolved
'heredoc_indentation' => [
'indentation' => 'start_plus_one',
],

'use_arrow_functions' => true,
'no_unused_imports' => true
])
->setFinder($finder)
->setRiskyAllowed(true)
->setUsingCache(true);
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.
14 changes: 9 additions & 5 deletions app/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function scopeVisibleFor($query, User $user)
->join($ownerTable, $ownerKeyName, '=', $foreignKeyName)
->join('project_volume', 'project_volume.volume_id', '=', "{$ownerTable}.volume_id")
->whereIn('project_volume.project_id', function ($query) use ($user) {
$query->select('project_id')
$query
->select('project_id')
->from('project_user')
->where('user_id', $user->id);
mzur marked this conversation as resolved.
Show resolved Hide resolved
});
Expand Down Expand Up @@ -109,8 +110,9 @@ public function scopeAllowedBySession($query, AnnotationSession $session, User $
$foreignKeyName = $this->labels()->getQualifiedForeignKeyName();
$foreignTable = explode('.', $foreignKeyName)[0];
$parentKeyName = $this->labels()->getQualifiedParentKeyName();

$query->select(DB::raw(1))

$query
->select(DB::raw(1))
->from($foreignTable)
->whereRaw("{$foreignKeyName} = {$parentKeyName}")
->where("{$foreignTable}.user_id", $user->id);
Expand All @@ -126,7 +128,8 @@ public function scopeAllowedBySession($query, AnnotationSession $session, User $
$foreignTable = explode('.', $foreignKeyName)[0];
$parentKeyName = $this->labels()->getQualifiedParentKeyName();

$query->select(DB::raw(1))
$query
->select(DB::raw(1))
->from($foreignTable)
->whereRaw("{$foreignKeyName} = {$parentKeyName}")
->where("{$foreignTable}.user_id", '!=', $user->id);
Expand All @@ -140,7 +143,8 @@ public function scopeAllowedBySession($query, AnnotationSession $session, User $
$foreignTable = explode('.', $foreignKeyName)[0];
$parentKeyName = $this->labels()->getQualifiedParentKeyName();

$query->select(DB::raw(1))
$query
->select(DB::raw(1))
->from($foreignTable)
->whereRaw("{$foreignKeyName} = {$parentKeyName}")
->where("{$foreignTable}.user_id", $user->id);
Expand Down
71 changes: 39 additions & 32 deletions app/AnnotationSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ public function getVolumeFileAnnotations(VolumeFile $file, User $user)
// wrap this in a where because the default query already has a where
$query->where(function ($query) use ($user) {
$query->where(function ($query) {
mzur marked this conversation as resolved.
Show resolved Hide resolved
$query->where('created_at', '>=', $this->starts_at)
$query
->where('created_at', '>=', $this->starts_at)
mzur marked this conversation as resolved.
Show resolved Hide resolved
->where('created_at', '<', $this->ends_at);
})
->orWhere('user_id', '!=', $user->id);
->orWhere('user_id', '!=', $user->id);
mzur marked this conversation as resolved.
Show resolved Hide resolved
});
}]);
} else {
Expand Down Expand Up @@ -206,24 +207,27 @@ public function imageAnnotations()
return ImageAnnotation::where(function ($query) {
// all annotations of the associated volume
return $query->whereIn('image_id', function ($query) {
$query->select('id')
->from('images')
->where('volume_id', $this->volume_id);
$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)
->where('created_at', '>=', $this->starts_at)
->where('created_at', '<', $this->ends_at)
mzur marked this conversation as resolved.
Show resolved Hide resolved
// and have a label by one of the members of this session
mzur marked this conversation as resolved.
Show resolved Hide resolved
->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);
});
});
->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 @@ -239,24 +243,27 @@ public function videoAnnotations()
return VideoAnnotation::where(function ($query) {
// all annotations of the associated volume
return $query->whereIn('video_id', function ($query) {
$query->select('id')
->from('videos')
->where('volume_id', $this->volume_id);
$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)
->where('created_at', '>=', $this->starts_at)
->where('created_at', '<', $this->ends_at)
mzur marked this conversation as resolved.
Show resolved Hide resolved
// 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);
});
});
->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);
});
});
});
}
}
3 changes: 2 additions & 1 deletion app/Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public static function getActive()
public function scopeActive($query)
{
return $query->where(function ($query) {
$query->whereNull('show_until')
$query
->whereNull('show_until')
->orWhere('show_until', '>', now());
});
}
Expand Down
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
11 changes: 7 additions & 4 deletions app/Console/Commands/UpdateVideoMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public function handle()

public function processVolume(Volume $volume)
{
$query = $volume->videos()
$query = $volume
->videos()
->where(function ($query) {
$query->whereNull('attrs->width')
->orWhereNull('attrs->height');
$query
->whereNull('attrs->width')
->orWhereNull('attrs->height');
});

if ($volume->isRemote()) {
Expand Down Expand Up @@ -93,7 +95,8 @@ public function processRemoteVideo(Video $video)
$this->line('Processing '.$video->url);

try {
$dimensions = $this->ffprobe->streams($video->url)
$dimensions = $this->ffprobe
->streams($video->url)
->videos()
->first()
->getDimensions();
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
20 changes: 11 additions & 9 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,31 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('queue:prune-batches')
$schedule
->command('queue:prune-batches')
->daily()
->onOneServer();

$schedule->command('prune-notifications')
$schedule
->command('prune-notifications')
->daily()
->onOneServer();

$schedule->call(function () {
if (FederatedSearchInstance::withLocalToken()->exists()) {
GenerateFederatedSearchIndex::dispatch();
}
})
if (FederatedSearchInstance::withLocalToken()->exists()) {
GenerateFederatedSearchIndex::dispatch();
}
})
->name('generate-federated-search-index')
// The requests to retrieve the federated search index are sent hourly at 05.
// This should not collide with this job to generate the index.
->hourlyAt(55)
->onOneServer();

$schedule->call(function () {
FederatedSearchInstance::withRemoteToken()
->eachById([UpdateFederatedSearchIndex::class, 'dispatch']);
})
FederatedSearchInstance::withRemoteToken()
->eachById([UpdateFederatedSearchIndex::class, 'dispatch']);
})
->name('update-federated-search-index')
// The jobs to generate the federated search index are run hourly at 55.
// This should not collide with this job to request the index from another
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
19 changes: 12 additions & 7 deletions 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 Expand Up @@ -50,7 +49,8 @@ public function update(UpdateAnnotationSession $request)
$session = $request->session;

if ($request->filled('starts_at')) {
$newStartsAt = Carbon::parse($request->input('starts_at'))
$newStartsAt = Carbon::parse($request
->input('starts_at'))
mzur marked this conversation as resolved.
Show resolved Hide resolved
->tz(config('app.timezone'));

if (!$request->input('force') && $session->annotations()->where('created_at', '<', $newStartsAt)->exists()) {
Expand All @@ -61,7 +61,8 @@ public function update(UpdateAnnotationSession $request)
}

if ($request->filled('ends_at')) {
$newEndsAt = Carbon::parse($request->input('ends_at'))
$newEndsAt = Carbon::parse($request
->input('ends_at'))
->tz(config('app.timezone'));

if (!$request->input('force') && $session->annotations()->where('created_at', '>=', $newEndsAt)->exists()) {
Expand Down Expand Up @@ -94,15 +95,18 @@ public function update(UpdateAnnotationSession $request)
if ($lostUsers->count() > 0) {
// Check if there are any annotations of the users that should no
// longer belong to the annotation session.
$wouldLooseAnnotations = $session->annotations()
$wouldLooseAnnotations = $session
->annotations()
->whereExists(function ($query) use ($session, $lostUsers) {
// This must work with image annotations and video
// annotations.
$labelModel = $session->annotations()
$labelModel = $session
->annotations()
->getModel()
->labels()
->getRelated();
$query->select(DB::raw(1))
$query
->select(DB::raw(1))
->from($labelModel->getTable())
->whereRaw($labelModel->annotation()->getQualifiedForeignKeyName().' = '.$labelModel->annotation()->getQualifiedOwnerKeyName())
->whereIn($labelModel->user()->getQualifiedForeignKeyName(), $lostUsers);
Expand All @@ -116,7 +120,8 @@ public function update(UpdateAnnotationSession $request)
}

// count users of all attached projects that match the given user IDs
$count = $session->volume->users()
$count = $session->volume
->users()
->whereIn('id', $users)
->count();

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function index($id)
$labelsRelation = $model->labels();
$labelsForeignKey = $labelsRelation->getRelated()->label()->getQualifiedForeignKeyName();
// take only labels that are used in annotations of this volume
$query->select(DB::raw(1))
$query
->select(DB::raw(1))
->from($fileRelation->getRelated()->getTable())
->join($model->getTable(), $fileRelation->getQualifiedOwnerKeyName(), '=', $fileRelation->getQualifiedForeignKeyName())
->join($labelsRelation->getRelated()->getTable(), $labelsRelation->getQualifiedParentKeyName(), '=', $labelsRelation->getQualifiedForeignKeyName())
Expand Down
Loading