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

FileAction::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
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