Passed
Push — master ( 29344f...675168 )
by Paweł
03:21 queued 12s
created

EntityMock::create()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 17
rs 9.9666
ccs 8
cts 9
cp 0.8889
crap 4.0218
1
<?php
2
/**
3
 * Copyright (c) 2020.
4
 * @author Paweł Antosiak <[email protected]>
5
 */
6
7
declare(strict_types=1);
8
9
namespace Gorynych\Testing;
10
11
use Faker\Factory;
12
13
final class EntityMock
14
{
15 1
    public static function create(string $entityClassName): self
16
    {
17 1
        $self = new self();
18 1
        $valueResolver = new FakerValueResolver(Factory::create());
19
20 1
        foreach ((new \ReflectionClass($entityClassName))->getProperties() as $property) {
21
            if (
22 1
                'id' === $property->getName() ||
23 1
                null === $value = $valueResolver->resolvePropertyValue($property)
24
            ) {
25
                continue;
26
            }
27
28 1
            $self->{$property->getName()} = $value;
29
        }
30
31 1
        return $self;
32
    }
33
}
34