Test Failed
Push — master ( 0ea0f1...28ea87 )
by kill
02:34
created

Str::endsWith()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
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
    public static function contains($haystack, $needles)
18
    {
19
        foreach ((array) $needles as $needle) {
20
            if ($needle != '' && mb_strpos($haystack, $needle) !== false) {
21
                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
    public static function endsWith($haystack, $needles)
34
    {
35
        foreach ((array) $needles as $needle) {
36
            if (substr($haystack, -strlen($needle)) === (string) $needle) {
37
                return true;
38
            }
39
        }
40
        return false;
41
    }
42
}