Ip::generateForProperty()   C
last analyzed

Complexity

Conditions 14
Paths 17

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 34.4273

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 24
ccs 9
cts 17
cp 0.5294
rs 6.2666
c 0
b 0
f 0
cc 14
nc 17
nop 3
crap 34.4273

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
3
namespace Er1z\FakeMock\Generator\AssertGenerator;
4
5
use Er1z\FakeMock\Metadata\FieldMetadata;
6
use Faker\Generator;
7
use Symfony\Component\Validator\Constraint;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraint was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Validator\Constraints\Ip as IpConstraint;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraints\Ip was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class Ip implements GeneratorInterface
11
{
12 6
    public function generateForProperty(FieldMetadata $field, Constraint $constraint, Generator $faker)
13
    {
14
        /*
15
         * @var IpConstraint
16
         */
17 6
        switch ($constraint->version) {
18 6
            case IpConstraint::V6:
19 3
            case IpConstraint::V6_NO_PRIV:
20 3
            case IpConstraint::V6_NO_RES:
21 3
            case IpConstraint::V6_ONLY_PUBLIC:
22 3
                return $faker->ipv6;
23
24
            default:
25 3
            case IpConstraint::V4:
26
            case IpConstraint::V4_NO_PRIV:
27
            case IpConstraint::V4_NO_RES:
28
            case IpConstraint::V4_ONLY_PUBLIC:
29 3
                return $faker->ipv4;
30
31
            case IpConstraint::ALL:
32
            case IpConstraint::ALL_NO_PRIV:
33
            case IpConstraint::ALL_NO_RES:
34
            case IpConstraint::ALL_ONLY_PUBLIC:
35
                return $faker->{mt_rand(0, 1) ? 'ipv4' : 'ipv6'};
36
        }
37
    }
38
}
39