Faker   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 54
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 10 2
A getFaker() 0 8 3
A fakerClass() 0 6 1
1
<?php
2
3
namespace PragmaRX\Random;
4
5
trait Faker
6
{
7
    protected $fakerClass = 'Faker\Factory';
8
9
    protected $faker;
10
11
    protected $fakerString;
12
13
    /**
14
     * Call faker.
15
     *
16
     * @param $name
17
     * @param $arguments
18
     * @return mixed
19
     * @throws \Exception
20
     */
21 2
    public function __call($name, $arguments)
22
    {
23
        try {
24 2
            $this->fakerString = $this->getFaker()->{$name}(...$arguments);
25 1
        } catch (\Error $e) {
26 1
            throw new \Exception('Faker is not installed. Call to undefined method PragmaRX\Random\Random::'.$name);
27
        }
28
29 1
        return $this;
30
    }
31
32
    /**
33
     * Instantiate and get Faker.
34
     *
35
     * @return \Faker\Generator|null
36
     */
37 2
    public function getFaker()
38
    {
39 2
        if (is_null($this->faker) && class_exists($this->fakerClass)) {
40 1
            $this->faker = call_user_func("$this->fakerClass::create");
41
        }
42
43 2
        return $this->faker;
44
    }
45
46
    /**
47
     * Set the faker class.
48
     *
49
     * @param $class
50
     * @return $this
51
     */
52 1
    public function fakerClass($class)
53
    {
54 1
        $this->fakerClass = $class;
55
56 1
        return $this;
57
    }
58
}
59