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

Str   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A contains() 0 9 4
A endsWith() 0 9 3
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
}