Failed Conditions
Pull Request — release/1.0.0 (#2)
by Yo
03:36
created

StringDocHelper::append()   D

Complexity

Conditions 21
Paths 21

Size

Total Lines 29
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 21

Importance

Changes 0
Metric Value
cc 21
eloc 24
nc 21
nop 2
dl 0
loc 29
ccs 24
cts 24
cp 1
crap 21
rs 4.8505
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Yoanm\JsonRpcParamsSymfonyConstraintDoc\App\Helper;
3
4
use Symfony\Component\Validator\Constraint;
5
use Symfony\Component\Validator\Constraints as Assert;
6
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\StringDoc;
7
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\TypeDoc;
8
9
/**
10
 * Class StringDocHelper
11
 */
12
class StringDocHelper
13
{
14
    /**
15
     * @param TypeDoc $doc
16
     * @param Constraint $constraint
17
     */
18 20
    public function append(TypeDoc $doc, Constraint $constraint)
19
    {
20
        // If format already defined or type is defined and is not a string nor scalar => give up
21 20
        if (!$doc instanceof StringDoc) {
22 1
            return;
23
        }
24
25
        switch (true) {
26 19
            case $constraint instanceof Assert\Bic:
27 18
            case $constraint instanceof Assert\CardScheme:
28 17
            case $constraint instanceof Assert\Country:
29 16
            case $constraint instanceof Assert\Currency:
30 15
            case $constraint instanceof Assert\Date:
31 14
            case $constraint instanceof Assert\DateTime:
32 13
            case $constraint instanceof Assert\Email:
33 12
            case $constraint instanceof Assert\File:
34 11
            case $constraint instanceof Assert\Iban:
35 10
            case $constraint instanceof Assert\Ip:
36 9
            case $constraint instanceof Assert\Isbn:
37 8
            case $constraint instanceof Assert\Issn:
38 7
            case $constraint instanceof Assert\Language:
39 6
            case $constraint instanceof Assert\Locale:
40 5
            case $constraint instanceof Assert\Luhn:
41 4
            case $constraint instanceof Assert\Regex:
42 3
            case $constraint instanceof Assert\Time:
43 2
            case $constraint instanceof Assert\Url:
44 1
            case $constraint instanceof Assert\Uuid:
45 19
                $doc->setFormat(lcfirst((new \ReflectionClass($constraint))->getShortName()));
46 19
                break;
47
        }
48 19
    }
49
}
50