Str::ends_with()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
1
<?php
2
namespace Intraxia\Jaxion\Utility;
3
4
/**
5
 * Class Str
6
 *
7
 * String utility class. Much of this has been borrowed from Illuminate\Support
8
 * and dumbed down for PHP 5.3 compatibility.
9
 *
10
 * @package Intraxia\Jaxion
11
 * @subpackage Utility
12
 */
13
class Str {
14
	/**
15
	 * Determine if a given string starts with a given substring.
16
	 *
17
	 * @param  string       $haystack
18
	 * @param  string|array $needles
19
	 *
20
	 * @return bool
21
	 */
22 45
	public static function starts_with( $haystack, $needles ) {
23 45
		foreach ( (array) $needles as $needle ) {
24 45
			if ( '' !== $needle && 0 === strpos( $haystack, $needle ) ) {
25 45
				return true;
26
			}
27 2
		}
28
29 3
		return false;
30
	}
31
32
	/**
33
	 * Determine if a given string ends with a given substring.
34
	 *
35
	 * @param  string       $haystack
36
	 * @param  string|array $needles
37
	 *
38
	 * @return bool
39
	 */
40 45
	public static function ends_with( $haystack, $needles ) {
41 45
		foreach ( (array) $needles as $needle ) {
42 45
			if ( substr( $haystack, - strlen( $needle ) ) === (string) $needle ) {
43 3
				return true;
44
			}
45 28
		}
46
47 42
		return false;
48
	}
49
}
50