functions.php ➔ str_start_with()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * String functions
5
 *
6
 * @package   Baguette\StrFunctions
7
 * @author    USAMI Kenta <[email protected]>
8
 * @copyright 2016 BaguetteHQ
9
 * @license   Apache-2.0
10
 */
11
12
if (!function_exists('str_start_with')) {
13
    /**
14
     * @param  string $haystack
15
     * @param  string $needle
16
     * @return bool
17
     */
18
    function str_start_with($haystack, $needle)
19
    {
20
        return isset($needle) && strncmp($haystack, $needle, strlen($needle)) === 0;
21
    }
22
}
23
24
if (!function_exists('str_end_with')) {
25
    /**
26
     * @param  string $haystack
27
     * @param  string $needle
28
     * @return bool
29
     */
30
    function str_end_with($haystack, $needle)
31
    {
32
        return $needle === '' || substr_compare($haystack, $needle, -strlen($needle)) === 0;
33
    }
34
}
35