gravatar()   B
last analyzed

Complexity

Conditions 7
Paths 48

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 7

Importance

Changes 8
Bugs 0 Features 0
Metric Value
cc 7
eloc 13
c 8
b 0
f 0
nc 48
nop 3
dl 0
loc 23
ccs 12
cts 12
cp 1
crap 7
rs 8.8333
1
<?php
2
3
use Illuminate\Support\Arr;
4
5
if (! function_exists('gravatar')) {
6
    /**
7
     * Generate Gravatar avatar URL for the given email address.
8
     *
9
     * @param  string      $email       Email or email hash
10
     * @param  string|int  $connection  Connection name or image size
11
     * @param  string|int  $size        Connection name or image size
12
     * @return string
13
     */
14
    function gravatar($email, $connection = 'default', $size = null)
15
    {
16 20
        $hash = strlen($email) == 32 && ctype_xdigit($email)
17 4
            ? strtolower($email)
18 20
            : md5(strtolower(trim($email)));
19
20 20
        if (is_int($connection)) {
21
            list($connection, $size) = [
22 16
                is_string($size) ? $size : 'default', $connection,
23
            ];
24
        }
25
26 20
        $config = array_filter(config('gravatar.'.$connection, []));
27
28 20
        if ($size) {
29 16
            unset($config['s']);
30 16
            $config['size'] = $size;
31
        }
32
33 20
        $url = Arr::pull($config, 'url', 'https://secure.gravatar.com/avatar');
34 20
        $query = http_build_query($config, null, '&', PHP_QUERY_RFC3986);
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type string expected by parameter $numeric_prefix of http_build_query(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        $query = http_build_query($config, /** @scrutinizer ignore-type */ null, '&', PHP_QUERY_RFC3986);
Loading history...
35
36 20
        return $url.'/'.$hash.($query ? '?'.$query : '');
37
    }
38
}
39