Completed
Push — master ( e6b986...26abcf )
by Elf
22:12
created

gravatar()   C

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 6
Bugs 0 Features 0
Metric Value
cc 7
eloc 13
c 6
b 0
f 0
nc 48
nop 3
dl 0
loc 23
ccs 12
cts 12
cp 1
crap 7
rs 6.7272
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 1
            ? 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
            ];
22
        }
23
24 5
        $config = array_filter(config('gravatar.'.$connection, []));
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

24
        $config = array_filter(/** @scrutinizer ignore-call */ config('gravatar.'.$connection, []));
Loading history...
25
26 5
        if ($size) {
27 4
            unset($config['s']);
28 4
            $config['size'] = $size;
29
        }
30
31 5
        $url = array_pull($config, 'url', 'https://secure.gravatar.com/avatar');
32 5
        $query = http_build_query($config, null, '&', PHP_QUERY_RFC3986);
33
34 5
        return $url.'/'.$hash.($query ? '?'.$query : '');
35
    }
36
}
37