Test Failed
Push — master ( 90f1e5...8cd561 )
by Jim
02:25
created

Str::startsWith()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.2
cc 4
eloc 4
nc 3
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lenovo
5
 * Date: 6/15/2018
6
 * Time: 11:18 AM
7
 */
8
9
namespace TimSDK\Support;
10
11
class Str
12
{
13
    /**
14
     * Determine if a given string starts with a given substring.
15
     *
16
     * @param  string  $haystack
17
     * @param  string|array  $needles
18
     * @return bool
19
     */
20
    public static function startsWith($haystack, $needles)
21
    {
22
        foreach ((array) $needles as $needle) {
23
            if ($needle !== '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
24
                return true;
25
            }
26
        }
27
        return false;
28
    }
29
30
    /**
31
     * Determine if a given string ends with a given substring.
32
     *
33
     * @param  string  $haystack
34
     * @param  string|array  $needles
35
     * @return bool
36
     */
37
    public static function endsWith($haystack, $needles)
38
    {
39
        foreach ((array) $needles as $needle) {
40
            if (substr($haystack, -strlen($needle)) === (string) $needle) {
41
                return true;
42
            }
43
        }
44
        return false;
45
    }
46
}
47