Completed
Push — master ( 9b1751...cf3cba )
by Elf
02:11
created

helpers.php ➔ gravatar()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.0493

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 24
nop 3
dl 0
loc 20
ccs 8
cts 9
cp 0.8889
crap 6.0493
rs 8.8571
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 1
            ? $email : 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(array_merge(
25 1
            config('gravatar.'.$connection, []), compact($size)
26
        ));
27
28 1
        $url = array_pull($config, 'url', 'https://secure.gravatar.com/avatar');
29 1
        $query = http_build_query($config);
30
31 1
        return $url.'/'.$hash.($query ? '?'.$query : '');
32
    }
33
}
34