Completed
Push — master ( 658ffe...da5f24 )
by Limon
02:18
created

Str::startsWith()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
namespace Limonte;
3
4
class Str
5
{
6 18
    public static function startsWith($haystack, $needle)
7
    {
8 18
        $length = mb_strlen($needle);
9 18
        return (mb_substr($haystack, 0, $length) === $needle);
10
    }
11
12 18
    public static function endsWith($haystack, $needle)
13
    {
14 18
        $length = mb_strlen($needle);
15 18
        if ($length == 0) {
16 1
            return true;
17
        }
18
19 18
        return (mb_substr($haystack, -$length) === $needle);
20
    }
21
22 18
    public static function contains($haystack, $needle)
23
    {
24 18
        return strpos($haystack, $needle) !== false;
25
    }
26
}
27