Completed
Push — master ( f1dd04...77e978 )
by Beñat
01:46
created

UploadRoutesLoader::supports()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\FileBundle\Routing\Api;
14
15
use BenGorFile\FileBundle\Routing\RoutesLoader;
16
use Symfony\Component\Routing\Route;
17
18
/**
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
class UploadRoutesLoader extends RoutesLoader
22
{
23
    public function supports($resource, $type = null)
24
    {
25
        return 'bengor_file_upload_api' === $type;
26
    }
27
28 View Code Duplication
    protected function register($file, array $config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $this->routes->add(
31
            $config['api_name'],
32
            new Route(
33
                $config['api_path'],
34
                [
35
                    '_controller' => $this->action($config),
36
                    'fileClass'   => $file,
37
                ],
38
                [],
39
                [],
40
                '',
41
                [],
42
                ['GET']
43
            )
44
        );
45
    }
46
47
    private function action(array $config)
48
    {
49
        return 'BenGorFileBundle:Api\\' . $this->controller($config['upload_strategy']) . ':upload';
50
    }
51
52
    private function controller($uploadStrategy)
53
    {
54
        if ('by_hash' === $uploadStrategy) {
55
            return 'ByHashUpload';
56
        } elseif ('suffix_number' === $uploadStrategy) {
57
            return 'SuffixNumberUpload';
58
        } else {
59
            return 'Upload';
60
        }
61
    }
62
}
63