diff --git a/app/Console/Commands/SyncUuids.php b/app/Console/Commands/SyncUuids.php index 99781edad..8263bdb40 100644 --- a/app/Console/Commands/SyncUuids.php +++ b/app/Console/Commands/SyncUuids.php @@ -105,7 +105,8 @@ protected function generateOutput() { $users = User::select('uuid', 'firstname', 'lastname', 'email')->get(); $bar = $this->output->createProgressBar($users->count()); - $users = $users->map(function ($user) use ($bar) { + $users = + $users->map(function ($user) use ($bar) { $bar->advance(); return [ diff --git a/app/Http/Controllers/Api/Import/ImportController.php b/app/Http/Controllers/Api/Import/ImportController.php index f47a160e2..6466b764b 100644 --- a/app/Http/Controllers/Api/Import/ImportController.php +++ b/app/Http/Controllers/Api/Import/ImportController.php @@ -3,11 +3,11 @@ namespace Biigle\Http\Controllers\Api\Import; use Biigle\Http\Controllers\Api\Controller; +use Biigle\Project; use Biigle\Services\Import\ArchiveManager; use Biigle\Services\Import\LabelTreeImport; use Biigle\Services\Import\UserImport; use Biigle\Services\Import\VolumeImport; -use Biigle\Project; use Biigle\Volume; use Exception; use Illuminate\Http\Request; diff --git a/app/Http/Controllers/Api/Import/PublicLabelTreeImportController.php b/app/Http/Controllers/Api/Import/PublicLabelTreeImportController.php index 3bb613c14..2e40b3ab6 100644 --- a/app/Http/Controllers/Api/Import/PublicLabelTreeImportController.php +++ b/app/Http/Controllers/Api/Import/PublicLabelTreeImportController.php @@ -4,8 +4,8 @@ use Biigle\Http\Controllers\Api\Controller; use Biigle\LabelTree; -use Biigle\Services\Import\ArchiveManager; use Biigle\Role; +use Biigle\Services\Import\ArchiveManager; use DB; use Exception; use Illuminate\Http\Request; diff --git a/app/Http/Controllers/Views/Admin/ImportController.php b/app/Http/Controllers/Views/Admin/ImportController.php index c76b3df94..7305ca872 100644 --- a/app/Http/Controllers/Views/Admin/ImportController.php +++ b/app/Http/Controllers/Views/Admin/ImportController.php @@ -4,11 +4,11 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\Label; +use Biigle\Role; use Biigle\Services\Import\ArchiveManager; use Biigle\Services\Import\LabelTreeImport; use Biigle\Services\Import\UserImport; use Biigle\Services\Import\VolumeImport; -use Biigle\Role; use Biigle\User; class ImportController extends Controller @@ -102,9 +102,7 @@ protected function showLabelTreeImport(LabelTreeImport $import, $token) $labelCandidates = $import->getLabelImportCandidates(); $labelCandidatesCount = $labelCandidates->count(); $conflictingParentIds = $labelCandidates->pluck('conflicting_parent_id') - ->reject(function ($id) { - return is_null($id); - }); + ->reject(fn ($id) => is_null($id)); if ($conflictingParentIds->isNotEmpty()) { $conflictingParents = Label::whereIn('id', $conflictingParentIds)->get(); } else { @@ -153,9 +151,7 @@ protected function showVolumeImport(VolumeImport $import, string $token) $labelCandidates = $import->getLabelImportCandidates(); $conflictingParentIds = $labelCandidates->pluck('conflicting_parent_id') - ->reject(function ($id) { - return is_null($id); - }); + ->reject(fn ($id) => is_null($id)); if ($conflictingParentIds->isNotEmpty()) { $conflictingParents = Label::whereIn('id', $conflictingParentIds)->get(); } else { diff --git a/app/Jobs/PostprocessVolumeImport.php b/app/Jobs/PostprocessVolumeImport.php index 01ac3dab0..0bf09d869 100644 --- a/app/Jobs/PostprocessVolumeImport.php +++ b/app/Jobs/PostprocessVolumeImport.php @@ -3,8 +3,6 @@ namespace Biigle\Jobs; use Biigle\Image; -use Biigle\Jobs\Job; -use Biigle\Jobs\ProcessNewVolumeFiles; use Biigle\Modules\Largo\Jobs\ProcessAnnotatedImage; use Biigle\Modules\Largo\Jobs\ProcessAnnotatedVideo; use Biigle\Video; diff --git a/app/Services/Export/LabelTreeExport.php b/app/Services/Export/LabelTreeExport.php index b12f66d96..7c028e072 100644 --- a/app/Services/Export/LabelTreeExport.php +++ b/app/Services/Export/LabelTreeExport.php @@ -12,7 +12,8 @@ class LabelTreeExport extends Export */ public function getContent() { - $trees = LabelTree::where(function ($query) { + $trees = + LabelTree::where(function ($query) { $query->whereIn('id', $this->ids) // Also add master trees of all included versioned trees. ->orWhereIn('id', function ($query) { diff --git a/app/Services/Import/Import.php b/app/Services/Import/Import.php index 62a72c888..470136ae9 100644 --- a/app/Services/Import/Import.php +++ b/app/Services/Import/Import.php @@ -69,9 +69,7 @@ protected function expectedFiles() */ protected function files() { - return array_map(function ($file) { - return File::basename($file); - }, File::files($this->path)); + return array_map(fn ($file) => File::basename($file), File::files($this->path)); } /** diff --git a/app/Services/Import/LabelTreeImport.php b/app/Services/Import/LabelTreeImport.php index 7b13ad534..a54e3aae2 100644 --- a/app/Services/Import/LabelTreeImport.php +++ b/app/Services/Import/LabelTreeImport.php @@ -10,7 +10,6 @@ use Biigle\Visibility; use Carbon\Carbon; use DB; -use Exception; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; @@ -52,9 +51,7 @@ public function perform(array $onlyTrees = null, array $onlyLabels = null, array $this->attachLabelTreeMembers($insertTrees, $labelTreeIdMap, $userIdMap); $labelCandidates = $this->getInsertLabels($onlyLabels, $labelTreeIdMap); - $labelHasConflict = function ($label) { - return array_key_exists('conflicting_name', $label) || array_key_exists('conflicting_parent_id', $label); - }; + $labelHasConflict = fn ($label) => array_key_exists('conflicting_name', $label) || array_key_exists('conflicting_parent_id', $label); $insertLabels = $labelCandidates->reject($labelHasConflict); // Insert all labels with parent_id null first. @@ -151,7 +148,8 @@ public function getLabelImportCandidates() // Add the conflicting attributes to the labels if there are any. Discard any // import labels that already exist and have no conflicts. Use values() to // discard the original keys. - return $labels->map(function ($label) use ($existingLabels) { + return $labels + ->map(function ($label) use ($existingLabels) { $existingLabel = $existingLabels->get($label['uuid']); if ($existingLabel) { $label['discard'] = true; @@ -171,9 +169,7 @@ public function getLabelImportCandidates() return $label; }) - ->reject(function ($label) { - return array_key_exists('discard', $label); - }) + ->reject(fn ($label) => array_key_exists('discard', $label)) ->values(); } @@ -248,16 +244,11 @@ protected function getInsertLabelTrees($onlyTrees) { $now = Carbon::now(); $candidates = $this->getLabelTreeImportCandidates(); - $trees = $candidates->when(is_array($onlyTrees), function ($collection) use ($onlyTrees) { - return $collection->whereIn('id', $onlyTrees); - }); + $trees = $candidates->when(is_array($onlyTrees), fn ($collection) => $collection->whereIn('id', $onlyTrees)); - $masterTreeIdsMissing = $trees->reject(function ($tree) { - return !array_key_exists('version', $tree) || is_null($tree['version']); - }) - ->map(function ($tree) { - return $tree['version']['label_tree_id']; - }); + $masterTreeIdsMissing = $trees + ->reject(fn ($tree) => !array_key_exists('version', $tree) || is_null($tree['version'])) + ->map(fn ($tree) => $tree['version']['label_tree_id']); $masterTrees = $candidates->whereIn('id', $masterTreeIdsMissing) ->whereNotIn('id', $trees->pluck('id')); @@ -308,10 +299,9 @@ protected function insertLabelTrees($trees) */ protected function insertLabelTreeVersions($insertTrees, $labelTreeIdMap) { - $this->getImportLabelTrees()->whereIn('uuid', $insertTrees->pluck('uuid')) - ->reject(function ($tree) { - return !array_key_exists('version', $tree) || is_null($tree['version']); - }) + $this->getImportLabelTrees() + ->whereIn('uuid', $insertTrees->pluck('uuid')) + ->reject(fn ($tree) => !array_key_exists('version', $tree) || is_null($tree['version'])) ->each(function ($tree) use ($labelTreeIdMap) { $id = LabelTreeVersion::insertGetId([ 'name' => $tree['version']['name'], @@ -336,9 +326,7 @@ protected function getInsertUserIds($trees) ->whereIn('uuid', $trees->pluck('uuid')) ->pluck('members') ->collapse() - ->filter(function ($user) { - return $user['role_id'] === Role::adminId(); - }) + ->filter(fn ($user) => $user['role_id'] === Role::adminId()) ->pluck('id') ->unique() ->toArray(); @@ -363,9 +351,7 @@ protected function attachLabelTreeMembers($trees, $labelTreeIdMap, $userIdMap) }, $tree['members']); }) ->collapse() - ->filter(function ($user) use ($userIdMap) { - return array_key_exists($user['id'], $userIdMap); - }) + ->filter(fn ($user) => array_key_exists($user['id'], $userIdMap)) ->map(function ($member) use ($labelTreeIdMap, $userIdMap) { return [ 'user_id' => $userIdMap[$member['id']], @@ -387,9 +373,7 @@ protected function attachLabelTreeMembers($trees, $labelTreeIdMap, $userIdMap) */ protected function getInsertLabels($onlyLabels, $labelTreeIdMap) { - $importedTrees = array_keys(array_filter($labelTreeIdMap, function ($value, $key) { - return $key !== $value; - }, ARRAY_FILTER_USE_BOTH)); + $importedTrees = array_keys(array_filter($labelTreeIdMap, fn ($value, $key) => $key !== $value, ARRAY_FILTER_USE_BOTH)); // As the import label trees have been imported at this point, their import // labels are included in the candidates now, too. @@ -455,7 +439,8 @@ protected function insertLabels($labels, $labelTreeIdMap) */ protected function updateInsertedLabelParentIds($labels, $labelIdMap) { - $labels->reject(function ($label) use ($labelIdMap) { + $labels + ->reject(function ($label) use ($labelIdMap) { return is_null($label['parent_id']) || // This might be the case if a user selectively imports a child label // but not its parent. @@ -477,29 +462,23 @@ protected function updateInsertedLabelParentIds($labels, $labelIdMap) */ protected function mergeLabels($mergeLabels, $nameConflictResolution, $parentConflictResolution, $labelIdMap) { - $nameConflicts = $mergeLabels->filter(function ($label) { - return array_key_exists('conflicting_name', $label); - }) + $nameConflicts = $mergeLabels + ->filter(fn ($label) => array_key_exists('conflicting_name', $label)) ->each(function ($label) use ($nameConflictResolution) { if (!array_key_exists($label['id'], $nameConflictResolution)) { throw new UnprocessableEntityHttpException("Unresolved name conflict for label '{$label['name']}'."); } }) - ->filter(function ($label) use ($nameConflictResolution) { - return $nameConflictResolution[$label['id']] === 'import'; - }); + ->filter(fn ($label) => $nameConflictResolution[$label['id']] === 'import'); - $parentConflicts = $mergeLabels->filter(function ($label) { - return array_key_exists('conflicting_parent_id', $label); - }) + $parentConflicts = $mergeLabels + ->filter(fn ($label) => array_key_exists('conflicting_parent_id', $label)) ->each(function ($label) use ($parentConflictResolution) { if (!array_key_exists($label['id'], $parentConflictResolution)) { throw new UnprocessableEntityHttpException("Unresolved parent conflict for label '{$label['name']}'."); } }) - ->filter(function ($label) use ($parentConflictResolution) { - return $parentConflictResolution[$label['id']] === 'import'; - }); + ->filter(fn ($label) => $parentConflictResolution[$label['id']] === 'import'); // Resolve name and parent conflicts *after* the check if every conflict has a // resolution. diff --git a/app/Services/Import/UserImport.php b/app/Services/Import/UserImport.php index c254d730b..136aac2cd 100644 --- a/app/Services/Import/UserImport.php +++ b/app/Services/Import/UserImport.php @@ -28,15 +28,11 @@ public function perform(array $only = null) $users = $this->getImportUsers(); $now = Carbon::now(); $candidates = $this->getUserImportCandidates() - ->when(is_array($only), function ($collection) use ($only) { - return $collection->whereIn('id', $only); - }); + ->when(is_array($only), fn ($collection) => $collection->whereIn('id', $only)); $conflicts = $candidates->whereIn('id', $this->getConflicts()->pluck('id')); if ($conflicts->isNotEmpty()) { - $users = $conflicts->map(function ($user) { - return "{$user['firstname']} {$user['lastname']} ({$user['email']})"; - })->implode(', '); + $users = $conflicts->map(fn ($user) => "{$user['firstname']} {$user['lastname']} ({$user['email']})")->implode(', '); throw new UnprocessableEntityHttpException("Import cannot be performed. The following users exist according to their email address but the UUIDs do not match: {$users}."); } @@ -132,8 +128,6 @@ protected function getConflicts() $users = $this->getImportUsers(); $existing = User::whereIn('email', $users->pluck('email'))->pluck('uuid', 'email'); - return $users->filter(function ($user) use ($existing) { - return $existing->has($user['email']) && $user['uuid'] !== $existing->get($user['email']); - }); + return $users->filter(fn ($user) => $existing->has($user['email']) && $user['uuid'] !== $existing->get($user['email'])); } } diff --git a/app/Services/Import/VolumeImport.php b/app/Services/Import/VolumeImport.php index 6a6e3497b..fa767ffa6 100644 --- a/app/Services/Import/VolumeImport.php +++ b/app/Services/Import/VolumeImport.php @@ -8,7 +8,6 @@ use Biigle\ImageLabel; use Biigle\Jobs\PostprocessVolumeImport; use Biigle\Label; -use Biigle\LabelTree; use Biigle\MediaType; use Biigle\Project; use Biigle\Rules\VolumeUrl; @@ -19,7 +18,6 @@ use Biigle\VideoLabel; use Biigle\Volume; use DB; -use Exception; use Illuminate\Support\Collection; use Ramsey\Uuid\Uuid; use SplFileObject; @@ -63,9 +61,7 @@ public function perform(Project $project, User $creator, array $only = null, arr { return DB::transaction(function () use ($project, $creator, $only, $newUrls, $nameConflictResolution, $parentConflictResolution) { $volumeCandidates = $this->getVolumeImportCandidates() - ->when(is_array($only), function ($collection) use ($only) { - return $collection->whereIn('id', $only); - }) + ->when(is_array($only), fn ($collection) => $collection->whereIn('id', $only)) ->keyBy('id'); $volumes = $this->insertVolumes($volumeCandidates, $creator, $newUrls); @@ -168,9 +164,7 @@ public function getVolumeImportCandidates() $volume['labels'] = []; } - $volume['label_trees'] = array_values(array_unique(array_map(function ($id) use ($labelToTreeMap) { - return $labelToTreeMap[$id]; - }, $volume['labels']))); + $volume['label_trees'] = array_values(array_unique(array_map(fn ($id) => $labelToTreeMap[$id], $volume['labels']))); return $volume; }); @@ -425,13 +419,8 @@ protected function getRequiredEntities() } } - $labels = array_map(function ($ids) { - return array_values(array_unique($ids)); - }, $labels); - - $users = array_map(function ($ids) { - return array_values(array_unique($ids)); - }, $users); + $labels = array_map(fn ($ids) => array_values(array_unique($ids)), $labels); + $users = array_map(fn ($ids) => array_values(array_unique($ids)), $users); return compact('labels', 'users'); } @@ -449,7 +438,8 @@ protected function insertVolumes(Collection $candidates, User $creator, array $n { $mediaTypes = MediaType::pluck('id', 'name'); - return $candidates->map(function ($candidate) use ($creator, $newUrls, $mediaTypes) { + return $candidates + ->map(function ($candidate) use ($creator, $newUrls, $mediaTypes) { $volume = new Volume; $volume->old_id = $candidate['id']; $volume->name = $candidate['name']; diff --git a/tests/php/Http/Controllers/Api/Import/ImportControllerTest.php b/tests/php/Http/Controllers/Api/Import/ImportControllerTest.php index 0e4d42dd6..a7a0ccb1a 100644 --- a/tests/php/Http/Controllers/Api/Import/ImportControllerTest.php +++ b/tests/php/Http/Controllers/Api/Import/ImportControllerTest.php @@ -3,12 +3,12 @@ namespace Biigle\Tests\Http\Controllers\Api\Import; use ApiTestCase; +use Biigle\Project; use Biigle\Services\Export\UserExport; use Biigle\Services\Import\ArchiveManager; use Biigle\Services\Import\LabelTreeImport; use Biigle\Services\Import\UserImport; use Biigle\Services\Import\VolumeImport; -use Biigle\Project; use Biigle\Tests\ProjectTest; use Biigle\Tests\UserTest; use Biigle\User; @@ -23,9 +23,7 @@ public function testStore() { $mock = Mockery::mock(ArchiveManager::class); $mock->shouldReceive('store')->once()->andReturn('123abc'); - $this->app->bind(ArchiveManager::class, function () use ($mock) { - return $mock; - }); + $this->app->bind(ArchiveManager::class, fn () => $mock); $user = UserTest::create(); $path = (new UserExport([$user->id]))->getArchive(); @@ -54,9 +52,7 @@ public function testStoreInvalid() $mock = Mockery::mock(ArchiveManager::class); $e = new Exception('my error message'); $mock->shouldReceive('store')->once()->andThrow($e); - $this->app->bind(ArchiveManager::class, function () use ($mock) { - return $mock; - }); + $this->app->bind(ArchiveManager::class, fn () => $mock); $export = new UserExport([$this->user()->id]); $path = $export->getArchive(); @@ -77,9 +73,7 @@ public function testUpdate() ->with('abc123') ->andReturn(null, $importMock); $managerMock->shouldReceive('delete')->once(); - $this->app->bind(ArchiveManager::class, function () use ($managerMock) { - return $managerMock; - }); + $this->app->bind(ArchiveManager::class, fn () => $managerMock); $this->doTestApiRoute('PUT', '/api/v1/import/abc123'); @@ -174,7 +168,8 @@ public function testUpdateLabelTreeImportConflictingNames() ->assertStatus(422); $this->putJson('/api/v1/import/abc123', ['name_conflicts' => [1 => 'a']]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'name_conflicts' => [1 => 'import', 2 => 'existing'], ]) ->assertStatus(200); @@ -192,7 +187,8 @@ public function testUpdateLabelTreeImportConflictingParents() ->assertStatus(422); $this->putJson('/api/v1/import/abc123', ['parent_conflicts' => [1 => 'a']]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'parent_conflicts' => [1 => 'import', 2 => 'existing'], ]) ->assertStatus(200); @@ -219,17 +215,20 @@ public function testUpdateVolumeImportOnlyVolumes() $this->beGlobalAdmin(); $p = ProjectTest::create(); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'only' => 'abc', ]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'only' => ['a'], ]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'only' => [1, 2, 3], ]) @@ -245,17 +244,20 @@ public function testUpdateVolumeImportConflictingNames() $this->beGlobalAdmin(); $p = ProjectTest::create(); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'name_conflicts' => 'abc', ]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'name_conflicts' => ['a'], ]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'name_conflicts' => [1 => 'existing'], ]) @@ -271,17 +273,20 @@ public function testUpdateVolumeImportConflictingParents() $this->beGlobalAdmin(); $p = ProjectTest::create(); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'parent_conflicts' => 'abc', ]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'parent_conflicts' => ['a'], ]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'parent_conflicts' => [1 => 'existing'], ]) @@ -297,12 +302,14 @@ public function testUpdateVolumeImportNewVolumeUrls() $this->beGlobalAdmin(); $p = ProjectTest::create(); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'new_urls' => 'abc', ]) ->assertStatus(422); - $this->putJson('/api/v1/import/abc123', [ + $this + ->putJson('/api/v1/import/abc123', [ 'project_id' => $p->id, 'new_urls' => ['a'], ]) @@ -314,9 +321,7 @@ public function testDestroy() $mock = Mockery::mock(ArchiveManager::class); $mock->shouldReceive('has')->twice()->with('abc123')->andReturn(false, true); $mock->shouldReceive('delete')->once()->with('abc123'); - $this->app->bind(ArchiveManager::class, function () use ($mock) { - return $mock; - }); + $this->app->bind(ArchiveManager::class, fn () => $mock); $this->doTestApiRoute('DELETE', '/api/v1/import/abc123'); @@ -339,9 +344,7 @@ protected function makeImportMock($class, $token = 'abc123', $delete = true) if ($delete) { $managerMock->shouldReceive('delete')->once(); } - $this->app->bind(ArchiveManager::class, function () use ($managerMock) { - return $managerMock; - }); + $this->app->bind(ArchiveManager::class, fn () => $managerMock); return $importMock; } diff --git a/tests/php/Http/Controllers/Api/Import/PublicLabelTreeImportControllerTest.php b/tests/php/Http/Controllers/Api/Import/PublicLabelTreeImportControllerTest.php index ddbbfe8ff..414317647 100644 --- a/tests/php/Http/Controllers/Api/Import/PublicLabelTreeImportControllerTest.php +++ b/tests/php/Http/Controllers/Api/Import/PublicLabelTreeImportControllerTest.php @@ -3,10 +3,10 @@ namespace Biigle\Tests\Http\Controllers\Api\Import; use ApiTestCase; +use Biigle\Role; use Biigle\Services\Export\PublicLabelTreeExport; use Biigle\Services\Import\ArchiveManager; use Biigle\Services\Import\PublicLabelTreeImport; -use Biigle\Role; use Biigle\Tests\LabelTreeTest; use Exception; use Illuminate\Http\UploadedFile; @@ -19,9 +19,7 @@ public function testStoreValidation() $mock = Mockery::mock(ArchiveManager::class); $mock->shouldReceive('store')->once()->andReturn('123abc'); $mock->shouldReceive('delete')->once()->with('123abc'); - $this->app->bind(ArchiveManager::class, function () use ($mock) { - return $mock; - }); + $this->app->bind(ArchiveManager::class, fn () => $mock); $labelTree = LabelTreeTest::create(); $path = (new PublicLabelTreeExport([$labelTree->id]))->getArchive(); @@ -53,9 +51,7 @@ public function testStore() ->with('123abc') ->andReturn($importMock); $managerMock->shouldReceive('delete')->once()->with('123abc'); - $this->app->bind(ArchiveManager::class, function () use ($managerMock) { - return $managerMock; - }); + $this->app->bind(ArchiveManager::class, fn () => $managerMock); $labelTree = LabelTreeTest::create(); $path = (new PublicLabelTreeExport([$labelTree->id]))->getArchive(); @@ -77,9 +73,7 @@ public function testStoreValidationException() { $mock = Mockery::mock(ArchiveManager::class); $mock->shouldReceive('store')->once()->andThrow(Exception::class); - $this->app->bind(ArchiveManager::class, function () use ($mock) { - return $mock; - }); + $this->app->bind(ArchiveManager::class, fn () => $mock); $labelTree = LabelTreeTest::create(); $path = (new PublicLabelTreeExport([$labelTree->id]))->getArchive(); diff --git a/tests/php/Http/Controllers/Views/LabelTrees/PublicImportControllerTest.php b/tests/php/Http/Controllers/Views/LabelTrees/PublicImportControllerTest.php index 623d23350..7a9ec05e8 100644 --- a/tests/php/Http/Controllers/Views/LabelTrees/PublicImportControllerTest.php +++ b/tests/php/Http/Controllers/Views/LabelTrees/PublicImportControllerTest.php @@ -3,11 +3,6 @@ namespace Biigle\Tests\Http\Controllers\Views; use ApiTestCase; -use Biigle\Services\Export\LabelTreeExport; -use Biigle\Services\Export\UserExport; -use Biigle\Services\Export\VolumeExport; -use Biigle\Services\Import\ArchiveManager; -use Illuminate\Http\UploadedFile; class PublicImportControllerTest extends ApiTestCase { diff --git a/tests/php/Jobs/PostprocessVolumeImportTest.php b/tests/php/Jobs/PostprocessVolumeImportTest.php index f81546709..43c754337 100644 --- a/tests/php/Jobs/PostprocessVolumeImportTest.php +++ b/tests/php/Jobs/PostprocessVolumeImportTest.php @@ -2,10 +2,10 @@ namespace Biigle\Tests\Jobs; +use Biigle\Jobs\PostprocessVolumeImport; use Biigle\Jobs\ProcessNewVolumeFiles; use Biigle\Modules\Largo\Jobs\ProcessAnnotatedImage; use Biigle\Modules\Largo\Jobs\ProcessAnnotatedVideo; -use Biigle\Jobs\PostprocessVolumeImport; use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\ImageTest; use Biigle\Tests\VideoAnnotationTest; diff --git a/tests/php/Services/Export/LabelTreeExportTest.php b/tests/php/Services/Export/LabelTreeExportTest.php index 200d832df..f227a1ec1 100644 --- a/tests/php/Services/Export/LabelTreeExportTest.php +++ b/tests/php/Services/Export/LabelTreeExportTest.php @@ -2,8 +2,8 @@ namespace Biigle\Tests\Services\Export; -use Biigle\Services\Export\LabelTreeExport; use Biigle\Role; +use Biigle\Services\Export\LabelTreeExport; use Biigle\Tests\LabelTest; use Biigle\Tests\LabelTreeTest; use Biigle\Tests\LabelTreeVersionTest; diff --git a/tests/php/Services/Export/PublicLabelExportTest.php b/tests/php/Services/Export/PublicLabelExportTest.php index c1b391661..dadeb3e11 100644 --- a/tests/php/Services/Export/PublicLabelExportTest.php +++ b/tests/php/Services/Export/PublicLabelExportTest.php @@ -3,7 +3,6 @@ namespace Biigle\Tests\Services\Export; use Biigle\Services\Export\PublicLabelExport; -use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\LabelTest; use File; use SplFileObject; diff --git a/tests/php/Services/Export/PublicLabelTreeExportTest.php b/tests/php/Services/Export/PublicLabelTreeExportTest.php index 801a5c06d..a022512f6 100644 --- a/tests/php/Services/Export/PublicLabelTreeExportTest.php +++ b/tests/php/Services/Export/PublicLabelTreeExportTest.php @@ -2,8 +2,8 @@ namespace Biigle\Tests\Services\Export; -use Biigle\Services\Export\PublicLabelTreeExport; use Biigle\Role; +use Biigle\Services\Export\PublicLabelTreeExport; use Biigle\Tests\LabelTest; use Biigle\Tests\LabelTreeTest; use Biigle\Tests\LabelTreeVersionTest; diff --git a/tests/php/Services/Export/VolumeExportTest.php b/tests/php/Services/Export/VolumeExportTest.php index 9ca8c68af..99cf7160b 100644 --- a/tests/php/Services/Export/VolumeExportTest.php +++ b/tests/php/Services/Export/VolumeExportTest.php @@ -64,18 +64,14 @@ public function testGetAdditionalExports() $this->assertCount(10, $exports); $userContent = $exports[0]->getContent(); - $userIds = array_map(function ($user) { - return $user['id']; - }, $userContent); + $userIds = array_map(fn ($user) => $user['id'], $userContent); $this->assertContains($imageAnnotationLabel->user->id, $userIds); $this->assertContains($imageLabel->user->id, $userIds); $this->assertContains($videoAnnotationLabel->user->id, $userIds); $this->assertContains($videoLabel->user->id, $userIds); $labelTreeContent = $exports[1]->getContent(); - $ids = array_map(function ($labelTree) { - return $labelTree['id']; - }, $labelTreeContent); + $ids = array_map(fn ($labelTree) => $labelTree['id'], $labelTreeContent); $this->assertContains($imageAnnotationLabel->label->label_tree_id, $ids); $this->assertContains($imageLabel->label->label_tree_id, $ids); $this->assertContains($videoAnnotationLabel->label->label_tree_id, $ids); diff --git a/tests/php/Services/Import/LabelTreeImportTest.php b/tests/php/Services/Import/LabelTreeImportTest.php index 1af284f7d..91070ed3e 100644 --- a/tests/php/Services/Import/LabelTreeImportTest.php +++ b/tests/php/Services/Import/LabelTreeImportTest.php @@ -4,9 +4,9 @@ use Biigle\Label; use Biigle\LabelTree; +use Biigle\Role; use Biigle\Services\Export\LabelTreeExport; use Biigle\Services\Import\LabelTreeImport; -use Biigle\Role; use Biigle\Tests\LabelTest; use Biigle\Tests\LabelTreeTest; use Biigle\Tests\LabelTreeVersionTest; @@ -501,6 +501,7 @@ protected function getImport(array $ids, $class = LabelTreeImportStub::class) class LabelTreeImportStub extends LabelTreeImport { public $throw; + protected function mergeLabels($mergeLabels, $nameConflictResolution, $parentConflictResolution, $labelIdMap) { if ($this->throw) { diff --git a/tests/php/Services/Import/PublicLabelTreeImportTest.php b/tests/php/Services/Import/PublicLabelTreeImportTest.php index 2caf25dbd..3c365d764 100644 --- a/tests/php/Services/Import/PublicLabelTreeImportTest.php +++ b/tests/php/Services/Import/PublicLabelTreeImportTest.php @@ -2,20 +2,16 @@ namespace Biigle\Tests\Services\Import; -use Biigle\Label; use Biigle\LabelTree; +use Biigle\Role; use Biigle\Services\Export\PublicLabelTreeExport; use Biigle\Services\Import\PublicLabelTreeImport; -use Biigle\Role; use Biigle\Tests\LabelTest; use Biigle\Tests\LabelTreeTest; -use Biigle\Tests\LabelTreeVersionTest; use Biigle\Tests\UserTest; -use Biigle\User; use Biigle\Visibility; use Exception; use File; -use Ramsey\Uuid\Uuid; use TestCase; use ZipArchive; diff --git a/tests/php/Services/Import/VolumeImportTest.php b/tests/php/Services/Import/VolumeImportTest.php index 392362dc5..824edf2ee 100644 --- a/tests/php/Services/Import/VolumeImportTest.php +++ b/tests/php/Services/Import/VolumeImportTest.php @@ -2,13 +2,13 @@ namespace Biigle\Tests\Services\Import; +use Biigle\Jobs\PostprocessVolumeImport; use Biigle\Label; use Biigle\LabelTree; use Biigle\MediaType; -use Biigle\Jobs\PostprocessVolumeImport; +use Biigle\Role; use Biigle\Services\Export\VolumeExport; use Biigle\Services\Import\VolumeImport; -use Biigle\Role; use Biigle\Tests\ImageAnnotationLabelTest; use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\ImageLabelTest;