Completed
Push — master ( a2d719...4531d5 )
by Radu
07:41
created

StringHelper::linkify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Helpers;
6
7
class StringHelper
8
{
9
    /**
10
    * @param mixed $context
11
    */
12
    public static function getContextAsString($context): string
13
    {
14
        \ob_start();
15
        \var_dump($context);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($context) looks like debug code. Are you sure you do not want to remove it?
Loading history...
16
        return (string) \ob_get_clean();
17
    }
18
19
    public static function isEmpty(string $string): bool
20
    {
21
        if ('' === $string) {
22
            return true;
23
        }
24
25
        return false;
26
    }
27
28
    public static function linkify(string $string): string
29
    {
30
        return (string) \preg_replace(
31
            "~[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]~",
32
            "<a href=\"\\0\">\\0</a>",
33
            $string,
34
        );
35
    }
36
37
    public static function startsWith(string $haystack, string $needle, bool $ignoreCase = true): bool
38
    {
39
        if (false !== $ignoreCase) {
40
            $function = \function_exists('mb_stripos')
41
                ? 'mb_stripos'
42
                : 'stripos';
43
        } else {
44
            $function = \function_exists('mb_strpos')
45
                ? 'mb_strpos'
46
                : 'strpos';
47
        }
48
49
        return 0 === $function($haystack, $needle);
50
    }
51
}
52