Completed
Push — master ( bf8da1...e4b361 )
by Zoltán
02:31
created

StringUtils::contains()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php namespace BuildR\Utils;
2
3
/**
4
 * Utility function for string analysis
5
 *
6
 * BuildR PHP Framework
7
 *
8
 * @author Zoltán Borsos <[email protected]>
9
 * @package Utils
10
 *
11
 * @copyright    Copyright 2016, Zoltán Borsos.
12
 * @license      https://github.com/BuildrPHP/Utils/blob/master/LICENSE.md
13
 * @link         https://github.com/BuildrPHP/Utils
14
 */
15
class StringUtils {
16
17
    /**
18
     * Determines that the given string starts with the
19
     * given substring
20
     *
21
     * @param string $input
22
     * @param string $match
23
     *
24
     * @return bool
25
     */
26 5
    public static function startsWith($input, $match) {
27 5
        return ($match !== '' && mb_strpos($input, $match) === 0);
28
    }
29
30
    /**
31
     * Determines that the given string ends with the
32
     * given substring
33
     *
34
     * @param string $input
35
     * @param string $match
36
     *
37
     * @return bool
38
     */
39 5
    public static function endsWith($input, $match) {
40 5
        return ((string) $match === mb_substr($input, (mb_strlen($match) * -1)));
41
    }
42
43
    /**
44
     * Determines that the input string contains the
45
     * given substring.
46
     *
47
     * @param string $input
48
     * @param string $match
49
     *
50
     * @return bool
51
     */
52 7
    public static function contains($input, $match) {
53 7
        return (mb_strpos($input, $match, 0) !== FALSE);
54
    }
55
56
}
57