Code Duplication    Length = 4-5 lines in 5 locations

code/Controller/AssetAdmin.php 5 locations

@@ 285-288 (lines=4) @@
282
        $fileIds = $vars['ids'];
283
        $files = $this->getList()->filter("ID", $fileIds)->toArray();
284
285
        if (!count($files)) {
286
            return (new HTTPResponse(json_encode(['status' => 'error']), 404))
287
                ->addHeader('Content-Type', 'application/json');
288
        }
289
290
        if (!min(array_map(function (File $file) {
291
            return $file->canDelete();
@@ 344-347 (lines=4) @@
341
        $file = Injector::inst()->create($fileClass);
342
343
        // check canCreate permissions
344
        if (!$file->canCreate(null, $data)) {
345
            return (new HTTPResponse(json_encode(['status' => 'error']), 403))
346
                ->addHeader('Content-Type', 'application/json');
347
        }
348
349
        $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/');
350
        if(!$uploadResult) {
@@ 350-354 (lines=5) @@
347
        }
348
349
        $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/');
350
        if(!$uploadResult) {
351
            $result = ['error' => 'unknown'];
352
            return (new HTTPResponse(json_encode($result), 400))
353
                ->addHeader('Content-Type', 'application/json');
354
        }
355
356
        $file->ParentID = $parentRecord ? $parentRecord->ID : 0;
357
        $file->write();
@@ 670-673 (lines=4) @@
667
        $id = (int) $data['ID'];
668
        $record = $this->getList()->filter('ID', $id)->first();
669
670
        if (!$record) {
671
            return (new HTTPResponse(json_encode(['status' => 'error']), 404))
672
                ->addHeader('Content-Type', 'application/json');
673
        }
674
675
        if (!$record->canEdit()) {
676
            return (new HTTPResponse(json_encode(['status' => 'error']), 401))
@@ 675-678 (lines=4) @@
672
                ->addHeader('Content-Type', 'application/json');
673
        }
674
675
        if (!$record->canEdit()) {
676
            return (new HTTPResponse(json_encode(['status' => 'error']), 401))
677
                ->addHeader('Content-Type', 'application/json');
678
        }
679
680
        $form->saveInto($record);
681
        $record->write();