helpers.php ➔ td()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
if (! function_exists('tinker')) {
4
    function tinker(...$args)
5
    {
6
        /*
7
         * Thank you Caleb
8
         * See: https://github.com/calebporzio/awesome-helpers/blob/master/src/helpers/tinker.php
9
         */
10
        $namedParameters = collect(debug_backtrace())
11
            ->where('function', 'tinker')->take(1)
12
            ->map(function ($slice) {
13
                return array_values($slice);
14
            })
15
            ->mapSpread(function ($filePath, $lineNumber, $function, $args) {
0 ignored issues
show
Unused Code introduced by
The parameter $function is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
                return file($filePath)[$lineNumber - 1];
17
                // "    tinker($post, new User);"
18
            })->map(function ($carry) {
19
                return str_before(str_after($carry, 'tinker('), ');');
20
                // "$post, new User"
21
            })->flatMap(function ($carry) {
22
                return array_map('trim', explode(',', $carry));
23
                // ["post", "new User"]
24
            })->map(function ($carry, $index) {
25
                return strpos($carry, '$') === 0
26
                    ? str_after($carry, '$')
27
                    : 'temp'.$index;
28
                // ["post", "temp1"]
29
            })
30
            ->combine($args)->all();
31
32
        $connection = new \BeyondCode\LaravelTinkerServer\Connection(config('laravel-tinker-server.host'));
33
34
        if (! $connection->write($namedParameters)) {
35
            dump($args);
36
        }
37
    }
38
}
39
40
if (! function_exists('td')) {
41
    function td(...$args)
42
    {
43
        tinker($args);
44
45
        die(1);
46
    }
47
}
48