Completed
Push — master ( 713930...c5a8d0 )
by Simon
03:41
created

GravatarModel::getGravatar()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.4285
cc 3
eloc 10
nc 2
nop 6
crap 3
1
<?php
2
3
namespace Schanihbg\Gravatar;
4
5
use \Anax\DI\InjectionAwareInterface;
6
use \Anax\DI\InjectionAwareTrait;
7
use \Anax\Configure\ConfigureInterface;
8
use \Anax\Configure\ConfigureTrait;
9
10
/**
11
 * Gravatar.
12
 */
13
class GravatarModel implements ConfigureInterface, InjectionAwareInterface
14
{
15
    use ConfigureTrait;
16
    use InjectionAwareTrait;
17
18
    /**
19
     * Get either a Gravatar URL or complete image tag for a specified email address.
20
     *
21
     * @param string $email The email address
22
     * @param string $size Size in pixels, defaults to 80px [ 1 - 2048 ]
23
     * @param string $rating Maximum rating (inclusive) [ g | pg | r | x ]
24
     * @param boole $img True to return a complete IMG tag False for just the URL
25
     * @param array $atts Optional, additional key/value attributes to include in the IMG tag
26
     * @return String containing either just a URL or a complete image tag
27
     * @source https://gravatar.com/site/implement/images/php/
28
     */
29 1
    public function getGravatar($email, $size, $dImageset, $rating, $img, $atts)
30
    {
31 1
        $url = 'https://www.gravatar.com/avatar/';
32 1
        $url .= md5(strtolower(trim($email)));
33 1
        $url .= "?s=$size&d=$dImageset&r=$rating";
34 1
        if ($img) {
35 1
            $url = '<img src="' . $url . '"';
36 1
            foreach ($atts as $key => $val) {
37 1
                $url .= ' ' . $key . '="' . $val . '"';
38
            }
39 1
            $url .= ' />';
40
        }
41 1
        return $url;
42
    }
43
}
44