GravatarMapper   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 104
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A defaultGravatar() 0 4 1
A https() 0 7 2
A size() 0 4 1
A rating() 0 4 1
A make() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
namespace Ballen\Gravel\Facades;
4
5
use Ballen\Gravel\Gravatar;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Ballen\Gravel\Facades\Gravatar. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
7
/**
8
 * GravelMapper
9
 *
10
 * Gravatar Mapper provides a binding/class method aliases for Laravel to provide friendly syntax.
11
 *
12
 * @author Bobby Allen <[email protected]>
13
 * @license http://opensource.org/licenses/MIT
14
 * @link https://github.com/allebb/gravel
15
 * @link http://www.bobbyallen.me
16
 *
17
 */
18
class GravatarMapper
19
{
20
21
    /**
22
     * Instance container for Gravatar Library dependency injection.
23
     * @var Ballen\Gravel\Gravatar
0 ignored issues
show
Bug introduced by
The type Ballen\Gravel\Facades\Ballen\Gravel\Gravatar was not found. Did you mean Ballen\Gravel\Gravatar? If so, make sure to prefix the type with \.
Loading history...
24
     */
25
    private $gravatar;
26
27
    /**
28
     * @codeCoverageIgnore
29
     */
30
    public function __construct()
31
    {
32
        $this->gravatar = new Gravatar();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Ballen\Gravel\Gravatar() of type Ballen\Gravel\Gravatar is incompatible with the declared type Ballen\Gravel\Facades\Ballen\Gravel\Gravatar of property $gravatar.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
    }
34
35
    /**
36
     * Make the gravatar with the supplied email address.
37
     * @codeCoverageIgnore
38
     * @param string $email The email address for the Gravatar.
39
     * @return Ballen\Gravel\Gravatar
40
     */
41
    public function make($email)
42
    {
43
        $this->gravatar->setEmail($email);
44
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ballen\Gravel\Facades\GravatarMapper which is incompatible with the documented return type Ballen\Gravel\Facades\Ballen\Gravel\Gravatar.
Loading history...
45
    }
46
47
    /**
48
     * Set a custom gravatar size, default is 120px.
49
     * @codeCoverageIgnore
50
     * @param int $size Gravatar image size
51
     * @return Ballen\Gravel\Gravatar
52
     */
53
    public function size($size)
54
    {
55
        $this->gravatar->setSize($size);
56
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ballen\Gravel\Facades\GravatarMapper which is incompatible with the documented return type Ballen\Gravel\Facades\Ballen\Gravel\Gravatar.
Loading history...
57
    }
58
59
    /**
60
     * Options for the default avatar to return when the avatar does not meet
61
     * the rating threshold or when no gravar is found for the user. Valid options
62
     * are:
63
     *
64
     * '404'      : do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response
65
     * 'mm'       : (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)
66
     * 'identicon': a geometric pattern based on an email hash
67
     * 'monsterid': a generated 'monster' with different colors, faces, etc
68
     * 'wavatar'  : generated faces with differing features and backgrounds
69
     * 'retro'    : awesome generated, 8-bit arcade-style pixelated faces
70
     * 'blank'    : a transparent PNG image (border added to HTML below for demonstration purposes)
71
     * @codeCoverageIgnore
72
     * @param string $option The prefix of the default avatar to return if no valid Gravatar is found for the supplied email address.
73
     * @return \Ballen\Gravel\Gravatar
74
     */
75
    public function defaultGravatar($option)
76
    {
77
        $this->gravatar->setDefaultAvatar($option);
78
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ballen\Gravel\Facades\GravatarMapper which is incompatible with the documented return type Ballen\Gravel\Gravatar.
Loading history...
79
    }
80
81
    /**
82
     * Set the rating threshold, will not return a Gravatar unless its in this band.
83
     * Valid options are ('g' is default!)
84
     *
85
     * 'g' : suitable for display on all websites with any audience type.
86
     * 'pg': may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence.
87
     * 'r' : may contain such things as harsh profanity, intense violence, nudity, or hard drug use.
88
     * 'x' : may contain hardcore sexual imagery or extremely disturbing violence.
89
     * @codeCoverageIgnore
90
     * @param string $rating
91
     * @return \Ballen\Gravel\Gravatar
92
     */
93
    public function rating($rating)
94
    {
95
        $this->gravatar->setRating($rating);
96
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ballen\Gravel\Facades\GravatarMapper which is incompatible with the documented return type Ballen\Gravel\Gravatar.
Loading history...
97
    }
98
99
    /**
100
     * Returns a HTTPS formatted URL instead, ideal for sites that implement HTTPS and do not wish to trigger SSL warnings regarding 'some content on this page is not encrytped'.
101
     * @codeCoverageIgnore
102
     * @param boolean $enable Retreive HTTPS formatted Gravatar links?
103
     * @return \Ballen\Gravel\Gravatar
104
     */
105
    public function https($enable = true)
106
    {
107
        $this->gravatar->setUseHTTPS();
108
        if (!$enable) {
109
            $this->gravatar->setUseHTTP();
110
        }
111
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Ballen\Gravel\Facades\GravatarMapper which is incompatible with the documented return type Ballen\Gravel\Gravatar.
Loading history...
112
    }
113
114
    /**
115
     * Builds and returns the final Gravatar URL.
116
     * @codeCoverageIgnore
117
     * @return string The URL to the Gravatar Image.
118
     */
119
    public function get()
120
    {
121
        return $this->gravatar->buildGravatarUrl();
122
    }
123
}
124