Code Duplication    Length = 4-5 lines in 4 locations

code/Controller/AssetAdmin.php 4 locations

@@ 647-650 (lines=4) @@
644
        /** @var File $record */
645
        $record = $this->getList()->filter('ID', $id)->first();
646
647
        if (!$record) {
648
            return (new HTTPResponse(json_encode(['status' => 'error']), 404))
649
                ->addHeader('Content-Type', 'application/json');
650
        }
651
652
        if (!$record->canEdit() || ($doPublish && !$record->canPublish())) {
653
            return (new HTTPResponse(json_encode(['status' => 'error']), 401))
@@ 286-289 (lines=4) @@
283
        $fileIds = $vars['ids'];
284
        $files = $this->getList()->filter("ID", $fileIds)->toArray();
285
286
        if (!count($files)) {
287
            return (new HTTPResponse(json_encode(['status' => 'error']), 404))
288
                ->addHeader('Content-Type', 'application/json');
289
        }
290
291
        if (!min(array_map(function (File $file) {
292
            return $file->canDelete();
@@ 345-348 (lines=4) @@
342
        $file = Injector::inst()->create($fileClass);
343
344
        // check canCreate permissions
345
        if (!$file->canCreate(null, $data)) {
346
            return (new HTTPResponse(json_encode(['status' => 'error']), 403))
347
                ->addHeader('Content-Type', 'application/json');
348
        }
349
350
        $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/');
351
        if(!$uploadResult) {
@@ 351-355 (lines=5) @@
348
        }
349
350
        $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/');
351
        if(!$uploadResult) {
352
            $result = ['error' => 'unknown'];
353
            return (new HTTPResponse(json_encode($result), 400))
354
                ->addHeader('Content-Type', 'application/json');
355
        }
356
357
        $file->ParentID = $parentRecord ? $parentRecord->ID : 0;
358
        $file->write();