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

Str::endsWith()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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