Completed
Pull Request — master (#2)
by Beñat
02:41
created

AjaxFileUploadAction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 16 5
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel package.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\CMSKernel\Infrastructure\BenGorFileBundle\HttpAction;
13
14
use BenGorFile\File\Domain\Model\FileAlreadyExistsException;
15
use BenGorFile\File\Domain\Model\FileDoesNotExistException;
16
use BenGorFile\File\Domain\Model\FileMimeTypeDoesNotSupportException;
17
use BenGorFile\File\Domain\Model\FileNameInvalidException;
18
use BenGorFile\File\Infrastructure\Application\FileCommandBus;
19
use BenGorFile\FileBundle\Controller\SuffixNumberUploadAction;
20
use Symfony\Component\HttpFoundation\JsonResponse;
21
use Symfony\Component\HttpFoundation\Request;
22
23
/**
24
 * @author Beñat Espiña <[email protected]>
25
 */
26
class AjaxFileUploadAction
27
{
28
    use SuffixNumberUploadAction;
29
30
    private $commandBus;
31
32
    public function __construct(FileCommandBus $commandBus)
33
    {
34
        $this->commandBus = $commandBus;
35
    }
36
37
    public function __invoke(Request $request)
38
    {
39
        try {
40
            $fileData = $this->upload($request, $this->commandBus, 'file');
41
        } catch (FileDoesNotExistException $exception) {
0 ignored issues
show
Bug introduced by
The class BenGorFile\File\Domain\M...leDoesNotExistException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
42
            return new JsonResponse($exception->getMessage(), 404);
43
        } catch (FileAlreadyExistsException $exception) {
0 ignored issues
show
Bug introduced by
The class BenGorFile\File\Domain\M...eAlreadyExistsException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
44
            return new JsonResponse($exception->getMessage(), 409);
45
        } catch (FileMimeTypeDoesNotSupportException $exception) {
0 ignored issues
show
Bug introduced by
The class BenGorFile\File\Domain\M...DoesNotSupportException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
46
            return new JsonResponse($exception->getMessage(), 400);
47
        } catch (FileNameInvalidException $exception) {
0 ignored issues
show
Bug introduced by
The class BenGorFile\File\Domain\M...ileNameInvalidException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
48
            return new JsonResponse($exception->getMessage(), 400);
49
        }
50
51
        return new JsonResponse($fileData);
52
    }
53
}
54