Passed
Push — master ( 8d6d1f...381e61 )
by kill
02:41
created

Str::endsWith()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 3.072
rs 9.6666
1
<?php
2
/**
3
 * Created by rozbo at 2017/3/18 下午9:03
4
 */
5
6
namespace puck\tools;
7
8
9
class Str {
10
    /**
11
     * 判断一个字符串是否包含于另一个字符中
12
     *
13
     * @param  string  $haystack
14
     * @param  string|array  $needles
15
     * @return bool
16
     */
17 1
    public static function contains($haystack, $needles)
18
    {
19 1
        foreach ((array) $needles as $needle) {
20 1
            if ($needle != '' && mb_strpos($haystack, $needle) !== false) {
21 1
                return true;
22
            }
23
        }
24
        return false;
25
    }
26
    /**
27
     * 判断一个字符串是否以给定字符串开始
28
     *
29
     * @param  string  $haystack
30
     * @param  string|array  $needles
31
     * @return bool
32
     */
33 3
    public static function startsWith($haystack, $needles)
34
    {
35 3
        foreach ((array) $needles as $needle) {
36 3
            if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
37 3
                return true;
38
            }
39
        }
40
        return false;
41
    }
42
    /**
43
     * 判断一个字符串是否以给定字符串结尾
44
     *
45
     * @param  string  $haystack
46
     * @param  string|array  $needles
47
     * @return bool
48
     */
49 1
    public static function endsWith($haystack, $needles)
50
    {
51 1
        foreach ((array) $needles as $needle) {
52 1
            if (substr($haystack, -strlen($needle)) === (string) $needle) {
53 1
                return true;
54
            }
55
        }
56
        return false;
57
    }
58
}