Completed
Push — master ( 5a1ced...5e31e4 )
by Lukas Kahwe
18:21 queued 11:48
created

AbstractParam::getConstraints()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6667
cc 2
eloc 5
nc 2
nop 0
crap 2
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\Validator\Constraints;
15
16
/**
17
 * {@inheritdoc}
18
 *
19
 * @author Jordi Boggiano <[email protected]>
20
 * @author Boris Guéry <[email protected]>
21
 * @author Ener-Getick <[email protected]>
22
 */
23
abstract class AbstractParam implements ParamInterface
24
{
25
    /** @var string */
26
    public $name;
27
    /** @var string */
28
    public $key;
29
    /** @var mixed */
30
    public $default;
31
    /** @var string */
32
    public $description;
33
    /** @var bool */
34
    public $strict = false;
35
    /** @var bool */
36
    public $nullable = false;
37
    /** @var array */
38
    public $incompatibles = array();
39
40
    /** {@inheritdoc} */
41 8
    public function getName()
42
    {
43 8
        return $this->name;
44
    }
45
46
    /** {@inheritdoc} */
47 5
    public function getDefault()
48
    {
49 5
        return $this->default;
50
    }
51
52
    /** {@inheritdoc} */
53 1
    public function getDescription()
54
    {
55 1
        return $this->description;
56
    }
57
58
    /** {@inheritdoc} */
59 5
    public function getIncompatibilities()
60
    {
61 5
        return $this->incompatibles;
62
    }
63
64
    /** {@inheritdoc} */
65 14
    public function getConstraints()
66
    {
67 14
        $constraints = array();
68 14
        if (!$this->nullable) {
69 13
            $constraints[] = new Constraints\NotNull();
70 13
        }
71
72 14
        return $constraints;
73
    }
74
75
    /** {@inheritdoc} */
76 1
    public function isStrict()
77
    {
78 1
        return $this->strict;
79
    }
80
81
    /**
82
     * @return string
83
     */
84 4
    protected function getKey()
85
    {
86 4
        return $this->key ?: $this->name;
87
    }
88
}
89