Passed
Push — main ( fe7ef9...03f6f3 )
by Miaad
10:51
created

strReplace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 2
rs 10
1
<?php
2
3
namespace BPT;
4
5
/**
6
 * easy function for creating inline object
7
 *
8
 *  
9
 *
10
 * e.g. => object(key: 'value', key2: 1234, key3: object(bool: true));
11
 *
12
 * same as (object) ['key' => 'value', 'key2' => 1234, 'key3' => ['bool' => true]]
13
 *
14
 * @param ...$argument
15
 *
16
 * @return object
17
 */
18
function object(... $argument): object {
19
    return (object) $argument;
20
}
21
22
/**
23
 * Same as str_replace but with a small different
24
 *
25
 * str_replace usage :
26
 * ```
27
 * str_replace(
28
 * [
29
 *     'test1',
30
 *     'test2'
31
 * ],
32
 * [
33
 *     'test3',
34
 *     'test4'
35
 * ], $test_text);
36
 * ```
37
 *
38
 * strReplace usage :
39
 * ```
40
 * strReplace(
41
 * [
42
 *     'test1' => 'test3',
43
 *     'test2' => 'test4'
44
 * ], $test_text);
45
 * ```
46
 *
47
 * @param array        $replacements Contain key => value array for needle => replacement
48
 * @param string|array $subject The string or array being searched and replaced on, otherwise known as the haystack.
49
 *
50
 * @return array|string
51
 */
52
function strReplace(array $replacements, string|array $subject): array|string {
53
    return str_replace(array_keys($replacements), array_values($replacements), $subject);
54
}