tap_if()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 3
cp 0
rs 10
cc 2
nc 2
nop 3
crap 6
1
<?php
2
3
if (! function_exists('tap_if')) {
4
    /**
5
     * Call the given Closure with the given value then return the value if the given condition is true.
6
     *
7
     * @param  mixed  $condition
8
     * @param  mixed  $value
9
     * @param  callable|null  $callback
10
     * @return mixed|\Illuminate\Support\HigherOrderTapProxy
11
     */
12
    function tap_if($condition, $value, callable $callback = null)
13
    {
14
        if ($condition) {
15
            return tap($value, $callback);
16
        }
17
18
        return $value;
19
    }
20
}
21
22
if (! function_exists('tap_unless')) {
23
    /**
24
     * Call the given Closure with the given value then return the value unless the given condition is true.
25
     *
26
     * @param  mixed  $condition
27
     * @param  mixed  $value
28
     * @param  callable|null  $callback
29
     * @return mixed|\Illuminate\Support\HigherOrderTapProxy
30
     */
31
    function tap_unless($condition, $value, callable $callback = null)
32
    {
33
        return tap_if(!$condition, $value, $callback);
34
    }
35
}
36
37
if (! function_exists('dd_if')) {
38
    /**
39
     * Run dd() helper if the given condition is true.
40
     *
41
     * @param  mixed  $condition
42
     * @param  mixed  ...$vars
43
     * @return exit
0 ignored issues
show
Bug introduced by
The type exit was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
     */
45
    function dd_if($condition, ...$vars)
46
    {
47
        if ($condition) {
48
            dd(...$vars);
49
        }
50
    }
51
}
52
53
if (! function_exists('dd_unless')) {
54
    /**
55
     * Run dd() helper unless the given condition is true.
56
     *
57
     * @param  mixed  $condition
58
     * @param  mixed  ...$vars
59
     * @return exit
60
     */
61
    function dd_unless($condition, ...$vars)
62
    {
63
        dd_if(!$condition, ...$vars);
64
    }
65
}
66