Completed
Push — master ( 11b317...37df4d )
by Lucas
09:27
created

IdInPostValidator::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 2
crap 12
1
<?php
2
/**
3
 * Validator for a POST request
4
 */
5
6
namespace Graviton\RestBundle\Validator\Constraints\Id;
7
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
/**
12
 * Validator that validates if its a POST request with an ID in the payload
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class IdInPostValidator extends ConstraintValidator
19
{
20
21
    /**
22
     * Checks if the ID is not in the payload of a POST request
23
     *
24
     * @param string     $value      Input value
25
     * @param Constraint $constraint Constraint instance
26
     *
27
     * @return void
28
     */
29
    public function validate($value, Constraint $constraint)
30
    {
31
        $HTTPVerb = $this->context->getRoot()->getConfig()->getMethod();
0 ignored issues
show
Coding Style introduced by
$HTTPVerb does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
32
        $id = $this->context->getRoot()->getData()->getId();
33
        if ($HTTPVerb === 'POST' && isset($id)) {
0 ignored issues
show
Coding Style introduced by
$HTTPVerb does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
34
                $this->context->addViolation($constraint->message);
35
        }
36
    }
37
}
38