StringUtils   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A endsWith() 0 5 1
A isEmptyLine() 0 3 1
A removeFromStart() 0 6 1
A startsWith() 0 3 1
1
<?php
2
3
/**
4
 * Static Analysis Results Baseliner (sarb).
5
 *
6
 * (c) Dave Liddament
7
 *
8
 * For the full copyright and licence information please view the LICENSE file distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Utils;
14
15
use Webmozart\Assert\Assert;
16
17
final class StringUtils
18
{
19
    /**
20
     * Returns true if $haystack starts with $needle.
21
     */
22
    public static function startsWith(string $needle, string $haystack): bool
23
    {
24
        return str_starts_with($haystack, $needle);
25
    }
26
27
    /**
28
     * Remove $needle from start of $haystack.
29
     */
30
    public static function removeFromStart(string $needle, string $haystack): string
31
    {
32
        Assert::true(self::startsWith($needle, $haystack));
33
        $length = strlen($needle);
34
35
        return substr($haystack, $length);
36
    }
37
38
    /**
39
     * Returns true if $haystack ends with $needle.
40
     */
41
    public static function endsWith(string $needle, string $haystack): bool
42
    {
43
        $length = strlen($needle);
44
45
        return substr($haystack, -$length) === $needle;
46
    }
47
48
    /**
49
     * Returns true if line is empty (or contains only white space).
50
     */
51
    public static function isEmptyLine(string $line): bool
52
    {
53
        return '' === trim($line);
54
    }
55
}
56