StringUtil::startsWith()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
cc 4
nc 3
nop 2
crap 20
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