Passed
Push — master ( e129b4...518849 )
by Przemysław eRIZ
02:32
created

Isbn::generateForProperty()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 17
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 3
crap 4
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\Length;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraints\Length 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 Isbn implements GeneratorInterface
11
{
12
    const DEFAULT_LENGTH = 13;
13
14 4
    public function generateForProperty(FieldMetadata $field, Constraint $constraint, Generator $faker)
15
    {
16
        /*
17
         * @var \Symfony\Component\Validator\Constraints\Isbn $constraint
18
         */
19
20
        /**
21
         * @var Length
22
         */
23 4
        if ($length = $field->annotations->findOneBy(Length::class)) {
24 2
            $max = $length->max ?: self::DEFAULT_LENGTH;
25 2
            if ($max >= 13) {
26 2
                return $faker->isbn13;
27
            }
28
        }
29
30 2
        return $faker->isbn10;
31
    }
32
}
33