Completed
Push — master ( cf3cba...c95851 )
by Elf
02:52
created

helpers.php ➔ gravatar()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.288

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 24
nop 3
dl 0
loc 21
ccs 8
cts 10
cp 0.8
crap 6.288
rs 8.7624
c 0
b 0
f 0
1
<?php
2
3
4
if (! function_exists('gravatar')) {
5
    /**
6
     * Generate Gravatar avatar URL for the given email address.
7
     *
8
     * @param  string      $email       Email or email hash
9
     * @param  string|int  $connection  Connection name or image size
10
     * @param  string|int  $size        Connection name or image size
11
     * @return string
12
     */
13
    function gravatar($email, $connection = 'default', $size = null)
14
    {
15 1
        $hash = strlen($email) == 32 && ctype_xdigit($email)
16
            ? strtolower($email)
17 1
            : md5(strtolower(trim($email)));
18
19 1
        if (is_int($connection)) {
20
            list($connection, $size) = [
21
                is_string($size) ? $size : 'default', $connection,
22
            ];
23
        }
24
25 1
        $config = array_filter(array_merge(
26 1
            config('gravatar.'.$connection, []), compact('size')
27
        ));
28
29 1
        $url = array_pull($config, 'url', 'https://secure.gravatar.com/avatar');
30 1
        $query = http_build_query($config);
31
32 1
        return $url.'/'.$hash.($query ? '?'.$query : '');
33
    }
34
}
35