Completed
Push — master ( b9337e...e2661d )
by Elf
02:08 queued 56s
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 15
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
eloc 14
nc 48
nop 3
dl 0
loc 24
ccs 15
cts 15
cp 1
crap 7
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 5
        $hash = strlen($email) == 32 && ctype_xdigit($email)
15 5
            ? strtolower($email)
16 5
            : md5(strtolower(trim($email)));
17
18 5
        if (is_int($connection)) {
19
            list($connection, $size) = [
20 4
                is_string($size) ? $size : 'default', $connection,
21 4
            ];
22 4
        }
23
24 5
        $config = array_filter(config('gravatar.'.$connection, []));
25
26 5
        if ($size) {
27 4
            unset($config['s']);
28 4
            $config['size'] = $size;
29 4
        }
30
31 5
        $url = array_pull($config, 'url', 'https://secure.gravatar.com/avatar');
32 5
        $query = http_build_query($config);
33
34 5
        return $url.'/'.$hash.($query ? '?'.$query : '');
35
    }
36
}
37