GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b864c9...ed9166 )
by butschster
12:41
created

UploadController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 64
c 0
b 0
f 0
ccs 0
cts 39
cp 0
rs 10
wmc 7
lcom 0
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B fromField() 0 53 7
1
<?php
2
3
namespace SleepingOwl\Admin\Http\Controllers;
4
5
use Validator;
6
use Illuminate\Http\Request;
7
use Illuminate\Http\JsonResponse;
8
use Illuminate\Routing\Controller;
9
use SleepingOwl\Admin\Form\Element\File;
10
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface;
11
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
13
class UploadController extends Controller
14
{
15
    /**
16
     * @param Request $request
17
     * @param ModelConfigurationInterface $model
18
     * @param string $field
19
     * @param int|null $id
20
     *
21
     * @return JsonResponse
22
     */
23
    public function fromField(Request $request, ModelConfigurationInterface $model, $field, $id = null)
24
    {
25
        if (! is_null($id)) {
26
            $item = $model->getRepository()->find($id);
27
            if (is_null($item) || ! $model->isEditable($item)) {
28
                return new JsonResponse([
29
                    'message' => trans('lang.message.access_denied'),
30
                ], 403);
31
            }
32
33
            $form = $model->fireEdit($id);
34
        } else {
35
            if (! $model->isCreatable()) {
36
                return new JsonResponse([
37
                    'message' => trans('lang.message.access_denied'),
38
                ], 403);
39
            }
40
41
            $form = $model->fireCreate();
42
        }
43
44
        /** @var File $element */
45
        if (is_null($element = $form->getElement($field))) {
46
            throw new NotFoundHttpException("Field [{$field}] not found");
47
        }
48
49
        $rules = $element->getUploadValidationRules();
50
        $messages = $element->getUploadValidationMessages();
51
        $labels = $element->getUploadValidationLabels();
52
53
        /** @var \Illuminate\Contracts\Validation\Validator $validator */
54
        $validator = Validator::make($request->all(), $rules, $messages, $labels);
55
56
        $element->customValidation($validator);
57
58
        if ($validator->fails()) {
59
            return new JsonResponse([
60
                'message' => trans('lang.message.validation_error'),
61
                'errors'  => $validator->errors()->get('file'),
62
            ], 400);
63
        }
64
65
        $file = $request->file('file');
66
67
        $filename = $element->getUploadFileName($file);
68
        $path = $element->getUploadPath($file);
69
        $settings = $element->getUploadSettings();
70
71
        $result = $element->saveFile($file, public_path($path), $filename, $settings);
72
73
        /* When driver not file */
74
        return new JsonResponse($result);
75
    }
76
}
77