Passed
Pull Request — master (#33)
by Kevin
19:22
created

faker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Zenstruck\Foundry;
4
5
use Faker;
6
7
/**
8
 * @see Factory::__construct()
9
 */
10
function factory(string $class, $defaultAttributes = []): Factory
11
{
12 32
    return new Factory($class, $defaultAttributes);
13
}
14
15
/**
16
 * @see Factory::create()
17
 *
18
 * @return Proxy|object
19
 */
20
function create(string $class, $attributes = []): Proxy
21
{
22 20
    return factory($class)->create($attributes);
23
}
24
25
/**
26
 * @see Factory::createMany()
27
 *
28
 * @return Proxy[]|object[]
29
 */
30
function create_many(int $number, string $class, $attributes = []): array
31
{
32 4
    return factory($class)->createMany($number, $attributes);
33
}
34
35
/**
36
 * Instantiate object without persisting.
37
 *
38
 * @return Proxy|object "unpersisted" Proxy wrapping the instantiated object
39
 */
40
function instantiate(string $class, $attributes = []): Proxy
41
{
42 4
    return factory($class)->withoutPersisting()->create($attributes);
43
}
44
45
/**
46
 * Instantiate X objects without persisting.
47
 *
48
 * @return Proxy[]|object[] "unpersisted" Proxy's wrapping the instantiated objects
49
 */
50
function instantiate_many(int $number, string $class, $attributes = []): array
51
{
52 4
    return factory($class)->withoutPersisting()->createMany($number, $attributes);
53
}
54
55
/**
56
 * @see Configuration::repositoryFor()
57
 */
58
function repository($objectOrClass): RepositoryProxy
59
{
60 56
    return Factory::configuration()->repositoryFor($objectOrClass);
61
}
62
63
/**
64
 * @see Factory::faker()
65
 */
66
function faker(): Faker\Generator
67
{
68 4
    return Factory::faker();
69
}
70