Passed
Pull Request — master (#50)
by Daniel
06:52
created

FileAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 2
b 0
f 0
dl 0
loc 13
ccs 0
cts 7
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[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
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\Action\File;
15
16
use Silverback\ApiComponentBundle\Exception\InvalidArgumentException;
17
use Silverback\ApiComponentBundle\Helper\FileHelper;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
20
21
/**
22
 * @author Daniel West <[email protected]>
23
 */
24
class FileAction
25
{
26
    public function __invoke(Request $request, FileHelper $fileHelper)
27
    {
28
        $resourceClass = $request->attributes->get('_api_resource_class');
29
        $resource = new $resourceClass();
30
        try {
31
            $fileHelper->uploadFile($resource, $request->files);
32
        } catch (InvalidArgumentException $exception) {
33
            throw new BadRequestHttpException($exception->getMessage());
34
        }
35
36
        return $resource;
37
    }
38
}
39