Issues (24)

src/helpers.php (1 issue)

Severity
1
<?php
2
/*
3
 * This file is part of Rivescript-php
4
 *
5
 * (c) Shea Lewis <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
use Axiom\Rivescript\Support\Str;
12
use Axiom\Rivescript\Cortex\Synapse;
13
use Axiom\Rivescript\Support\Logger;
14
15
if (!function_exists('synapse')) {
16
    /**
17
     * Get the available Synapse instance.
18
     *
19
     * @return Synapse
20
     */
21
    function synapse(): Synapse
22
    {
23
        return Synapse::getInstance();
24
    }
25
}
26
27
if (!function_exists('dd')) {
28
    /**
29
     * Dump the passed variable(s) and end the script.
30
     *
31
     * param  mixed  $args  The information to dump.
32
     *
33
     * @return void
34
     * @noinspection ForgottenDebugOutputInspection
35
     */
36
    function dd()
37
    {
38
        array_map(function ($x) {
39
            print_r($x);
40
            echo "\n";
41
        }, func_get_args());
42
        die;
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
43
    }
44
}
45
46
if (!function_exists('ends_with')) {
47
    /**
48
     * Determine if a given string ends with a given substring.
49
     *
50
     * @param string $haystack The containing string.
51
     * @param string $needle   The needle to look for.
52
     *
53
     * @return bool
54
     */
55
    function ends_with(string $haystack, string $needle): bool
56
    {
57
        return Str::endsWith($haystack, $needle);
58
    }
59
}
60
61
if (!function_exists('log_debug')) {
62
    /**
63
     * Log the message and contextual array as a new debug entry.
64
     *
65
     * @param string  $message The message to output.
66
     * @param array[] $context The context for the message.
67
     *
68
     * @return bool
69
     */
70
    function log_debug(string $message, array $context = []): bool
71
    {
72
        return (new Logger())->debug($message, $context);
73
    }
74
}
75
76
if (!function_exists('log_warning')) {
77
    /**
78
     * Log the message and contextual array as a new warning entry.
79
     *
80
     * @param string  $message The message to output.
81
     * @param array[] $context The context for the message.
82
     *
83
     * @return bool
84
     */
85
    function log_warning(string $message, array $context = []): bool
86
    {
87
        return (new Logger())->warning($message, $context);
88
    }
89
}
90
91
if (!function_exists('remove_whitespace')) {
92
    /**
93
     * Trim leading and trailing whitespace as well as
94
     * whitespace surrounding individual arguments.
95
     *
96
     * @param string $line The line to remove whitespace from.
97
     *
98
     * @return string
99
     */
100
    function remove_whitespace(string $line): string
101
    {
102
        return Str::removeWhitespace($line);
103
    }
104
}
105
106
if (!function_exists('starts_with')) {
107
    /**
108
     * Determine if a given string starts with a given substring.
109
     *
110
     * @param string $haystack The containing string.
111
     * @param string $needle   The needle to look for.
112
     *
113
     * @return bool
114
     */
115
    function starts_with(string $haystack, string $needle): bool
116
    {
117
        return Str::startsWith($haystack, $needle);
118
    }
119
}
120