Passed
Push — master ( 487122...6a6881 )
by Mokhirjon
26:45 queued 11:50
created

dropDoubleQuotes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
if ( ! function_exists('str_split_unicode')) {
4
    /**
5
     * A proper unicode string split.
6
     * 
7
     * @param  string  $string
8
     * @param  int  $max_length
9
     * @return array
10
     */
11
    function str_split_unicode(string $string, int $max_length = 200) : array
12
    {
13
        if ($max_length > 0) {
14
            $result = [];
15
            $char_length = mb_strlen($string, "UTF-8");
16
17
            for ($part = 0; $part < $char_length; $part += $max_length) {
18
                array_push($result, mb_substr($string, $part, $max_length, "UTF-8"));
19
            }
20
21
            return $result;
22
        }
23
24
        return preg_split("//u", $string, -1, PREG_SPLIT_NO_EMPTY);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_split('//u',...1, PREG_SPLIT_NO_EMPTY) could return the type false which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
25
    }
26
}
27
28
if ( ! function_exists('dropDoubleQuotes')) {
29
    /**
30
     * Drop the beginning and ending double quotes.
31
     * 
32
     * @param  string  $string
33
     * @return string
34
     */
35
    function dropDoubleQuotes(string $string) : string
36
    {
37
        return preg_replace('/^\"|\"$/', '', $string);
38
    }
39
}