FileParam   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 0
loc 49
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConstraints() 0 23 5
A getValue() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\RestBundle\Controller\Annotations;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\Validator\Constraint;
16
use Symfony\Component\Validator\Constraints\All;
17
use Symfony\Component\Validator\Constraints\File;
18
use Symfony\Component\Validator\Constraints\Image;
19
20
/**
21
 * Represents a file that must be present.
22
 *
23
 * @Annotation
24
 * @Target("METHOD")
25
 *
26
 * @author Ener-Getick <[email protected]>
27
 */
28
class FileParam extends AbstractParam
29
{
30
    /** @var bool */
31
    public $strict = true;
32
33
    /** @var mixed */
34
    public $requirements = null;
35
36
    /** @var bool */
37
    public $image = false;
38
39
    /** @var bool */
40
    public $map = false;
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 10
    public function getConstraints()
46
    {
47 10
        $constraints = parent::getConstraints();
48 10
        if ($this->requirements instanceof Constraint) {
49 1
            $constraints[] = $this->requirements;
50
        }
51
52 10
        $options = is_array($this->requirements) ? $this->requirements : array();
53 10
        if ($this->image) {
54 4
            $constraints[] = new Image($options);
55
        } else {
56 6
            $constraints[] = new File($options);
57
        }
58
59
        // If the user wants to map the value
60 10
        if ($this->map) {
61
            $constraints = array(
62 5
                new All(array('constraints' => $constraints)),
63
            );
64
        }
65
66 10
        return $constraints;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 7
    public function getValue(Request $request, $default = null)
73
    {
74 7
        return $request->files->get($this->getKey(), $default);
75
    }
76
}
77