Completed
Push — master ( b3febe...348067 )
by Zach
04:06 queued 02:03
created

helpers.php ➔ factory()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 3
nop 0
dl 0
loc 15
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
use Faker\Factory;
4
use Phalcon\Debug\Dump;
5
use Yarak\DB\ModelFactory;
6
7
if (!function_exists('dd')) {
8
    /**
9
     * Dump the passed variables and end the script.
10
     *
11
     * @param  mixed
12
     */
13
    function dd()
14
    {
15
        array_map(function ($x) {
16
            $string = (new Dump(null, true))->variable($x);
17
18
            echo PHP_SAPI == 'cli' ? strip_tags($string).PHP_EOL : $string;
19
        }, func_get_args());
20
21
        die(1);
22
    }
23
}
24
25
if (!function_exists('factory')) {
26
    /**
27
     * Dump the passed variables and end the script.
28
     *
29
     * @param  mixed
30
     */
31
    function factory()
32
    {
33
        $factory = new ModelFactory(Factory::create());
34
35
        $arguments = func_get_args();
36
37
        if (isset($arguments[1]) && is_string($arguments[1])) {
38
            return $factory->forClass($arguments[0], $arguments[1])
39
                ->times(isset($arguments[2]) ? $arguments[2] : null);
40
        } elseif (isset($arguments[1])) {
41
            return $factory->forClass($arguments[0])->times($arguments[1]);
42
        }
43
44
        return $factory->forClass($arguments[0]);
45
    }
46
}
47