Completed
Push — master ( 72a03e...b9337e )
by Elf
01:19
created

helpers.php ➔ gravatar()   C

Complexity

Conditions 7
Paths 48

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 8.8142

Importance

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