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

IdInPostValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 20
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 3
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