• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 5046041481

pending completion
5046041481

Pull #1697

github

GitHub
Merge 2cd309b47 into a16355c73
Pull Request #1697: perf: native_function_invocation

322 of 322 new or added lines in 62 files covered. (100.0%)

2784 of 4121 relevant lines covered (67.56%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.5
/src/Util/Str.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Cecil\Util;
15

16
class Str
17
{
18
    /**
19
     * Combines an array into a string.
20
     *
21
     * @param string $keyToKey   The key that become the key of the new array
22
     * @param string $keyToValue The key that become the value of the new array
23
     * @param string $separator  The separtor between the key and the value in the result string
24
     */
25
    public static function combineArrayToString(
26
        array $array,
27
        string $keyToKey,
28
        string $keyToValue,
29
        string $separator = ':'
30
    ): string {
31
        $string = '';
1✔
32

33
        foreach ($array as $subArray) {
1✔
34
            $string .= sprintf('%s%s%s, ', $subArray[$keyToKey], $separator, $subArray[$keyToValue]);
1✔
35
        }
36

37
        return substr($string, 0, -2);
1✔
38
    }
39

40
    /**
41
     * Converts 'true', 'false', 'on', 'off', 'yes', 'no' to a boolean.
42
     *
43
     * @param mixed $value Value to convert
44
     *
45
     * @return bool|mixed
46
     */
47
    public static function strToBool($value)
48
    {
49
        if (\is_string($value)) {
1✔
50
            if (\in_array($value, ['true', 'on', 'yes'])) {
1✔
51
                return true;
×
52
            }
53
            if (\in_array($value, ['false', 'off', 'no'])) {
1✔
54
                return false;
×
55
            }
56
        }
57

58
        return $value;
1✔
59
    }
60

61
    /**
62
     * Checks if a string starts with the given string.
63
     */
64
    public static function startsWith(string $haystack, string $needle): bool
65
    {
66
        $length = \strlen($needle);
1✔
67

68
        return substr($haystack, 0, $length) === $needle;
1✔
69
    }
70

71
    /**
72
     * Checks if a string ends with the given string.
73
     */
74
    public static function endsWith(string $haystack, string $needle): bool
75
    {
76
        $length = \strlen($needle);
×
77
        if (!$length) {
×
78
            return true;
×
79
        }
80

81
        return substr($haystack, -$length) === $needle;
×
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc