Util::toCamelCase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace HumanDirect\Socially;
4
5
/**
6
 * Class Util.
7
 */
8
class Util
9
{
10
    /**
11
     * @param string $input
12
     *
13
     * @return string
14
     */
15
    public static function toCamelCase(string $input): string
16
    {
17
        return str_replace(' ', '', ucwords(str_replace(['.', '_', '-'], ' ', $input)));
18
    }
19
20
    /**
21
     * Validates if supplied URL is valid and not an IP address.
22
     *
23
     * @param string $url
24
     *
25
     * @return bool
26
     */
27
    public static function isValidUrl(string $url): bool
28
    {
29
        $cleaned = self::cleanUrl($url);
30
        if (!filter_var($cleaned, FILTER_VALIDATE_URL)) {
31
            return false;
32
        }
33
34
        $result = Result::createFromUrl($cleaned);
35
36
        return $result->isValidDomain();
37
    }
38
39
    /**
40
     * @param string $url
41
     *
42
     * @return string
43
     */
44
    public static function cleanUrl(string $url): string
45
    {
46
        return mb_strtolower(trim($url));
47
    }
48
}
49