Passed
Branch master (c90b6c)
by Paweł
03:51 queued 01:24
created

EntityMock::resolvePropertyValue()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 6
eloc 22
nc 6
nop 1
dl 0
loc 29
rs 8.9457
c 1
b 0
f 1
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
    public static function create(string $entityClassName): self
16
    {
17
        $self = new self();
18
        $valueResolver = new FakerValueResolver(Factory::create());
19
20
        foreach ((new \ReflectionClass($entityClassName))->getProperties() as $property) {
21
            if (
22
                'id' === $property->getName() ||
23
                null === $value = $valueResolver->resolvePropertyValue($property)
24
            ) {
25
                continue;
26
            }
27
28
            $self->{$property->getName()} = $value;
29
        }
30
31
        return $self;
32
    }
33
}
34