Str   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 37
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A starts_with() 0 9 4
A ends_with() 0 9 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