Completed
Pull Request — master (#470)
by Anton
14:03 queued 11:44
created

array_add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
use Bluz\Common\Collection;
0 ignored issues
show
Bug introduced by
The type Bluz\Common\Collection 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...
12
use Bluz\Common\Str;
13
use Bluz\Translator\Translator;
14
15
/**
16
 * Simple functions of framework
17
 * be careful with this way
18
 *
19
 * @author   Anton Shevchuk
20
 */
21
if (!function_exists('debug')) {
22
    /**
23
     * Debug variables
24
     *
25
     * Example of usage
26
     *     debug(123);
27
     *     debug(new stdClass());
28
     *     debug($_GET, $_POST, $_FILES);
29
     *
30
     * @codeCoverageIgnore
31
     *
32
     * @param mixed ...$params
33
     */
34
    function debug(...$params)
35
    {
36
        // check definition
37
        if (!getenv('BLUZ_DEBUG') || !isset($_COOKIE['BLUZ_DEBUG'])) {
38
            return;
39
        }
40
41
        ini_set('xdebug.var_display_max_children', '512');
42
43
        if (PHP_SAPI === 'cli') {
44
            if (extension_loaded('xdebug')) {
45
                // try to enable CLI colors
46
                ini_set('xdebug.cli_color', '1');
47
                xdebug_print_function_stack();
48
            } else {
49
                debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
50
            }
51
            var_dump($params);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($params) looks like debug code. Are you sure you do not want to remove it?
Loading history...
52
        } else {
53
            echo '<div class="textleft clear"><pre class="bluz-debug">';
54
            debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
55
            var_dump($params);
56
            echo '</pre></div>';
57
        }
58
    }
59
}
60
61
if (!function_exists('esc')) {
62
    /**
63
     * Escape variable for use in View
64
     *
65
     * Example of usage
66
     *     esc($_GET['name']);
67
     *     esc($_GET['name'], ENT_QUOTES);
68
     *
69
     * @param  string  $variable
70
     * @param  integer $flags
71
     *
72
     * @return string
73
     */
74
    function esc($variable, int $flags = ENT_HTML5)
75
    {
76 1
        return htmlentities((string)$variable, $flags, 'UTF-8');
77
    }
78
}
79
80
if (!function_exists('str_trim_end')) {
81
    /**
82
     * Added symbol to end of string, trim it before
83
     *
84
     * @param  string $subject
85
     * @param  string $symbols
86
     *
87
     * @return string
88
     */
89
    function str_trim_end($subject, $symbols)
90
    {
91 604
        return rtrim($subject, $symbols) . $symbols;
92
    }
93
}
94
95
if (!function_exists('to_camel_case')) {
96
    /**
97
     * Convert string to camel case
98
     *
99
     * @param  string $subject
100
     *
101
     * @return string
102
     */
103
    function to_camel_case($subject)
104
    {
105 4
        return Str::toCamelCase($subject);
106
    }
107
}
108
109
if (!function_exists('class_namespace')) {
110
    /**
111
     * Get namespace of class
112
     *
113
     * @param  string $class
114
     *
115
     * @return string
116
     */
117
    function class_namespace($class)
118
    {
119 6
        return substr($class, 0, strrpos($class, '\\'));
120
    }
121
}
122
123
if (!function_exists('value')) {
124
    /**
125
     * Return the value for callable
126
     *
127
     * @param  callable|mixed $value
128
     *
129
     * @return mixed
130
     */
131
    function value($value)
132
    {
133 6
        return is_callable($value) ? $value(): $value;
134
    }
135
}
136
137
// @codingStandardsIgnoreStart
138
if (!function_exists('__')) {
139
    /**
140
     * Translate message
141
     *
142
     * Example of usage
143
     *
144
     *     // simple
145
     *     // equal to gettext('Message')
146
     *     __('Message');
147
     *
148
     *     // simple replace of one or more argument(s)
149
     *     // equal to sprintf(gettext('Message to %s'), 'Username')
150
     *     __('Message to %s', 'Username');
151
     *
152
     * @param  string   $message
153
     * @param  string[] $text [optional]
154
     *
155
     * @return string
156
     */
157
    function __($message, ...$text)
158
    {
159 452
        return Translator::translate($message, ...$text);
160
    }
161
}
162
163
if (!function_exists('_n')) {
164
    /**
165
     * Translate plural form
166
     *
167
     * Example of usage
168
     *
169
     *     // plural form + sprintf
170
     *     // equal to sprintf(ngettext('%d comment', '%d comments', 4), 4)
171
     *     _n('%d comment', '%d comments', 4, 4)
172
     *
173
     *     // plural form + sprintf
174
     *     // equal to sprintf(ngettext('%d comment', '%d comments', 4), 4, 'Topic')
175
     *     _n('%d comment to %s', '%d comments to %s', 4, 'Topic')
176
     *
177
     * @param  string   $singular
178
     * @param  string   $plural
179
     * @param  integer  $number
180
     * @param  string[] $text [optional]
181
     *
182
     * @return string
183
     */
184
    function _n($singular, $plural, $number, ...$text)
185
    {
186
        return Translator::translatePlural($singular, $plural, $number, ...$text);
187
    }
188
}
189
// @codingStandardsIgnoreEnd
190