StringUtils::removeFromStart()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
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