Passed
Branch development-2.0 (bf78c7)
by Jonathan
06:14
created

Stdlib::startsWith()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * ReportingCloud PHP Wrapper
6
 *
7
 * PHP wrapper 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://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
11
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
12
 * @copyright © 2019 Text Control GmbH
13
 */
14
15
namespace TxTextControl\ReportingCloud\Stdlib;
16
17
/**
18
 * Class Stdlib
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 * @author  Jonathan Maron (@JonathanMaron)
22
 */
23
class Stdlib 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 10
    public static function startsWith(string $haystack, string $needle): bool
34
    {
35 10
        $len = strlen($needle);
36
37 10
        return ($needle === substr($haystack, 0, $len));
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 11
    public static function endsWith(string $haystack, string $needle): bool
49
    {
50 11
        $len = strlen($needle);
51
52 11
        return ($needle === substr($haystack, -$len));
53
    }
54
}
55