StringUtil   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 9
c 1
b 0
f 0
dl 0
loc 36
ccs 0
cts 10
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A startsWith() 0 9 4
A endsWith() 0 9 4
1
<?php declare(strict_types=1);
2
3
namespace Formularium;
4
5
// from https://github.com/illuminate/support/blob/master/Str.php
6
class StringUtil
7
{
8
    /**
9
     * Determine if a given string starts with a given substring.
10
     *
11
     * @param  string  $haystack
12
     * @param  string|string[]  $needles
13
     * @return bool
14
     */
15
    public static function startsWith($haystack, $needles)
16
    {
17
        foreach ((array) $needles as $needle) {
18
            if ((string) $needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0) {
19
                return true;
20
            }
21
        }
22
23
        return false;
24
    }
25
26
    /**
27
     * Determine if a given string ends with a given substring.
28
     *
29
     * @param  string  $haystack
30
     * @param  string|string[]  $needles
31
     * @return bool
32
     */
33
    public static function endsWith($haystack, $needles)
34
    {
35
        foreach ((array) $needles as $needle) {
36
            if ($needle !== '' && substr($haystack, -strlen($needle)) === (string) $needle) {
37
                return true;
38
            }
39
        }
40
41
        return false;
42
    }
43
}
44