StringUtils   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 3
c 2
b 0
f 0
dl 0
loc 30
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A endsWith() 0 5 3
A startsWith() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * ReportingCloud PHP SDK
6
 *
7
 * PHP SDK for ReportingCloud Web API. Authored and supported by Text Control GmbH.
8
 *
9
 * @link      https://www.reporting.cloud to learn more about ReportingCloud
10
 * @link      https://git.io/Jejj2 for the canonical source repository
11
 * @license   https://git.io/Jejjr
12
 * @copyright © 2022 Text Control GmbH
13
 */
14
15
namespace TxTextControl\ReportingCloud\Stdlib;
16
17
/**
18
 * Class StringUtils
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 * @author  Jonathan Maron (@JonathanMaron)
22
 */
23
class StringUtils extends AbstractStdlib
24
{
25
    /**
26
     * Return true, if needle is at the beginning of haystack
27
     *
28
     * @param string $haystack
29
     * @param string $needle
30
     *
31
     * @return bool
32
     */
33 28
    public static function startsWith(string $haystack, string $needle): bool
34
    {
35
        // Source: https://git.io/JnWmc
36
37 28
        return 0 === strncmp($haystack, $needle, strlen($needle));
38
    }
39
40
    /**
41
     * Return true, if needle is at the end of haystack
42
     *
43
     * @param string $haystack
44
     * @param string $needle
45
     *
46
     * @return bool
47
     */
48 92
    public static function endsWith(string $haystack, string $needle): bool
49
    {
50
        // Source: https://git.io/JnWml
51
52 92
        return '' === $needle || ('' !== $haystack && 0 === substr_compare($haystack, $needle, -strlen($needle)));
53
    }
54
}
55